Commit Graph

50 Commits

Author SHA1 Message Date
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
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
2c77dc9a82 added wrapping table name
- fixed mysql query builder unit tests
 - every query builder unit tests will have own test project, sqlite
   test project will be in the next commit to preserve commit history
2021-03-28 19:22:04 +02:00
silverqx
16713bec77 renamed some exceptions 2021-03-26 20:33:24 +01: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
0976e36d37 added the many-to-many type relationship
Relationship can be created by the BaseModel::belongsToMany method.
Added common Pivot model class for a pivot table that extends
the BasePivot<PivotModel>, so a user can extend this class to define
custom pivot model class.
Pivot relation is saved under the pivot key and can be customized by
the BelongsToMany::as method.
Can be selected custom columns in the pivot table by the help with
the withPivot() method.
Can be selected default or custom timestamp columns with withTimestamps
method.
Added example model classes Tag and Tagged for the pivot table, which
demonstrates all implemented features.
Pivot model relations are ignored during refresh.

 - added torrent_tags and tag_torrent tables to the test database
 - added tag_properties to the test table to test eager load relations
   on the pivot table
 - added Tag model and Tagged pivot model
 - used friend declaration instead of friend class
 - fixed typos and whitespaces
 - removed unnecessary empty cpp files, without any implementation
   methods
 - used using BaseModel::BaseModel in all models
 - fixed template parameter names in the Relation class
 - moved the getKeys method up to the Relation class
2021-03-26 18:07:21 +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
46c0161d4c added tests for Model::with() and failed relations
- tests for failed eager and lazy relations
 - added two new exception classes RelationNotFoundError and
   RelationNotLoadedError
2021-03-26 18:07:16 +01:00
silverqx
886c9cfced added Model::findOrFail, TinyBuilder::firstOrFail 2021-03-26 18:07:15 +01:00
silverqx
3d1edaf053 renamed to OrmRuntimeError 2021-03-26 18:07:13 +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
0ef81aa589 moved models to the TinyOrmPlayground
Also fixes to be able to use BaseModel outside of the TinyORM library.
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
silverqx
224c972c9e added DatabaseManager and new connection flow
- every connection is configurable
 - can be added more connections, for now only to the MySQL database
 - code is ready to add PostgreSQL, SqlLite, and Microsoft SqlServer or
   any DB supported by underlying QSqlDatabase class
 - added MySQL connection and MySQL connector
 - removed QueryBuilder::table() and getTable() methods
 - added 'as' parameter to the QueryBuilder::from() method, but does
   nothing for now
 - BaseModel implements HasConnectionResolver interface
 - DatabaseConnection::queryBuilder() renamed to query()
 - removed EntityManager, all methods are implemented
   in the DatabaseManager
 - removed RepositoryFactory, have to be implemented in the future
2021-03-26 18:07:11 +01:00
silverqx
8fd5cfcf26 Expression moved to Query::Expression 2021-03-26 18:07:11 +01:00
silverqx
e6425a535c added utils library for tests 2021-03-26 17:59:00 +01:00
silverqx
f0d00c9971 changed header files extension to hpp 2021-03-26 17:58:59 +01:00
silverqx
76397391d9 separated source and header files
Source files are located in src/ folder and header files in include/
folder.
2021-03-26 17:58:59 +01:00