mirror of
https://github.com/silverqx/TinyORM.git
synced 2026-05-08 01:29:23 -05:00
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: https://github.com/qt/qtbase/commit/8c8d6ff7b6e2e6b1b673051685f1499ae4d65e05?diff=unified&w=0
This commit is contained in:
@@ -221,9 +221,9 @@ std::shared_ptr<DatabaseManager> setupDatabaseManager()
|
||||
{collation_, qEnvironmentVariable("DB_MYSQL_COLLATION", UTF8MB40900aici)},
|
||||
{timezone_, TZ00},
|
||||
/* Specifies what time zone all QDateTime-s will have, the overridden default is
|
||||
the Qt::UTC, set to the Qt::LocalTime or QtTimeZoneType::DontConvert to use
|
||||
the system local time. */
|
||||
{qt_timezone, QVariant::fromValue(Qt::UTC)},
|
||||
the QTimeZone::UTC, set to the QTimeZone::LocalTime or
|
||||
QtTimeZoneType::DontConvert to use the system local time. */
|
||||
{qt_timezone, QVariant::fromValue(QTimeZone::UTC)},
|
||||
{strict_, true},
|
||||
},
|
||||
QStringLiteral("tinyorm_tom_mysql")); // shell:connection
|
||||
|
||||
@@ -76,9 +76,9 @@ auto manager = DB::create({
|
||||
{"collation", qEnvironmentVariable("DB_COLLATION", "utf8mb4_0900_ai_ci")},
|
||||
{"timezone", "+00:00"},
|
||||
/* Specifies what time zone all QDateTime-s will have, the overridden default is
|
||||
the Qt::UTC, set to the Qt::LocalTime or QtTimeZoneType::DontConvert to use
|
||||
the system local time. */
|
||||
{"qt_timezone", QVariant::fromValue(Qt::UTC)},
|
||||
the QTimeZone::UTC, set to the QTimeZone::LocalTime or
|
||||
QtTimeZoneType::DontConvert to use the system local time. */
|
||||
{"qt_timezone", QVariant::fromValue(QTimeZone::UTC)},
|
||||
{"prefix", ""},
|
||||
{"prefix_indexes", false},
|
||||
{"strict", true},
|
||||
@@ -107,9 +107,9 @@ auto manager = DB::create({
|
||||
{"charset", qEnvironmentVariable("DB_CHARSET", "utf8")},
|
||||
{"timezone", "UTC"},
|
||||
/* Specifies what time zone all QDateTime-s will have, the overridden default is
|
||||
the Qt::UTC, set to the Qt::LocalTime or QtTimeZoneType::DontConvert to use
|
||||
the system local time. */
|
||||
{"qt_timezone", QVariant::fromValue(Qt::UTC)},
|
||||
the QTimeZone::UTC, set to the QTimeZone::LocalTime or
|
||||
QtTimeZoneType::DontConvert to use the system local time. */
|
||||
{"qt_timezone", QVariant::fromValue(QTimeZone::UTC)},
|
||||
{"prefix", ""},
|
||||
{"prefix_indexes", false},
|
||||
{"options", QVariantHash()},
|
||||
@@ -131,9 +131,9 @@ auto manager = DB::create({
|
||||
{"foreign_key_constraints", qEnvironmentVariable("DB_FOREIGN_KEYS", "true")},
|
||||
{"check_database_exists", true},
|
||||
/* Specifies what time zone all QDateTime-s will have, the overridden default is
|
||||
the Qt::UTC, set to the Qt::LocalTime or QtTimeZoneType::DontConvert to use
|
||||
the system local time. */
|
||||
{"qt_timezone", QVariant::fromValue(Qt::UTC)},
|
||||
the QTimeZone::UTC, set to the QTimeZone::LocalTime or
|
||||
QtTimeZoneType::DontConvert to use the system local time. */
|
||||
{"qt_timezone", QVariant::fromValue(QTimeZone::UTC)},
|
||||
/* Return a QDateTime/QDate with the correct time zone instead of the QString,
|
||||
only works when the qt_timezone isn't set to the DontConvert. */
|
||||
{"return_qdatetime", true},
|
||||
@@ -162,9 +162,9 @@ auto manager = DB::create({
|
||||
{"collation", qEnvironmentVariable("DB_COLLATION", "utf8mb4_unicode_520_ci")},
|
||||
{"timezone", "+00:00"},
|
||||
/* Specifies what time zone all QDateTime-s will have, the overridden default is
|
||||
the Qt::UTC, set to the Qt::LocalTime or QtTimeZoneType::DontConvert to use
|
||||
the system local time. */
|
||||
{"qt_timezone", QVariant::fromValue(Qt::UTC)},
|
||||
the QTimeZone::UTC, set to the QTimeZone::LocalTime or
|
||||
QtTimeZoneType::DontConvert to use the system local time. */
|
||||
{"qt_timezone", QVariant::fromValue(QTimeZone::UTC)},
|
||||
{"prefix", ""},
|
||||
{"prefix_indexes", false},
|
||||
{"strict", true},
|
||||
@@ -208,9 +208,9 @@ auto manager = DB::create({
|
||||
// {options, ConfigUtils::mysqlSslOptions()},
|
||||
{timezone_, TZ00},
|
||||
/* Specifies what time zone all QDateTime-s will have, the overridden default is
|
||||
the Qt::UTC, set to the Qt::LocalTime or QtTimeZoneType::DontConvert to use
|
||||
the system local time. */
|
||||
{qt_timezone, QVariant::fromValue(Qt::UTC)},
|
||||
the QTimeZone::UTC, set to the QTimeZone::LocalTime or
|
||||
QtTimeZoneType::DontConvert to use the system local time. */
|
||||
{qt_timezone, QVariant::fromValue(QTimeZone::UTC)},
|
||||
{prefix_, EMPTY},
|
||||
{prefix_indexes, false},
|
||||
{strict_, true},
|
||||
@@ -258,9 +258,9 @@ auto manager = DB::create({
|
||||
// {options_, ConfigUtils::postgresSslOptions()},
|
||||
{timezone_, UTC},
|
||||
/* Specifies what time zone all QDateTime-s will have, the overridden default is
|
||||
the Qt::UTC, set to the Qt::LocalTime or QtTimeZoneType::DontConvert to use
|
||||
the system local time. */
|
||||
{qt_timezone, QVariant::fromValue(Qt::UTC)},
|
||||
the QTimeZone::UTC, set to the QTimeZone::LocalTime or
|
||||
QtTimeZoneType::DontConvert to use the system local time. */
|
||||
{qt_timezone, QVariant::fromValue(QTimeZone::UTC)},
|
||||
{prefix_, EMPTY},
|
||||
{prefix_indexes, false},
|
||||
// {isolation_level, QStringLiteral("REPEATABLE READ")}, // Postgres default is READ COMMITTED
|
||||
@@ -291,9 +291,9 @@ auto manager = DB::create({
|
||||
{foreign_key_constraints, qEnvironmentVariable("DB_FOREIGN_KEYS", "true")},
|
||||
{check_database_exists, true},
|
||||
/* Specifies what time zone all QDateTime-s will have, the overridden default is
|
||||
the Qt::UTC, set to the Qt::LocalTime or QtTimeZoneType::DontConvert to use
|
||||
the system local time. */
|
||||
{qt_timezone, QVariant::fromValue(Qt::UTC)},
|
||||
the QTimeZone::UTC, set to the QTimeZone::LocalTime or
|
||||
QtTimeZoneType::DontConvert to use the system local time. */
|
||||
{qt_timezone, QVariant::fromValue(QTimeZone::UTC)},
|
||||
/* Return a QDateTime/QDate with the correct time zone instead of the QString,
|
||||
only works when the qt_timezone isn't set to the DontConvert. */
|
||||
{return_qdatetime, true},
|
||||
@@ -333,9 +333,9 @@ auto manager = DB::create({
|
||||
// {options, ConfigUtils::mariaSslOptions()},
|
||||
{timezone_, TZ00},
|
||||
/* Specifies what time zone all QDateTime-s will have, the overridden default is
|
||||
the Qt::UTC, set to the Qt::LocalTime or QtTimeZoneType::DontConvert to use
|
||||
the system local time. */
|
||||
{qt_timezone, QVariant::fromValue(Qt::UTC)},
|
||||
the QTimeZone::UTC, set to the QTimeZone::LocalTime or
|
||||
QtTimeZoneType::DontConvert to use the system local time. */
|
||||
{qt_timezone, QVariant::fromValue(QTimeZone::UTC)},
|
||||
{prefix_, EMPTY},
|
||||
{prefix_indexes, false},
|
||||
{strict_, true},
|
||||
@@ -372,6 +372,10 @@ A database connection is resolved lazily, which means that the connection config
|
||||
You can also use predefined string constants to avoid unnecessary `QString` instantiations, as used in the `tom` migrations [example](building/migrations.mdx#string-constants-example).
|
||||
:::
|
||||
|
||||
:::info
|
||||
See [Date Casting, Serialization & Timezones](tinyorm/casts.mdx#date-casting-serialization-and-timezones) if you have problems with `qt_timezone` configuration option and `QTimeZone` value on older `Qt <6.5` versions.
|
||||
:::
|
||||
|
||||
#### SQLite Configuration
|
||||
|
||||
SQLite databases are contained within a single file on your filesystem. You can create a new SQLite database using the `touch` command in your terminal: `touch database.sqlite3`. After the database has been created, you may configure SQLite database connection:
|
||||
|
||||
@@ -290,10 +290,16 @@ inline static QString u_timeFormat {"HH:mm:ss.zzz"};
|
||||
|
||||
#### Date Casting, Serialization & Timezones {#date-casting-serialization-and-timezones}
|
||||
|
||||
By default, the `CastType::CustomQDate` and `CastType::CustomQDateTime` casts will serialize dates to a UTC ISO-8601 date string (`yyyy-MM-ddTHH:mm:ss.zzzZ`), regardless of the timezone specified in your database connection's `qt_timezone` configuration option. You are strongly encouraged to always use this serialization format, as well as to store your application's dates in the UTC timezone by not changing your database connection's `qt_timezone` configuration option from its default `Qt::UTC` value. Consistently using the UTC timezone throughout your application will provide the maximum level of interoperability with other date manipulation libraries or services written in any programming language.
|
||||
By default, the `CastType::CustomQDate` and `CastType::CustomQDateTime` casts will serialize dates to a UTC ISO-8601 date string (`yyyy-MM-ddTHH:mm:ss.zzzZ`), regardless of the timezone specified in your database connection's `qt_timezone` configuration option. You are strongly encouraged to always use this serialization format, as well as to store your application's dates in the UTC timezone by not changing your database connection's `qt_timezone` configuration option from its default `QTimeZone::UTC` value. Consistently using the UTC timezone throughout your application will provide the maximum level of interoperability with other date manipulation libraries or services written in any programming language.
|
||||
|
||||
If a custom format is applied to the `CastType::CustomQDate` or `CastType::CustomQDateTime` cast types, such as `{CastType::CustomQDateTime, "yyyy-MM-dd HH:mm:ss"}`, the inner timezone of the QDateTime instance will be used during date serialization. Typically, this will be the timezone specified in your database connection's `qt_timezone` configuration option.
|
||||
|
||||
:::info
|
||||
Passing the `Qt::TimeSpec` (eg. `Qt::UTC` or `Qt::LocalTime`) to `QDateTime` methods was deprecated in [`Qt >=6.5`](https://github.com/qt/qtbase/commit/8c8d6ff7b6e2e6b1b673051685f1499ae4d65e05?diff=unified&w=0), it was replaced by the `enum QTimeZone::Initialization` (`QTimeZone::UTC` and `QTimeZone::LocalTime`).
|
||||
|
||||
If you need to support older and newer versions of Qt at the same time, you can use the `Orm::QtTimeZoneConfig::utc()` or `QtTimeZoneConfig::localTime()` factory methods to create the `QtTimeZoneConfig` instance.
|
||||
:::
|
||||
|
||||
### Query Time Casting
|
||||
|
||||
Sometimes you may need to apply casts while executing a query, such as when selecting a raw value from a table. For example, consider the following query:
|
||||
|
||||
@@ -88,7 +88,7 @@ Alternatively, you can use the `Orm::collect<Model>` helper function to create a
|
||||
```cpp
|
||||
ModelsCollection<User> users = Orm::collect<User>({
|
||||
{{"name", "Kate"}, {"added_on", QDateTime::currentDateTimeUtc()}},
|
||||
{{"name", "John"}, {"added_on", QDateTime({2023, 6, 1}, {13, 46, 15}, Qt::UTC)}},
|
||||
{{"name", "John"}, {"added_on", QDateTime({2023, 6, 1}, {13, 46, 15}, QTimeZone::UTC)}},
|
||||
});
|
||||
```
|
||||
|
||||
|
||||
Reference in New Issue
Block a user