Commit Graph

36 Commits

Author SHA1 Message Date
silverqx
c4430453e6 drivers added SqlDatabase::record(tableName)
It allows to obtain a SqlRecord for the given table.

Populating the Default Column Values works the same way as
for the SqlQuery/SqlResult couterparts.

The recordCached() counterparts in SqlResult were not implemented
because of cache invalidation problems (not possible with the current
API, it's hard to implement).

This API always select-s all columns from the information_schema.columns
table, that's why the SqlResult::recordWithDefaultValues(allColumns)
has the allColumns parameter, it's used but this API/feature.

 - added functional tests
 - added a new empty_with_default_values table
 - logic that doesn't fit into the MySqlDriver class was extracted
   to the SelectsAllColumnsWithLimit0 concern 🕺
2024-07-20 19:58:54 +02:00
silverqx
1c2f17facf removed deprecated up to Qt v6.9 (Qt::TimeSpec) 🎉
- removed using of QDateTime methods using plain Qt::TimeSpec
 - set QT_DISABLE_DEPRECATED_UP_TO to 0x060900 (also 0x061000 works)
 - maintained Qt v5 and <v6.5 code still 😬 (next step will be to drop
   Qt v5 🎉)
 - updated auto tests
 - updated docs
 - updated comments

See:
8c8d6ff7b6
2024-06-25 12:13:07 +02:00
silverqx
07513aa377 used utf8mb4_uca1400_ai_ci for MariaDB 2024-06-05 10:22:06 +02:00
silverqx
2e88965159 tom bugfix missing defined 2024-04-23 18:04:41 +02:00
silverqx
f7a36ca237 tom built MySQL connection only with TinyDrivers 2024-04-23 16:30:11 +02:00
silverqx
6699bd3ea8 testdata_tom bugfix fixtypo in migration filename 2024-02-25 13:55:48 +01:00
silverqx
4e34fc4143 tests used sl() macro everywhere 2024-02-05 16:27:44 +01:00
silverqx
11693e32a3 tom renamed local function 2023-08-19 13:09:44 +02:00
silverqx
84c6da09f6 tom fixtypo 2023-08-18 17:52:42 +02:00
silverqx
aad52a89c8 changed qt_timezone default to Qt::UTC
Previously, it was the QtTimeZoneType::DontConvert that implied the
Qt::LocalTime timezone spec.

Setting this to the Qt::UTC by default is the only way to have the
maximum level of interoperability between TinyORM and other libraries
and services.

 - updated comments in docs and source code
2023-06-29 12:07:42 +02:00
silverqx
c60dc1b0da tests added more seed data, to test relations
Added a new roles belongs-to-many relation to the Tag model to test
eager or lazy loading with select constraints.

 - updated affected unit tests
2023-06-17 17:27:56 +02:00
silverqx
1f5eedb38f models added new belongs-to-many relation
- for testing serialization
 - added two new migrations
 - added two new models
 - updated testdata_tom main.cpp
 - updated affected unit tests
2023-06-16 12:52:18 +02:00
silverqx
7f344a2145 added ModelsCollection 🔥🚀🎉
The Orm::Tiny::Types::ModelsCollection is container class with
additional handy methods like pluck(), whereIn(), filter(), ...
It extends the QVector. The template parameter can be the Model or
Model *, the model must be the Derived model type eg. Torrent, Post, ...

All ORM-related methods return the ModelsCollection so it can be easily
filtered, changed, transformed with one simple line or callback.
All the algorithms are nicely encapsulated in the ModelsCollection
methods.

Currently, there is this pattern, all TinyBuilder or Model methods are
returning the ModelsCollection<Derived> and all relation related
methods are returning the ModelsCollection<Derived *>.

 - added Album and AlbumImage migrations and seeder data (also PHP)
 - added Album and AlbumImage models
 - added functional tests for ModelsCollection<Model> and
   ModelsCollection<Model *>
 - all ModelsCollection methods or algorithms are unit tested
 - replaced all occurences of the QVector<Model> and QVector<Model *>
   with the ModelsCollection<Model> and ModelsCollection<Model *> 😵‍💫
 - tests added Model::findMany()
 - added reserve() on few places
 - removed useless #include-s
2023-05-05 13:06:15 +02:00
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
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
89d63d5ba1 added Casting Attributes 🤯🙌
Attribute casting allows converting TinyORM Model attribute values when
you retrieve them on model instances. Conversion is done using
the QVariant::convert(QMetaType) method.

To cast attributes you can provide the Model::u_casts data member
of the type std::unordered_map<QString, CastItem>.
The CastItem type can be initialized by the CastType (first argument)
and optionally a modifier of the QVariant type (second argument).
Currently, only the CastType::Decimal accepts a modifier that rounds
the decimal number to the given number of decimals.

Supported Orm::Tiny::CastType-s are:
Bool, Boolean, Short, UShort, Int, Integer, UInt, UInteger, LongLong,
ULongLong, Real, Float, Double, Decimal, QString, QDate, QDateTime,
Timestamp, QByteArray.

The MySQL, PostgreSQL, and SQLite QSqlDriver-s already do conversions,
but every one of these drivers is doing these conversions in their own
way, only the varchar or text database types are handled uniformly.
The rules of how these Qt drivers are handling or converting these types
are not simple and the explanation will need it's own paragraph in docs.

Attributes casting is especially useful with the QSQLiteDriver. Other
useful use cases are casting of dates or Unix timestamps,
bool (tinyint), and the decimal type (also supports modifier).

 - added functional tests
 - added a new Type model class used by unit testing
 - added a new migration and seeder for the Type model
 - added showcase example to the Torrent model class
 - updated Model::newInstance() method to also copy a model casts
 - added TinyBuilder::withCasts() method to apply query-time casts
   to the model instance
 - added withCasts() model and relation proxies
 - added functional tests for withCasts() (for all proxies 😎)
 - set the u_casts for the boolean columns/attributes on RoleUser,
   Tagged, and User models
2022-09-20 20:20:56 +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
cca1305054 shell complete, rename shell:connection tag 2022-07-09 06:24:45 +02:00
silverqx
9413daf99f workflows added tom SQLite migrations
- also removed php migrations from all workflows 🙌🥳
2022-06-21 08:35:55 +02:00
silverqx
f0a985ca6b added zsh completion 🤯🚀 2022-06-15 15:40:30 +02:00
silverqx
2cb8bb9b4b use tom migrations in unit tests for PostgreSQL 💪
- added fixPostgresSequences() to our tom seeder
 - added PostgreSQL connection to tom_testdata
 - updated msvc workflow
 - tom, throw if empty connection only if exactly one connection
   provided
 - also updated create_and_seed_database.php script to exclude postgres
   connection using --skip-postgres-migrate command-line parameter
2022-05-23 16:11:30 +02:00
silverqx
74e8078897 added todo task 2022-05-18 14:14:39 +02:00
silverqx
54e3613a98 added a new TZ00 string constant
- used everywhere
 - updated docs
2022-05-18 09:57:06 +02:00
silverqx
488037b33a used our seeder in workflows 🎉💪 2022-05-18 09:40:45 +02:00
silverqx
3b05cd1bed used own tom migrations in unit tests 🎉 2022-05-12 12:25:22 +02:00