- extracted logic to own classes
- every driver has it's own class and can have driver-specific logic
- the 'options' option has it's own parser class, is declared as
the mixin class
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
In addition to actually removing records from your database, TinyORM
can also "soft delete" models. When models are soft deleted, they are
not actually removed from your database. Instead, a deleted_at attribute
is set on the model indicating the date and time at which the model was
"deleted".
- added docs
- added all proxies
- added complete functional tests and a few unit tests
- carefully verified all possible scenarios because it changes
practically all queries 🤯
Others:
- also added from() to all proxies
- bugfix in seeders, bad ID in the PostgreSQL primary key (sequence)
It allows comparing a related model without issuing a query to retrieve
that model.
- added functional tests for both HasOne and also BelongsTo relations
- added docs
Others:
- added the new unit test case tst_Relations_Connection_Independent
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
Move all pivot related methods for the BelongsToMany relation into
the new InteractsWithPivotTable concern.
- rvalue overloads for BelongsToMany::as/withPivot
- added reserve where possible
- whitespaces and formatting
- also complete revisit
Added chunk, each, chunkMap, chunkById, eachById, sole, tap
in TinyBuilder::Concerns::BuildsQueries and TinyBuilder::soleValue().
- added tests
- added proxies to Model and Relation
- also added missing proxy for forPageAfterId()
It calls the given callback with the given value then return the value.
Also used it on few places as a proof that it works, the old code
looks cleaner though because it's flat.
- 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
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()
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
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
Queries counters extracted to the Concerns::CountsQueries base class.
- removed ConnectionInterface 😕😎🙌
- all methods are returning DatabaseConnection & instead of
ConnectionInterface
- includes cleanup after extraction
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
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.
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
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
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
- 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
groupBy() methods now take column expressions.
- added all proxies
- added new perfectly forwarded groupBy(&&...args) overload
- all new code tested manually in the TinyOrmPlayground