Commit Graph

39 Commits

Author SHA1 Message Date
silverqx
b97818b67a forced TLS connection for MariaDB
Everywhere, tom, tom_testdata, and tests.
2023-03-14 12:48:22 +01:00
silverqx
880bc91317 verified MariaDB support 🔥🚀🎉
Added the MariaDB connections and verified and passed all auto tests.
There was not too much to fix. The TLS connections are still not
enabled.

 - fixed upsert
 - fixed tests
 - enhanced upsert tests
 - refactored tst_mysql_qdatetime to be able test both, the MySQL and
   also MariaDB database connections
 - added a few new MariaDB related tests
2023-03-14 12:48:22 +01:00
silverqx
140c3319f9 added comment 2023-02-15 13:58:18 +01:00
silverqx
b9aad6a830 tests and tom set prefix_indexes to false 2023-02-14 21:38:34 +01:00
silverqx
b13728db08 refactored PostgreSQL search_path configuration
Changed from the 'schema' configuration option to the 'search_path',
the 'schema' config. option was dropped and currently throws exception
with a suggestion to use the 'search_path' instead.

The new 'search_path' config. option can be the QString or QStringList
and also supports to set an empty search_path using '' or empty QString
or QStringList.
This search_path config. option is correctly parsed and quoted.
Setting the search_path is initiated from the PostgresConnector
right after the database connection is established.

The PostgresSchemaBuilder is actively using the search_path during
practically all method calls (dropAllTables(), getColumnListing(),
hasTable(), ...). If the search_path is not defined then it queries
the database for the real search_path because the search_path can be
changed anytime and the search_path configuration option value can be
incorrect (out of sync).
It also works correctly with the empty search_path, in this case a fully
qualified table names are required. If the table name is not fully
qualified then the SearchPathEmptyError exception is thrown.
And it also works correctly with the "$user" PostgreSQL's variable, this
variable is resolved to the config["username"] during obtaining
the search_path from the database.

In the pretend mode it behaves little different, if pretending then
the 'search_path' is obtained from the connection configuration and
if the 'search_path' is not defined in the config. the 'public' will
be used as the default.

 - added many new unit and functional tests which are testing all the
   above described scenarios
   - added new functional test case tst_PostgreSQL_SchemaBuilder_f
   - added new functional test case tst_SchemaBuilder
   - added new tests for dropAllTable(), dropAllViews(), hasTable(),
     getColumnListing(), createDatabase(), dropDatabaseIfExists()
     for ALL supported databases
 - added new search_path constant
 - renamed env. variable to DB_PGSQL_SEARCHPATH (from DB_PGSQL_SCHEMA)
 - added new search_path and dont_drop configuration validations to
   check correct type (QString or QStringList)
 - added new 'schema' config. option validation
 - added new exception SearchPathEmptyError
 - started the TinyUtils::Databases refactor
2023-02-11 09:39:28 +01:00
silverqx
e9693d7867 added Postgres isolation_level configuration
- also added a new constants the isolation_level and spatial_ref_sys
2023-01-31 11:25:09 +01:00
silverqx
8750b612d1 added PostgreSQL application_name conn. option 2023-01-28 14:22:14 +01:00
silverqx
b285f54430 added support to pass sslmode for PostgreSQL
It can be passed by the DB_PGSQL_SSLMODE env. variable.
2023-01-21 18:35:23 +01:00
silverqx
5ab041512c tom whitespaces 2023-01-19 14:22:21 +01:00
silverqx
636b4d1ead added support for SSL connections
If the DB_MYSQL_SSL_CERT/KEY/CA env. variables are set then used them
for the MySQL SSL connections in all tests, tom, and tom_testdata.
2023-01-06 19:12:35 +01:00
silverqx
5f4b3f11bb updated comment for return_qdatetime 2022-10-31 16:34:29 +01:00
silverqx
90a03e67f8 cmake added header files to projects
Added using the target_sources() so IDE-s can show these header files
in the Project Explorer.
2022-10-29 19:22:06 +02:00
silverqx
1ded27bbc8 QDateTime overhaul 🤯🤐🙃
Fixed buggy behavior of QDateTime values during SELECT, INSERT, and
UPDATE queries for all supported QtSql drivers. Behavior is fixed if
querying the database using Orm::QueryBuilder or TinyBuilder/Model.
Can't be fixed if using raw queries using the QSqlQuery because I don't
have any control over this code.

