Commit Graph

68 Commits

Author SHA1 Message Date
silverqx
0bcbcd2431 added support for PostgreSQL schema builder 🎉👌
- added a new config. option dont_drop, allows to define table that
   will be excluded during dropAllTables(), has a default value
   spatial_ref_sys for PostGIS
 - implemented fluent commands, used only by the PostgreSQL Comment
   command
 - added tests for PostgreSQL schema builder
 - reworked tst_Migrate to be able to run on all supported connections,
   currently PostgreSQL and MySQL
 - updated docs

Unrelated:

 - added a new reference class IndexDefinitionReference for a nice API
   during index definition, contains algorithm and language
 - unified selectFromWriteConnection() in schema builders
2022-05-23 10:14:25 +02:00
silverqx
1b3b431873 extracted Model unguarded to own class
Extracting these guard related methods to own class allows to call
GuardedModel::unguarded() regardless of a template parameters needed
on the Model class, before was needed to call
Model<Torrent, Relations..>::unguarded().

 - also made the g_unguarded atomic
 - bugfix reguard() try-catch-finally in GuardedModel::unguarded()
2022-05-16 14:25:24 +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
silverqx
a2714be30e added schema builder 🔥🚀
Added practically everything I wanted to have in except for updating
columns.
Needed to name the schema namespace as Orm::SchemaNs to avoid collision
with the Orm::Schema class.

 - unit tests with great coverage
 - new schema constants
 - a new prefix_indexes and engine DB conncetion configurations

Others:

 - IsModel tag
 - enhanced columnize in the BaseGrammar
 - used a new columnize logic in all grammars
 - new constants
 - new container utils class for joining containers
 - new DB::driver() getter for QSqlDriver
 - avoid possible crash in tests with pretend, added empty log checks
 - clang tidy, excluded to word from short variable names
2022-03-22 09:53:33 +01:00
silverqx
5956cb86c5 added OrmError base class for all exceptions 2022-02-14 17:23:31 +01:00
silverqx
8794b8b285 extracted relation types to own header file 2022-01-16 18:24:05 +01:00
silverqx
bbfca1594e extracted transactions to ManagesTransactions
Transactions extracted to the Concerns::ManagesTransactions base class.

 - bugfix includes
 - logConnected()/logDisconnected() code wrapped in TINYORM_MYSQL_PING
 - hitTransactionalCounters() extracted to Concerns::CountsQueries
 - convertNamedToPositionalBindings() extracted to Concerns::LogsQueries
2022-01-14 21:26:02 +01:00
silverqx
ff0697e1a5 extracted logging queries to LogQueries
Logging queries extracted to the Concerns::LogsQueries base class.
2022-01-14 17:37:58 +01:00
silverqx
b36888ae93 extracted queries counters to CountsQueries
Queries counters extracted to the Concerns::CountsQueries base class.

 - removed ConnectionInterface 😕😎🙌
 - all methods are returning DatabaseConnection & instead of
   ConnectionInterface
 - includes cleanup after extraction
2022-01-14 16:04:17 +01:00
silverqx
280713bcd1 ConnectionOverride moved to own tiny types ns 2022-01-07 13:07:40 +01:00
silverqx
b092191aa5 concepts divided to orm and tiny concepts 2022-01-07 12:54:34 +01:00
silverqx
dbc375f1fe added HasRelationships concerns
Extracted appropriate methods from the Tiny::Model class to own
HasRelationships concerns.
2022-01-07 12:35:47 +01:00
silverqx
5a593224fe extracted CRTP static cast to own macro files
Added to macro files, one with derived model cast and another with
derived model cast and with cast to the base model.
2022-01-06 11:14:48 +01:00
silverqx
7a975f7b99 added HasAttributes and HasTimestamps concerns
Extracted appropriate methods from the Tiny::Model class to own
HasAttributes and HasTimestamps concerns.
2022-01-05 21:02:57 +01:00
silverqx
657f39b104 moved SyncChanges to Tiny::Types 2022-01-03 13:11:01 +01:00
silverqx
087bf68999 moved LOG_EXECUTED_QUERY macro to own file 2022-01-01 16:31:59 +01:00
silverqx
92775f444c divided Orm::Utils
While ORM can be disabled, Orm::Utils has been split into Orm::Utils
and Orm::Tiny::Utils (Orm::Tiny::TinyUtils alias).
So when ORM is disabled then utils used only in the ORM will be
excluded from a final build.

 - bugfix cmake undefined ORM option in TinySources
