Commit Graph

31 Commits

Author SHA1 Message Date
silverqx 1df00a3caf prettified section names in DB/DM/DC 2021-11-13 15:10:15 +01:00
silverqx 82bcdc2623 made all defaulted methods explicitly inline 2021-11-13 15:08:20 +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 af222b44ba unified all virtual destructors
- explicitly declared all virtual destructors
 - inline for pure dtors moved to the declaration
 - used override/final where appropriate
 - made some dtors pure virtual where appropriate
2021-10-28 20:13:30 +02:00
silverqx 845a71faae passed * clang-tidy (hpp files)
Following clang-tidy checks bugprone-*, concurrency-*, modernize-*, and
google-*.

 - namespace-comments
 - using-namespaces
 - virtual vs override/final
 - explicit ctor/conversion operator
2021-10-26 06:14:04 +02:00
silverqx accb2a6106 changed savepoints counter to std::size_t
Changed transaction level (aka savepoints in MySQL DB) from uint
to the std::size_t type.
2021-10-23 11:07:20 +02:00
silverqx 182abf4c4f changed size_t to std::size_t 2021-10-23 10:47:58 +02:00
silverqx 7f07ed4482 unified macro guards 2021-10-21 16:36:50 +02:00
silverqx d2999dfcbf qmake/cmake unified debug output
- removed all occurrences of QT_NO_DEBUG_OUTPUT, it is up to user
 - TINYORM_DEBUG_SQL is enabled in debug builds and TINYORM_NO_DEBUG_SQL
   in release builds, user still can override debug build with
   TINYORM_NO_DEBUG_SQL
 - enhanced debug output in DatabaseConnection class
 - added driverNamePrintable(), databaseName(), hostName() to
   DB/DatabaseManager/DatabaseConnection
 - logquery added to NS and created library class for it
2021-10-21 09:48:53 +02:00
silverqx 89f8566d33 replaced TINYORM_COMMON_NAMESPACE with macro 2021-10-19 19:40:17 +02:00
silverqx d68d8fedb3 added pragma system_header 2021-10-13 10:06:50 +02:00
silverqx 63792d3798 fixed clang warnings
- fixed Wconversion warnings
 - disabled Wstrict-null-sentinel for clang compiler
2021-09-05 18:45:33 +02:00
silverqx 70a9e0fceb used pure virtual destructors when appropriate 2021-08-06 13:42:48 +02:00
silverqx cf939e0005 fixed comment for destructors 2021-08-06 13:24:17 +02:00
silverqx 8473ada739 added comments for all classes 2021-08-06 11:52:26 +02:00
silverqx e9133df5c8 comments for all ctors/dtors 2021-08-06 10:35:15 +02:00
silverqx f7442f5c4d added pragma once to every header file 2021-06-16 14:37:16 +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 84e456060b added support for table prefixes
- also added tests
2021-05-28 18:23: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 49eae88995 added partial gcc compatibility
I still was not able to compile it on gcc because of the cyclic
dependency of models.

 - removed zero from dll names where possible
2021-05-07 11:14:24 +02:00
silverqx cb05bfae6d return values for non-affecting statements
Removed std::tuple<bool, QSqlQuery>, exactly bool ok return value
for non-affecting statements, used the QSqlQuery only.

 - also unified return values in the Model::save()
2021-04-14 11:06:16 +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
silverqx 20c03828ff added Mass Assignment feature
- added u_fillable on models used in tests that need it
 - added documentation for mass assignment
 - added tests for mass assignment feature
 - added new Torrent models for tests, which have set up u_fillable and
   u_guarded differently
 - added schema grammar, query post-processor, and schema builder, they
   was needed for database column listing during a mass assignment
   guarded attributes check, used to check if the given attribute is
   a valid guardable column
2021-04-09 10:19:19 +02:00
silverqx 68446e3530 added SQLite database support 🔥🚀
- all tests are ran against SQLite test database too 🎉🔥
 - removed default models connection for tests, because I'm testing
   models for all database connections and the connection is controlled
   by global test data, so every test is ran against all the
   supported databases
 - added test code controlled by TINYORM_TESTS_CODE preprocessor macro,
   which enables connection override in the BaseModel
 - build tests only when the "CONFIG += build_tests" was added to the
   qmake command

added php script to create databases

 - script creates MySQL and SQLite databases
 - script populate this databases with test data
 - connection credentials are provided through the DB_ env. variables

other changes

 - added api to enable statement counters for the given connections
 - added BaseModel::truncate test
2021-03-26 18:49:50 +01:00
silverqx 17e0bb4cca added BelongsToMany::attach and queries counter
The BelongsToMany::attach overloads are able to accept also Model instance/s.
The many-to-many relation also supports touching timestamps on the pivot table and also touching parent timestamps.

Added queries execution time counter and the number of executed queries
counter, it counts normal, affecting and transactional queries.
Also added proxy methods to the DB facade and DatabaseManager.
The DatabaseManager also contains api to be able enable/disable counters
on all connections or get/reset counters on all connections.

 - tried to compile without PCH and added all the missing includes
2021-03-26 18:44:06 +01:00
silverqx 24ff919f99 added documentation
Huge commit, added following documentation pages:

 - Database: Getting Started
 - Database: Query Builder
 - TinyORM: Getting Started
 - TinyORM: Relationships

Also fixed and added many features to match behavior described
in the documentation.

 - added Orm::DB facade
 - made DatabaseManager strict singleton
 - added BaseModel/TinyBuilder::without method and also tests
 - bugfix affecting statements always returned 1
 - removed defaultConnection argument from the DatabaseManager::create
 - added many proxy methods from DatabaseManager -> DatabaseConnection,
   for transactions, select, update, remove, ... type methods and
   DB::raw method
 - added JoinClause::orOn method
 - added QueryBuilder::groupBy overload
 - added where type proxy methods to the Tiny::Relations::Relation
 - added some missing where and order type proxy methods
   to the TinyBuilder
 - fixed typos and some minor fixes in a comment texts
 - added feature which logs also transaction queries
 - added a new exception class SqlTransactionError
 - added overloaded methods to the
   ConnectionInterface::savepoint/rollbackToSavepoint that takes size_t
2021-03-26 18:07:18 +01:00
silverqx 550874034c added Timestamps
- into the QueryBuilder, TinyBuilder and BaseModel
 - added latest()/oldest() methods into the QueryBuilder, TinyBuilder
   and BaseModel
 - created_at/updated_at columns are touched during insert/update
 - a user can control if the model should be timestamped with
   the u_timestamps data member in Models
 - a user can change the storage format of the model's date columns
   with the u_dateFormat data member in Models
 - a user can override CREATED_AT/UPDATED_AT static data members
   in Models
 - added some shortcut methods related to timestamping into the Relation
   class
2021-03-26 18:07:13 +01:00
silverqx b23b72e1f8 made methods that start query builder static 2021-03-26 18:07:12 +01:00
silverqx 44de2025d7 reconnector and connection/query exceptions
- added reconnector, which reconnects when a connection lost
 - when connection fails or lost, the SqlError exception will be thrown
 - throw the QueryError exception when executed query failed
 - ConnectionInterface is passed around instead of
   the DatabaseConnection
 - renamed some methods in the DatabaseConnection to match Eloquent
2021-03-26 18:07:11 +01:00