Every QtSql driver behaves differently in how it works with
the QDateTime and datetime-related database types. It doesn't have only
one problem, it has various kinds of problems, eg. it returns all
QDateTime objects in the local time zone. All issues are summarized
in NOTES.TXT under "QDateTime and database date/time types:"
section.

This buggy behavior can be fixed or corrected using a new "qt_timezone"
database connection configuration option. It accepts the time zone value
in various formats (QTimeZone, Qt::TimeSpec, int number as an offset
from UTC, QString eg. +02:00, Europe/Prague or Orm::QtTimeZoneConfig).
This "qt_timezone" value affects how the  QueryBuilder and TinyBuilder
send and receives datetime-related types to/from database. It should be
set to the same time zone value as the "timezone" connection
configuration option.

During the INSERT and UPDATE statements, it CONVERTS QDateTime's
time zone to the qt_timezone value before the statement is sent
to the database.
And during the SELECT statements it SETS QDateTime's time zone value
after the values are obtained from the database.

So if you set the "timezone" to UTC and "qt_timezone" to eg. Qt::UTC or
QTimeZone::utc(), then QDateTime values will have set the correct
time zone, in this case, the time zone will be UTC.

For the SQLite database was also added the "return_qdatetime" connection
configuration option which default value is true. By default,
the QSQLITE driver returns datetime values as QString.
The "return_qdatetime" controls this behavior and if is set to true then
the QDateTime will be returned instead.

TinyORM QueryBuilder returns the Orm::SqlQuery instead of QSqlQuery
from methods for which the QDateTime's time zone should be corrected.
That are eg. the select(), selectOne(), unprepared(), or chunk(),
chunkById(), each(), eachById(), ...

Orm::SqlQuery is a simple wrapper around the QSqlQuery whose
responsibility is only to fix a QDateTime's time zone.

Also unified the QDate behavior across all QtSql drivers.

 - added a new migration for the datetime table for testing QDateTime
   and datetime-related database types
 - added new Datetime model
 - added functional tests for testing datetime-related queries
   - testing QDateTime for all supported drivers
   - testing with different time zones, UTC, +02:00
   - testing QDate for all supported drivers
 - added two new connection configuration options "qt_timezone" and
   "return_qdatetime" which is for the SQLite database only
 - added returnQDateTime()/setReturnQDateTime() getter/setter
   to the SQLiteConnection class
 - added getQtTimeZone()/setQtTimeZone()/isConvertingTimeZone()
   to the DatabaseConnection class
 - tests, fixed all QDateTime instances, changed time zone to UTC, so
   auto tests are now UTC, they force also MySQL and PostgreSQL server
   time zone session variable to UTC

Others:

 - StringUtils moved from orm/tiny/utils/ to the orm/utils/ folder
   to the ::Orm::Utils namespace
 - enhanced all database connection constructors, used rvalue references
 - added delegated DatabaseConnection() constructor
   for SQLiteConnection() because of m_returnQDateTime
2022-10-27 14:30:00 +02:00
silverqx
39388abc47 tom used move for DM 2022-08-16 20:38:20 +02:00
silverqx
5ff160dec5 use upsert alias on MySQL
The MySQL >=8.0.19 supports aliases in the VALUES and SET clauses
of INSERT INTO ... ON DUPLICATE KEY UPDATE statement for the row to be
inserted and its columns. It also generates warning from >=8.0.20 if
an old style used.

This enhancement detects the MySQL version and on the base of it uses
alias during the upsert call.

Also a user can override the version through the MySQL database
configuration. It helps to save/avoid one database query
(select version()) during the upsert method call or during connecting
to the MySQL database (version is needed if strict mode is enabled).

 - added unit and functional tests
 - updated number of unit tests to 1402
 - updated upsert docs
 - added ConfigUtils to avoid duplicates

Others:

 - added the version database configuration everywhere
 - docs added few lines about MySQL version configuration option
 - docs updated database configurations, added a new missing options
2022-08-12 15:37:56 +02:00
silverqx
23d0d9045b cmake added FetchContent support
Primary fixed paths CMAKE_SOURCE_DIR, PROJECT_SOURCE_DIR,
CMAKE_BINARY_DIR and similar.

An user can use the following code in the CMakeLists.txt file to
fetch and configure the TinyORM project from GitHub:

FetchContent_Declare(TinyORM
    GIT_REPOSITORY https://github.com/silverqx/TinyORM.git
    GIT_TAG        origin/main
)
# Here you can configure TinyORM CMake options
set(TOM_EXAMPLE ON)
FetchContent_MakeAvailable(TinyORM)
2022-08-11 15:19:56 +02:00
silverqx
8a90bd8653 qmake disabled tiny_ccache in example configs 2022-07-17 11:15:53 +02:00
silverqx
109ed60913 added qmake ccache support on Windows
The ccache can be enable using the "CONFIG*=tiny_ccache" feature.

 - updated docs
2022-07-13 13:56:23 +02:00
silverqx
cca1305054 shell complete, rename shell:connection tag 2022-07-09 06:24:45 +02:00
silverqx
96d0924983 added SQLite connection to tom example 2022-06-21 08:51:39 +02:00
silverqx
f0a985ca6b added zsh completion 🤯🚀 2022-06-15 15:40:30 +02:00
silverqx
43335a6ca4 updated conf.pri.example/s
[skip ci]
2022-06-04 15:10:52 +02:00
silverqx
4f1c931eae added support for clang-cl
Be able to build with clang-cl with MSVC 2019/2022 but only with
inline constants.

 - supported by both CMake and qmake 🎉
 - updated docs support compilers

qmake specific:

 - enhanced and fixed tiny_toolchain_requirement
 - added clang-cl min. required version to tiny_toolchain_requirement
 - enhanced winconf.pri
 - updated conf.pri.examples
 - added a new feature file the tiny_system_headers.prf, it unifies
   tagging system headers

cmake specific:

 - also added clang-cl min. required version as minReqClangClVersion
 - for clang-cl set the INLINE_CONSTANTS to ON and don't show this
   CMake option
2022-06-04 09:23:53 +02:00
silverqx
5f33a1f186 set default connection in tom example
Made the mysql connection the default connection in the tom example.
2022-05-28 18:01:10 +02:00
silverqx
4967700361 workflows execute some tom commands on PostgreSQL
- added PostgreSQL connection to the tom example application
2022-05-23 16:29:45 +02:00
silverqx
54e3613a98 added a new TZ00 string constant
- used everywhere
 - updated docs
2022-05-18 09:57:06 +02:00
silverqx
eb638704dc whitespace 2022-05-18 09:01:41 +02:00
silverqx
d4557fc705 added database seeder 🔥🎉
The db:seed command invokes the root seeder DatabaseSeeder which can
invoke another seeders using the call() related methods. The root seeder
can be set by the --class command-line option and also by the --seeder
cmd. line option on some other commands like migrate:fresh/refresh.

Seeders can be passed to the Tom application in the similar way like the
migrations using the TomApplication::seeders<>() method or through the
constructor.

Arguments can be passed to the call<>() method, then the seeders run()
method will not be called using the virtual dispatch but using the type
traits. Of course the arguments passed to the call<>() method has to
match with the run() method parameters.

Others:

 - unified usingConnection() across all commands, this functionality was
   extracted to own class, previous it was a part of the Migrator class,
   so now every command even if it doesn't use Migrator can call
   the usingConnection() and it correctly sets a default connection and
   SQL queries debugging on the base of the -vvv command-line argument
 - a default database connection is now required, if not set then
   the exception will be thrown
 - added example seeders to the Tom application
2022-05-16 14:25:29 +02:00
silverqx
da9608202d avoid migrations table names collision
tom example, main unit tests migrations and migrations table used during
unit testing have different names.
2022-05-12 13:52:23 +02:00
silverqx
923d54567e cmake removed useless BUILD_INTERFACE 2022-05-10 16:08:45 +02:00
silverqx
4bd89200cb tom example, updated alternative syntax 2022-05-04 10:56:46 +02:00
silverqx
08c41ba9bd added new constant for utf80900 encoding 2022-05-04 10:56:28 +02:00
silverqx
c98833c7b6 updated comments 2022-05-02 12:11:48 +02:00
silverqx
98c61891c3 enhanced migration classes naming
Migration classes can be named in two formats, CamelCase without the
datetime prefix and snake_case with the datetime prefix.

If the CamelCase name is used then the T_MIGRATION macro has to be
also used in the migration class.

 - also added a new validations of the migration class names
2022-05-02 10:59:30 +02:00
silverqx
b732f6f115 QLatin1String to QStringLiteral 😎 2022-04-28 17:22:42 +02:00
silverqx
63d81e0569 used EMPTY constant in the tom example 2022-04-28 14:36:32 +02:00
silverqx
373937958c provide custom migrations path to the tom example
User can provide a custom migrations path for the make:migration
command.