2022-01-01 14:28:42 +01:00
silverqx
fc477bf1e5 added qmake/cmake option to disable ORM
Added TINYORM_DISABLE_ORM macro controlled by ORM for CMake and
disable_orm for qmake. When TINYORM_DISABLE_ORM macro is defined then
only the query builder without ORM is compiled.
Also excludes ORM-related unit tests.
2021-12-31 11:40:12 +01:00
silverqx
dcbb113fc8 added Fs::resolveHome()
It resolves ~ home prefix to the full filepath
2021-11-21 19:30:51 +01:00
silverqx
037207cd42 moved DatabaseConfiguration to support/ 2021-11-13 19:09:15 +01:00
silverqx
57da4a109e renamed macros.hpp to likely.hpp
It contained T_LIKELY/T_UNLIKELY only.
2021-11-12 20:40:02 +01:00
silverqx
b39b4dcf48 fixed errors for Linux clang/gcc 2021-11-12 12:27:03 +01:00
silverqx
272d27043c database connections in threads support 🔥🚀
Database connection can run in a thread, if you create a connection in
a thread, then you have to use it only from that thread, moving it to
another thread is disallowed.
All restrictions for QSqlDatabase are true also for TinyORM.
The most important work was in DatabaseManager because more threads can
access it at once.
DatabaseManager has to be created only once in the whole application,
so it means when it will be created in a non-main thread, then it has
to be used from this non-main thread the whole time, I didn't try it
to move to another thread, the conclusion is that DatabaseManager can be
created and used from a worker thread.

 - refactored db configuration
 - added DatabaseConnectionsMap to outsource ConnectionsType and make it
   thread_local
 - added resetDefaultConnection()
 - m_queryLogId is atomic
 - made all class static data members thread_local

Thread unrelated:
 - added two new addConnections() overloads
 - added Thread utils class
   - added NameThreadForDebugging()
 - enhanced tst_DatabaseManager
2021-11-12 09:54:28 +01:00
silverqx
ff7596a96e renamed logquery to utils/query 2021-10-21 09:53:26 +02:00
silverqx
89f8566d33 replaced TINYORM_COMMON_NAMESPACE with macro 2021-10-19 19:40:17 +02:00
silverqx
cf0d60e122 moved export.hpp to macros/ folder 2021-10-19 17:14:33 +02:00
silverqx
3212fc4d1c added LibraryInfo class
This class provides info about build type, isDebugBuild() and version.

 - removed QT_DEBUG/QT_NO_DEBUG and used TINYORM_DEBUG/TINYORM_NO_DEBUG
   instead
2021-10-19 16:11:54 +02:00
silverqx
d71312ec44 bugfix typo in the header filename 2021-10-13 17:27:22 +02:00
silverqx
d68d8fedb3 added pragma system_header 2021-10-13 10:06:50 +02:00
silverqx
d60b9704a3 renamed export_global.hpp to export_common.hpp 2021-10-09 13:17:32 +02:00
silverqx
4024f4a35e qmake moved TinyOrm.pri, enforce extern_constants
- TinyOrm.pri moved to tests/qmake/
 - enforce extern constants in shared build/linking when a user did not
   define it
2021-10-07 12:56:58 +02:00
silverqx
4deafe66a1 qmake static build support
Added CONFIG option inline_constants/extern_constants, in shared library
build is used extern_constants option ( can be overridden by
inline_constants option ) and in static library build is used
inline_constants option ( can not be overridden, extern constants cause
crash ).

 - refactored exports in TinyUtils
 - bugfix on tst_version for static build