Default path is at database/migrations relative to the tom example
executable.

This allows to use the tom example as a real migration application and
the user doesn't have to create his own migration project.

Using:

 - TomApplication::migrationsPath()
 - TINYTOM_MIGRATIONS_PATH preprocessor macro, will be stringified
 - TOM_MIGRATIONS_PATH CMake PATH option
2022-04-26 19:56:48 +02:00
silverqx
4dda25105f updated all docs links to www.tinyorm.org 2022-04-25 15:10:32 +02:00
silverqx
a6213a6a9d added migrations 🔥🚀
Almost everything is implemented, possible to migrate up, down
(rollback), migrate by steps (works for up/down too), reset, refresh,
fresh, wipe database, showing status, installing migration table.

Command line interface is superb, it supports ansi coloring, verbosity,
no-interactive mode, force option, env option to select current env.

It has enhanced ansi coloring (vt100 terminal) detection, when ansi or
no-ansi option is not passed it can detect whether terminal supports
coloring.
Ansi coloring is disabled when redirection to file is detected (can
be overridden by ansi/no-ansi options).
Supports NO_COLOR env. variable (https://no-color.org/) and can detect
the ConEmu, Hyper, and xterm on Windows.

Carefully implemented help and list commands, list command can print
supported commands by namespace.

Advanced make migration command offers great command interface for
creating migration classes, supports options for generating empty,
create, or update migration classes.

Unfinished make project command, will support creating qmake, qmake
subproject, and cmake, cmake subproject projects. Later will be
extracted to own executable tomproject.exe for rapidly generating a new
TinyORM projects.

Other implemented commands are env that prints current env. and inspire
that displays an inspiring quote 😁.

Verbose supports 5 levels quiet, normal, verbose, very verbose, and
debug.

Possibility to disable compilation of the tom command related code using
TINYORM_DISABLE_TOM c macro, for the qmake exists disable_tom CONFIG
option and for the CMake exist TOM configuration option.

Confirmable interface that ask Y/N confirmation during migrate when
env. == production, can be overridden by --force option.

Whole tom terminal application supports or is implemented with UTF-8
support, also implemented UTF-16 output methods but they are not needed.
Input also supports UTF-8, currently only Y/N input is needed by the
Confirmation concern.

All migrate commands also support the --pretend option and the --env
option, when env. is production then tom asks confirmation to migrate,
it can be overridden by the --force option.

Added the tom example project, it is a complete command-line migration
application, it uses migrations from the tests.

Implementing this was really fun 🙃😎.

 - added 14 functional tests to test migrations up/down, stepping,
   installing migration table, refresh, reset on MySQL database
 - added unit test to check version number in tom.exe executable
 - new tom exception classes
 - created dozens of a new todo tasks 😂🤪, currently 348 todos 😎
 - added some info messages to the qmake build about building features
 - in the debug build and with the -vvv option enable debugging of sql
   queries
 - enhanced RC and manifest file generation, allowed to pass a custom
   basename for a RC/manifest file as the 3. argument and a custom
   replace token for the CMake genex as the 4. argument
 - bugfix disabled #pragma code_page(65001) // UTF-8 in RC files, it
   messes up the © character

Output of tom exe without arguments and options:

Common options:
      --ansi            Force ANSI output
      --no-ansi         Disable ANSI output
      --env             The environment the command should run under
  -h, --help            Display help for the given command. When no
                        command is given display help for the list
                        command
  -n, --no-interaction  Do not ask any interactive question
  -q, --quiet           Do not output any message
  -V, --version         Display this application version
  -v|vv|vvv, --verbose  Increase the verbosity of messages: 1 for normal
                        output, 2 for more verbose output and
                        3 for debug

Available commands:
  env                   Display the current framework environment
  help                  Display help for a command
  inspire               Display an inspiring quote
  list                  List commands
  migrate               Run the database migrations
 db
  db:wipe               Drop all tables, views, and types
 make
  make:migration        Create a new migration file
  make:project          Create a new Tom application project
 migrate
  migrate:fresh         Drop all tables and re-run all migrations
  migrate:install       Create the migration repository
  migrate:refresh       Rollback and re-run all migrations
  migrate:reset         Rollback all database migrations
  migrate:rollback      Rollback the last database migration
  migrate:status        Show the status of each migration
2022-04-20 15:45:35 +02:00