2021-10-07 09:37:14 +02:00
silverqx
e0ebbd0d61 qmake obtain version info from version.hpp file
Discarded configuration of the version header file by version.hpp.in,
instead the project version is obtained from version.hpp file.

 - also added autotest to test these versions
 - like cherries on a cake, a real Product/FileVersion in exe/dll of the
   TinyOrm.dll and utils.dll is tested too 😲😎
 - added new Fs library class to the utils dll
 - renamed macro defines in utils project to TINYUTILS_XYZ_HPP
2021-09-27 19:09:59 +02:00
silverqx
71626536d2 qmake configure version header file 2021-09-27 08:46:29 +02:00
silverqx
db5aa004a1 all exceptions moved to own folder and namespace 2021-08-05 21:13:23 +02:00
silverqx
dd55222a57 all proxy methods extracted to base classes
All proxy methods on TinyBuilder, Model and Relation moved to their own
base classes.
This change makes the classes code in headers more clear.
2021-08-05 13:51:42 +02:00
silverqx
7ca8910cc4 added querying relationship existence/absence
- support for querying nested relations existence/absence
 - added tests for all possible overloads 😲, 28 unit tests and 14
   functional tests
 - added has() related proxies to the Model and Relation
 - added documentation
 - gcc and clang specific fixes

others:

 - used clazy exclude comments instead of suppressing warnings in IDE
2021-08-03 09:31:31 +02:00
silverqx
7d1f03021b added global constants for most used strings 2021-07-17 14:41:28 +02:00
silverqx
7298d72623 groupBy column expressions and new overload
groupBy() methods now take column expressions.

 - added all proxies
 - added new perfectly forwarded groupBy(&&...args) overload
 - all new code tested manually in the TinyOrmPlayground
2021-07-05 11:57:12 +02:00
silverqx
5e174009e5 added Aggregates
- added shortcut aggregate functions count, min, max, sum, avg
 - also added unit and functional tests3
2021-07-04 19:54:49 +02:00
silverqx
ef82a3f1c1 remove can take expression and new tests
remove() method can also take expression as parameter.
Added new unit tests for insert, update, and remove, also expressions
are tested.
2021-06-30 14:32:07 +02:00
silverqx
5f5002fc30 Qt6 compatibility 2021-06-09 21:33:11 +02:00
silverqx
778a225b1f added PostgreSQL support 🔥🚀
- also all tests pass, problem was only with bool values and truncate
   statement ( can't be send as prepared statement )
 - updated migration and seeds, added PostgreSQL connection
 - bugfix in migration script ?? vs ?:
 - added DatabaseConnection::unprepared()
2021-06-02 15:59:04 +02:00
silverqx
44e959dd05 moved export.hpp to orm/utils/ 2021-05-22 18:27:05 +02:00
silverqx
f2a9a2de29 moved Orm::StatementsCounter to own header file 2021-05-21 20:46:35 +02:00
silverqx
4ce0c02f52 added query log, pretending and records modified
- added query log
 - added pretending (dry run) feature
   - pretending has separate logging logic for qDebug()
 - added records have been modified flag to the database connection
 - deleted copy/move ctors for connection classes
2021-05-19 21:37:59 +02:00
silverqx
0137724b04 added GuardsAttributes class
All the methods related to the Mass Assignment feature extracted to its
own class and used multi-inheritance.
2021-04-20 18:37:55 +02:00
silverqx
9ade54a539 added Default Models for HasOne and BelongsTo
The HasOne and BelongsTo can now return default model instead
of the nullptr.

 - also added tests
 - added documentation
 - updated test db structure, null foreign key in previewable files
 - to the test db into the previewable files added row without parent
 - relation factory methods return actual creating type instead of
   the general base Relation type
2021-04-16 13:29:42 +02:00
silverqx
90aba701e2 renamed basemodel hpp/cpp files to model
- also renamed an include preprocessor directive to MODEL_H
2021-04-12 11:14:42 +02:00
silverqx
0792c78b19 renamed schema grammars and builders
- renamed to avoid the same name conflicts
 - removed object_parallel_to_source from qmake CONFIG
2021-04-11 18:56:18 +02:00