fib-orm 2.0.0 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +42 -6
- package/index.d.ts +11 -0
- package/index.js +15 -0
- package/package.json +36 -34
- package/{lib/cli/commands/ddlFrom.js → src/cli/commands/ddlFrom.ts} +40 -26
- package/{lib/cli/commands/dumpModel.js → src/cli/commands/dumpModel.ts} +78 -31
- package/{lib/cli/commands/escape.js → src/cli/commands/escape.ts} +51 -28
- package/{lib/cli/commands/spinner.js → src/cli/commands/spinner.ts} +20 -10
- package/{lib/cli/commands/upgrade.js → src/cli/commands/upgrade.ts} +53 -33
- package/src/cli/helpers/ddl.ts +84 -0
- package/src/cli/helpers/package.ts +81 -0
- package/src/cli/index.ts +24 -0
- package/src/cli/wrapSubcommand.ts +66 -0
- package/src/db-driver/Typo.d.ts +141 -0
- package/src/db-driver/built-ins/base.class.ts +260 -0
- package/src/db-driver/built-ins/driver-dm.ts +62 -0
- package/src/db-driver/built-ins/driver-mssql.ts +67 -0
- package/src/db-driver/built-ins/driver-mysql.ts +44 -0
- package/src/db-driver/built-ins/driver-postgresql.ts +94 -0
- package/src/db-driver/built-ins/driver-redis.ts +45 -0
- package/src/db-driver/built-ins/driver-sqlite.ts +41 -0
- package/src/db-driver/index.ts +6 -0
- package/src/db-driver/parseQueryString.ts +76 -0
- package/src/db-driver/utils.ts +204 -0
- package/src/knex/deps/tarn/PendingOperation.ts +56 -0
- package/src/knex/deps/tarn/Pool.ts +610 -0
- package/src/knex/deps/tarn/PromiseInspection.ts +29 -0
- package/src/knex/deps/tarn/Resource.ts +22 -0
- package/src/knex/deps/tarn/TimeoutError.ts +1 -0
- package/src/knex/deps/tarn/tarn.ts +7 -0
- package/src/knex/deps/tarn/utils.ts +62 -0
- package/src/knex/knex.ts +11 -0
- package/src/knex/result.d.ts +27 -0
- package/src/knex/sandbox.ts +45 -0
- package/src/knex/tables.d.ts +4 -0
- package/src/knex/types.d.ts +3228 -0
- package/src/orm/Adapters.ts +53 -0
- package/src/orm/AggregateFunctions.ts +254 -0
- package/src/orm/Associations/Extend.ts +405 -0
- package/src/orm/Associations/Many.ts +784 -0
- package/src/orm/Associations/One.ts +494 -0
- package/src/orm/Associations/_utils.ts +72 -0
- package/src/orm/ChainFind.ts +427 -0
- package/src/orm/ChainInstance.ts +97 -0
- package/src/orm/Debug.ts +21 -0
- package/src/orm/Drivers/DB/base.ts +7 -0
- package/src/orm/Drivers/DB/dm.ts +35 -0
- package/src/orm/Drivers/DB/mssql.ts +35 -0
- package/src/orm/Drivers/DB/mysql.ts +35 -0
- package/src/orm/Drivers/DB/postgres.ts +35 -0
- package/src/orm/Drivers/DB/sqlite3.ts +60 -0
- package/src/orm/Drivers/DML/_ddl-sql.ts +85 -0
- package/src/orm/Drivers/DML/_dml-helpers.ts +66 -0
- package/src/orm/Drivers/DML/_shared.ts +61 -0
- package/src/orm/Drivers/DML/_utils.ts +112 -0
- package/{lib/orm/Drivers/DML/dm.js → src/orm/Drivers/DML/dm.ts} +178 -85
- package/src/orm/Drivers/DML/index.ts +10 -0
- package/src/orm/Drivers/DML/mssql.ts +366 -0
- package/src/orm/Drivers/DML/mysql.ts +347 -0
- package/src/orm/Drivers/DML/postgres.ts +382 -0
- package/src/orm/Drivers/DML/sqlite.ts +361 -0
- package/src/orm/Error.ts +49 -0
- package/src/orm/Helpers.ts +297 -0
- package/src/orm/Hook.ts +125 -0
- package/src/orm/Instance.ts +944 -0
- package/src/orm/LazyLoad.ts +117 -0
- package/src/orm/Model.ts +1235 -0
- package/src/orm/ORM.ts +301 -0
- package/src/orm/Patch/fib-cache.ts +7 -0
- package/src/orm/Patch/plugin.ts +25 -0
- package/src/orm/Property.ts +86 -0
- package/src/orm/Settings.ts +134 -0
- package/src/orm/Singleton.ts +97 -0
- package/src/orm/Typo/Adapter.d.ts +5 -0
- package/src/orm/Typo/DMLDriver.d.ts +260 -0
- package/src/orm/Typo/Db.d.ts +100 -0
- package/src/orm/Typo/Error.d.ts +36 -0
- package/src/orm/Typo/ORM.d.ts +315 -0
- package/src/orm/Typo/Validators.d.ts +39 -0
- package/src/orm/Typo/_common.d.ts +44 -0
- package/src/orm/Typo/assoc.d.ts +280 -0
- package/src/orm/Typo/hook.d.ts +68 -0
- package/src/orm/Typo/instance.d.ts +214 -0
- package/{lib → src}/orm/Typo/model.d.ts +297 -176
- package/src/orm/Typo/patch.d.ts +39 -0
- package/src/orm/Typo/property.d.ts +79 -0
- package/src/orm/Typo/query.d.ts +266 -0
- package/{lib → src}/orm/Typo/settings.d.ts +14 -7
- package/{lib → src}/orm/Typo/synchronous.d.ts +51 -26
- package/src/orm/Utilities.ts +1313 -0
- package/src/orm/Validators.ts +127 -0
- package/src/orm/Where/common.ts +8 -0
- package/src/orm/Where/filterDate.ts +74 -0
- package/src/orm/cloneDeep.ts +45 -0
- package/src/orm/index.ts +231 -0
- package/src/orm-core/callback.d.ts +15 -0
- package/{lib → src}/orm-core/dialect.d.ts +75 -52
- package/src/orm-core/error.ts +71 -0
- package/{lib/orm-core/index.d.ts → src/orm-core/index.ts} +8 -2
- package/src/orm-core/sync.d.ts +14 -0
- package/src/orm-core/utils.ts +4 -0
- package/src/orm-property/Property.ts +110 -0
- package/src/orm-property/Utils.ts +26 -0
- package/src/orm-property/customTypes.ts +13 -0
- package/src/orm-property/index.ts +34 -0
- package/src/orm-property/transformer.ts +16 -0
- package/{lib/orm-property/transformers/dm.js → src/orm-property/transformers/dm.ts} +128 -68
- package/src/orm-property/transformers/index.ts +10 -0
- package/src/orm-property/transformers/mssql.ts +285 -0
- package/src/orm-property/transformers/mysql.ts +395 -0
- package/src/orm-property/transformers/postgresql.ts +267 -0
- package/src/orm-property/transformers/sqlite.ts +217 -0
- package/src/plugins/orm-plugin-uacl/Typo.d.ts +173 -0
- package/src/plugins/orm-plugin-uacl/_utils.ts +237 -0
- package/src/plugins/orm-plugin-uacl/acl-tree.ts +440 -0
- package/src/plugins/orm-plugin-uacl/config-acl-tree.ts +592 -0
- package/src/plugins/orm-plugin-uacl/index.ts +180 -0
- package/src/plugins/orm-plugin-uacl/tree.ts +331 -0
- package/src/sql-ddl-sync/Dialects/dm.ts +493 -0
- package/{lib/sql-query/Dialects/index.d.ts → src/sql-ddl-sync/Dialects/index.ts} +3 -3
- package/src/sql-ddl-sync/Dialects/mssql.ts +441 -0
- package/src/sql-ddl-sync/Dialects/mysql.ts +414 -0
- package/src/sql-ddl-sync/Dialects/postgresql.ts +474 -0
- package/src/sql-ddl-sync/Dialects/sqlite.ts +439 -0
- package/src/sql-ddl-sync/SQL.ts +157 -0
- package/src/sql-ddl-sync/Typo/Collection.d.ts +19 -0
- package/src/sql-ddl-sync/Typo/DbIndex.d.ts +11 -0
- package/{lib → src}/sql-ddl-sync/Typo/Dialect.d.ts +67 -52
- package/src/sql-ddl-sync/Typo/Driver.d.ts +67 -0
- package/src/sql-ddl-sync/Typo/Query.d.ts +8 -0
- package/src/sql-ddl-sync/Typo/SQL.d.ts +45 -0
- package/src/sql-ddl-sync/Typo/_common.d.ts +59 -0
- package/src/sql-ddl-sync/Utils.ts +291 -0
- package/src/sql-ddl-sync/index.ts +599 -0
- package/src/sql-query/Comparators.ts +115 -0
- package/src/sql-query/Create.ts +87 -0
- package/{lib/sql-query/Dialects/dm.js → src/sql-query/Dialects/dm.ts} +42 -21
- package/src/sql-query/Dialects/index.ts +14 -0
- package/src/sql-query/Dialects/mssql.ts +91 -0
- package/src/sql-query/Dialects/mysql.ts +120 -0
- package/src/sql-query/Dialects/postgresql.ts +99 -0
- package/src/sql-query/Dialects/sqlite.ts +80 -0
- package/src/sql-query/Helpers.ts +303 -0
- package/src/sql-query/Insert.ts +41 -0
- package/src/sql-query/Query.ts +140 -0
- package/src/sql-query/Remove.ts +111 -0
- package/src/sql-query/Select.ts +719 -0
- package/src/sql-query/Set.ts +25 -0
- package/src/sql-query/Typo/Aggregation.d.ts +34 -0
- package/src/sql-query/Typo/Comparators.d.ts +156 -0
- package/src/sql-query/Typo/Dialect.d.ts +51 -0
- package/src/sql-query/Typo/Field.d.ts +10 -0
- package/src/sql-query/Typo/Helper.d.ts +4 -0
- package/src/sql-query/Typo/Query-ChainBuilder.d.ts +110 -0
- package/src/sql-query/Typo/Query.d.ts +65 -0
- package/src/sql-query/Typo/Sql.d.ts +192 -0
- package/src/sql-query/Typo/SubQuery.d.ts +52 -0
- package/{lib/sql-query/Typo/index.d.ts → src/sql-query/Typo/index.ts} +5 -2
- package/src/sql-query/Update.ts +50 -0
- package/src/sql-query/Where.ts +435 -0
- package/{lib/orm/Patch → src/typings}/fib-cache.d.ts +4 -3
- package/lib/cli/commands/ddlFrom.d.ts +0 -2
- package/lib/cli/commands/dumpModel.d.ts +0 -2
- package/lib/cli/commands/escape.d.ts +0 -2
- package/lib/cli/commands/spinner.d.ts +0 -2
- package/lib/cli/commands/upgrade.d.ts +0 -2
- package/lib/cli/helpers/ddl.d.ts +0 -17
- package/lib/cli/helpers/ddl.js +0 -55
- package/lib/cli/helpers/package.d.ts +0 -26
- package/lib/cli/helpers/package.js +0 -56
- package/lib/cli/index.d.ts +0 -2
- package/lib/cli/index.js +0 -18
- package/lib/db-driver/Typo.d.ts +0 -112
- package/lib/db-driver/Typo.js +0 -1
- package/lib/db-driver/built-ins/base.class.d.ts +0 -96
- package/lib/db-driver/built-ins/base.class.js +0 -186
- package/lib/db-driver/built-ins/driver-dm.d.ts +0 -18
- package/lib/db-driver/built-ins/driver-dm.js +0 -53
- package/lib/db-driver/built-ins/driver-mongodb.d.ts +0 -24
- package/lib/db-driver/built-ins/driver-mongodb.js +0 -46
- package/lib/db-driver/built-ins/driver-mysql.d.ts +0 -18
- package/lib/db-driver/built-ins/driver-mysql.js +0 -37
- package/lib/db-driver/built-ins/driver-postgresql.d.ts +0 -22
- package/lib/db-driver/built-ins/driver-postgresql.js +0 -76
- package/lib/db-driver/built-ins/driver-redis.d.ts +0 -12
- package/lib/db-driver/built-ins/driver-redis.js +0 -35
- package/lib/db-driver/built-ins/driver-sqlite.d.ts +0 -17
- package/lib/db-driver/built-ins/driver-sqlite.js +0 -34
- package/lib/db-driver/index.d.ts +0 -3
- package/lib/db-driver/index.js +0 -4
- package/lib/db-driver/utils.d.ts +0 -14
- package/lib/db-driver/utils.js +0 -187
- package/lib/knex/deps/tarn/dist/PendingOperation.d.ts +0 -12
- package/lib/knex/deps/tarn/dist/PendingOperation.js +0 -48
- package/lib/knex/deps/tarn/dist/Pool.d.ts +0 -97
- package/lib/knex/deps/tarn/dist/Pool.js +0 -516
- package/lib/knex/deps/tarn/dist/PromiseInspection.d.ts +0 -16
- package/lib/knex/deps/tarn/dist/PromiseInspection.js +0 -21
- package/lib/knex/deps/tarn/dist/Resource.d.ts +0 -9
- package/lib/knex/deps/tarn/dist/Resource.js +0 -19
- package/lib/knex/deps/tarn/dist/TimeoutError.d.ts +0 -2
- package/lib/knex/deps/tarn/dist/TimeoutError.js +0 -5
- package/lib/knex/deps/tarn/dist/tarn.d.ts +0 -3
- package/lib/knex/deps/tarn/dist/tarn.js +0 -10
- package/lib/knex/deps/tarn/dist/utils.d.ts +0 -14
- package/lib/knex/deps/tarn/dist/utils.js +0 -60
- package/lib/knex/knex.d.ts +0 -2
- package/lib/knex/knex.js +0 -3
- package/lib/knex/sandbox.d.ts +0 -4
- package/lib/knex/sandbox.js +0 -22
- package/lib/orm/Adapters.d.ts +0 -3
- package/lib/orm/Adapters.js +0 -44
- package/lib/orm/AggregateFunctions.d.ts +0 -3
- package/lib/orm/AggregateFunctions.js +0 -176
- package/lib/orm/Associations/Extend.d.ts +0 -22
- package/lib/orm/Associations/Extend.js +0 -274
- package/lib/orm/Associations/Many.d.ts +0 -17
- package/lib/orm/Associations/Many.js +0 -569
- package/lib/orm/Associations/One.d.ts +0 -16
- package/lib/orm/Associations/One.js +0 -310
- package/lib/orm/Associations/_utils.d.ts +0 -15
- package/lib/orm/Associations/_utils.js +0 -52
- package/lib/orm/ChainFind.d.ts +0 -3
- package/lib/orm/ChainFind.js +0 -327
- package/lib/orm/ChainInstance.d.ts +0 -6
- package/lib/orm/ChainInstance.js +0 -73
- package/lib/orm/Debug.d.ts +0 -2
- package/lib/orm/Debug.js +0 -17
- package/lib/orm/Drivers/DB/base.d.ts +0 -3
- package/lib/orm/Drivers/DB/base.js +0 -3
- package/lib/orm/Drivers/DB/dm.d.ts +0 -11
- package/lib/orm/Drivers/DB/dm.js +0 -23
- package/lib/orm/Drivers/DB/mysql.d.ts +0 -11
- package/lib/orm/Drivers/DB/mysql.js +0 -23
- package/lib/orm/Drivers/DB/postgres.d.ts +0 -11
- package/lib/orm/Drivers/DB/postgres.js +0 -22
- package/lib/orm/Drivers/DB/sqlite3.d.ts +0 -16
- package/lib/orm/Drivers/DB/sqlite3.js +0 -39
- package/lib/orm/Drivers/DML/_ddl-sql.d.ts +0 -3
- package/lib/orm/Drivers/DML/_ddl-sql.js +0 -51
- package/lib/orm/Drivers/DML/_dml-helpers.d.ts +0 -19
- package/lib/orm/Drivers/DML/_dml-helpers.js +0 -51
- package/lib/orm/Drivers/DML/_shared.d.ts +0 -9
- package/lib/orm/Drivers/DML/_shared.js +0 -38
- package/lib/orm/Drivers/DML/_utils.d.ts +0 -8
- package/lib/orm/Drivers/DML/_utils.js +0 -67
- package/lib/orm/Drivers/DML/constants.d.ts +0 -3
- package/lib/orm/Drivers/DML/constants.js +0 -2
- package/lib/orm/Drivers/DML/dm.d.ts +0 -2
- package/lib/orm/Drivers/DML/index.d.ts +0 -4
- package/lib/orm/Drivers/DML/index.js +0 -6
- package/lib/orm/Drivers/DML/mysql.d.ts +0 -2
- package/lib/orm/Drivers/DML/mysql.js +0 -251
- package/lib/orm/Drivers/DML/postgres.d.ts +0 -3
- package/lib/orm/Drivers/DML/postgres.js +0 -276
- package/lib/orm/Drivers/DML/sqlite.d.ts +0 -2
- package/lib/orm/Drivers/DML/sqlite.js +0 -266
- package/lib/orm/Error.d.ts +0 -11
- package/lib/orm/Error.js +0 -40
- package/lib/orm/Helpers.d.ts +0 -35
- package/lib/orm/Helpers.js +0 -233
- package/lib/orm/Hook.d.ts +0 -13
- package/lib/orm/Hook.js +0 -99
- package/lib/orm/Instance.d.ts +0 -2
- package/lib/orm/Instance.js +0 -697
- package/lib/orm/LazyLoad.d.ts +0 -4
- package/lib/orm/LazyLoad.js +0 -76
- package/lib/orm/Model.d.ts +0 -7
- package/lib/orm/Model.js +0 -971
- package/lib/orm/ORM.d.ts +0 -37
- package/lib/orm/ORM.js +0 -241
- package/lib/orm/Patch/fib-cache.js +0 -2
- package/lib/orm/Patch/plugin.d.ts +0 -4
- package/lib/orm/Patch/plugin.js +0 -13
- package/lib/orm/Property.d.ts +0 -9
- package/lib/orm/Property.js +0 -71
- package/lib/orm/Settings.d.ts +0 -42
- package/lib/orm/Settings.js +0 -119
- package/lib/orm/Singleton.d.ts +0 -5
- package/lib/orm/Singleton.js +0 -72
- package/lib/orm/Typo/Adapter.d.ts +0 -5
- package/lib/orm/Typo/Adapter.js +0 -1
- package/lib/orm/Typo/DMLDriver.d.ts +0 -210
- package/lib/orm/Typo/DMLDriver.js +0 -1
- package/lib/orm/Typo/Db.d.ts +0 -38
- package/lib/orm/Typo/Db.js +0 -1
- package/lib/orm/Typo/Error.d.ts +0 -31
- package/lib/orm/Typo/Error.js +0 -1
- package/lib/orm/Typo/ORM.d.ts +0 -233
- package/lib/orm/Typo/ORM.js +0 -3
- package/lib/orm/Typo/Validators.d.ts +0 -32
- package/lib/orm/Typo/Validators.js +0 -2
- package/lib/orm/Typo/_common.d.ts +0 -38
- package/lib/orm/Typo/_common.js +0 -1
- package/lib/orm/Typo/assoc.d.ts +0 -221
- package/lib/orm/Typo/assoc.js +0 -1
- package/lib/orm/Typo/hook.d.ts +0 -42
- package/lib/orm/Typo/hook.js +0 -1
- package/lib/orm/Typo/instance.d.ts +0 -157
- package/lib/orm/Typo/instance.js +0 -1
- package/lib/orm/Typo/model.js +0 -6
- package/lib/orm/Typo/patch.d.ts +0 -31
- package/lib/orm/Typo/patch.js +0 -1
- package/lib/orm/Typo/property.d.ts +0 -57
- package/lib/orm/Typo/property.js +0 -1
- package/lib/orm/Typo/query.d.ts +0 -216
- package/lib/orm/Typo/query.js +0 -1
- package/lib/orm/Typo/settings.js +0 -5
- package/lib/orm/Typo/synchronous.js +0 -1
- package/lib/orm/Utilities.d.ts +0 -179
- package/lib/orm/Utilities.js +0 -975
- package/lib/orm/Validators.d.ts +0 -34
- package/lib/orm/Validators.js +0 -100
- package/lib/orm/Where/common.d.ts +0 -1
- package/lib/orm/Where/common.js +0 -7
- package/lib/orm/Where/filterDate.d.ts +0 -11
- package/lib/orm/Where/filterDate.js +0 -58
- package/lib/orm/index.d.ts +0 -68
- package/lib/orm/index.js +0 -157
- package/lib/orm-core/callback.d.ts +0 -12
- package/lib/orm-core/callback.js +0 -1
- package/lib/orm-core/dialect.js +0 -1
- package/lib/orm-core/error.d.ts +0 -16
- package/lib/orm-core/error.js +0 -29
- package/lib/orm-core/index.js +0 -6
- package/lib/orm-core/sync.d.ts +0 -12
- package/lib/orm-core/sync.js +0 -1
- package/lib/orm-core/utils.d.ts +0 -1
- package/lib/orm-core/utils.js +0 -5
- package/lib/orm-property/Property.d.ts +0 -78
- package/lib/orm-property/Property.js +0 -1
- package/lib/orm-property/Utils.d.ts +0 -9
- package/lib/orm-property/Utils.js +0 -13
- package/lib/orm-property/customTypes.d.ts +0 -2
- package/lib/orm-property/customTypes.js +0 -13
- package/lib/orm-property/index.d.ts +0 -10
- package/lib/orm-property/index.js +0 -22
- package/lib/orm-property/transformer.d.ts +0 -5
- package/lib/orm-property/transformer.js +0 -10
- package/lib/orm-property/transformers/dm.d.ts +0 -29
- package/lib/orm-property/transformers/index.d.ts +0 -4
- package/lib/orm-property/transformers/index.js +0 -5
- package/lib/orm-property/transformers/mysql.d.ts +0 -102
- package/lib/orm-property/transformers/mysql.js +0 -261
- package/lib/orm-property/transformers/postgresql.d.ts +0 -54
- package/lib/orm-property/transformers/postgresql.js +0 -189
- package/lib/orm-property/transformers/sqlite.d.ts +0 -19
- package/lib/orm-property/transformers/sqlite.js +0 -171
- package/lib/sql-ddl-sync/Dialects/dm.d.ts +0 -40
- package/lib/sql-ddl-sync/Dialects/dm.js +0 -296
- package/lib/sql-ddl-sync/Dialects/index.d.ts +0 -7
- package/lib/sql-ddl-sync/Dialects/index.js +0 -7
- package/lib/sql-ddl-sync/Dialects/mysql.d.ts +0 -39
- package/lib/sql-ddl-sync/Dialects/mysql.js +0 -240
- package/lib/sql-ddl-sync/Dialects/postgresql.d.ts +0 -40
- package/lib/sql-ddl-sync/Dialects/postgresql.js +0 -286
- package/lib/sql-ddl-sync/Dialects/sqlite.d.ts +0 -44
- package/lib/sql-ddl-sync/Dialects/sqlite.js +0 -256
- package/lib/sql-ddl-sync/SQL.d.ts +0 -12
- package/lib/sql-ddl-sync/SQL.js +0 -108
- package/lib/sql-ddl-sync/Typo/Collection.d.ts +0 -13
- package/lib/sql-ddl-sync/Typo/Collection.js +0 -1
- package/lib/sql-ddl-sync/Typo/DbIndex.d.ts +0 -13
- package/lib/sql-ddl-sync/Typo/DbIndex.js +0 -1
- package/lib/sql-ddl-sync/Typo/Dialect.js +0 -1
- package/lib/sql-ddl-sync/Typo/Driver.d.ts +0 -53
- package/lib/sql-ddl-sync/Typo/Driver.js +0 -1
- package/lib/sql-ddl-sync/Typo/Query.d.ts +0 -7
- package/lib/sql-ddl-sync/Typo/Query.js +0 -1
- package/lib/sql-ddl-sync/Typo/SQL.d.ts +0 -31
- package/lib/sql-ddl-sync/Typo/SQL.js +0 -1
- package/lib/sql-ddl-sync/Typo/_common.d.ts +0 -29
- package/lib/sql-ddl-sync/Typo/_common.js +0 -1
- package/lib/sql-ddl-sync/Utils.d.ts +0 -40
- package/lib/sql-ddl-sync/Utils.js +0 -217
- package/lib/sql-ddl-sync/index.d.ts +0 -87
- package/lib/sql-ddl-sync/index.js +0 -371
- package/lib/sql-query/Comparators.d.ts +0 -3
- package/lib/sql-query/Comparators.js +0 -94
- package/lib/sql-query/Create.d.ts +0 -35
- package/lib/sql-query/Create.js +0 -77
- package/lib/sql-query/Dialects/dm.d.ts +0 -3
- package/lib/sql-query/Dialects/index.js +0 -12
- package/lib/sql-query/Dialects/mssql.d.ts +0 -3
- package/lib/sql-query/Dialects/mssql.js +0 -73
- package/lib/sql-query/Dialects/mysql.d.ts +0 -3
- package/lib/sql-query/Dialects/mysql.js +0 -100
- package/lib/sql-query/Dialects/postgresql.d.ts +0 -3
- package/lib/sql-query/Dialects/postgresql.js +0 -76
- package/lib/sql-query/Dialects/sqlite.d.ts +0 -3
- package/lib/sql-query/Dialects/sqlite.js +0 -61
- package/lib/sql-query/Helpers.d.ts +0 -38
- package/lib/sql-query/Helpers.js +0 -259
- package/lib/sql-query/Insert.d.ts +0 -12
- package/lib/sql-query/Insert.js +0 -33
- package/lib/sql-query/Query.d.ts +0 -29
- package/lib/sql-query/Query.js +0 -119
- package/lib/sql-query/Remove.d.ts +0 -16
- package/lib/sql-query/Remove.js +0 -93
- package/lib/sql-query/Select.d.ts +0 -62
- package/lib/sql-query/Select.js +0 -533
- package/lib/sql-query/Set.d.ts +0 -4
- package/lib/sql-query/Set.js +0 -16
- package/lib/sql-query/Typo/Aggregation.d.ts +0 -32
- package/lib/sql-query/Typo/Aggregation.js +0 -1
- package/lib/sql-query/Typo/Comparators.d.ts +0 -140
- package/lib/sql-query/Typo/Comparators.js +0 -1
- package/lib/sql-query/Typo/Dialect.d.ts +0 -39
- package/lib/sql-query/Typo/Dialect.js +0 -1
- package/lib/sql-query/Typo/Field.d.ts +0 -8
- package/lib/sql-query/Typo/Field.js +0 -1
- package/lib/sql-query/Typo/Helper.d.ts +0 -4
- package/lib/sql-query/Typo/Helper.js +0 -1
- package/lib/sql-query/Typo/Query-ChainBuilder.d.ts +0 -80
- package/lib/sql-query/Typo/Query-ChainBuilder.js +0 -1
- package/lib/sql-query/Typo/Query.d.ts +0 -34
- package/lib/sql-query/Typo/Query.js +0 -16
- package/lib/sql-query/Typo/Sql.d.ts +0 -143
- package/lib/sql-query/Typo/Sql.js +0 -1
- package/lib/sql-query/Typo/SubQuery.d.ts +0 -39
- package/lib/sql-query/Typo/SubQuery.js +0 -1
- package/lib/sql-query/Typo/index.js +0 -1
- package/lib/sql-query/Update.d.ts +0 -15
- package/lib/sql-query/Update.js +0 -38
- package/lib/sql-query/Where.d.ts +0 -4
- package/lib/sql-query/Where.js +0 -280
- /package/{lib → src}/codepoints-map.json +0 -0
|
@@ -1,81 +1,96 @@
|
|
|
1
|
-
import { IDbDriver } from '../../db-driver/index';
|
|
2
|
-
import { FxOrmCoreCallbackNS, FxOrmDialect } from "../../orm-core/index"
|
|
3
|
-
import { IProperty } from "../../orm-property/index"
|
|
4
|
-
import { IPropTransformer } from '../../orm-property/Property';
|
|
5
|
-
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
import type { IDbDriver } from '../../db-driver/index';
|
|
2
|
+
import type { FxOrmCoreCallbackNS, FxOrmDialect } from "../../orm-core/index"
|
|
3
|
+
import type { IProperty } from "../../orm-property/index"
|
|
4
|
+
import type { IPropTransformer } from '../../orm-property/Property';
|
|
5
|
+
|
|
6
|
+
import type { FxOrmSqlDDLSync__Collection } from "./Collection"
|
|
7
|
+
import type { FxOrmSqlDDLSync__DbIndex } from "./DbIndex"
|
|
8
|
+
import type { FxOrmSqlDDLSync } from "./_common"
|
|
9
|
+
|
|
10
|
+
export namespace FxOrmSqlDDLSync__Dialect{
|
|
11
|
+
export type DialectType = 'mysql' | 'mssql' | 'sqlite' | 'postgresql' | 'dm'
|
|
12
|
+
|
|
13
|
+
export type PurposeToGetRawType = 'alter_table' | 'create_table' | 'add_column' | 'alter_column'
|
|
14
|
+
|
|
11
15
|
type ITypedDriver<T extends IDbDriver.ISQLConn> = IDbDriver.ITypedDriver<T>;
|
|
12
16
|
export interface Dialect<ConnType extends IDbDriver.ISQLConn> extends FxOrmDialect.DDLDialect<ITypedDriver<ConnType>> {
|
|
13
17
|
addForeignKey: {
|
|
14
|
-
(driver: ITypedDriver<ConnType>, tableName: string, options: any, cb: FxOrmCoreCallbackNS.ExecutionCallback<any>): void
|
|
15
|
-
}
|
|
18
|
+
(driver: ITypedDriver<ConnType>, tableName: string, options: any, cb: FxOrmCoreCallbackNS.ExecutionCallback<any>): void
|
|
19
|
+
}
|
|
16
20
|
addForeignKeySync: {
|
|
17
|
-
(driver: ITypedDriver<ConnType>, tableName: string, options: any): any
|
|
18
|
-
}
|
|
21
|
+
(driver: ITypedDriver<ConnType>, tableName: string, options: any): any
|
|
22
|
+
}
|
|
19
23
|
dropForeignKey: {
|
|
20
|
-
(driver: ITypedDriver<ConnType>, tableName: string, columnName: string, cb: FxOrmCoreCallbackNS.ExecutionCallback<any>): void
|
|
21
|
-
}
|
|
24
|
+
(driver: ITypedDriver<ConnType>, tableName: string, columnName: string, cb: FxOrmCoreCallbackNS.ExecutionCallback<any>): void
|
|
25
|
+
}
|
|
22
26
|
dropForeignKeySync: {
|
|
23
|
-
(driver: ITypedDriver<ConnType>, tableName: string, columnName: string): any
|
|
24
|
-
}
|
|
27
|
+
(driver: ITypedDriver<ConnType>, tableName: string, columnName: string): any
|
|
28
|
+
}
|
|
25
29
|
getCollectionProperties: {
|
|
26
|
-
(driver: ITypedDriver<ConnType>, collection: string, cb: FxOrmCoreCallbackNS.ExecutionCallback<Record<string, IProperty>>): void
|
|
27
|
-
}
|
|
30
|
+
(driver: ITypedDriver<ConnType>, collection: string, cb: FxOrmCoreCallbackNS.ExecutionCallback<Record<string, IProperty>>): void
|
|
31
|
+
}
|
|
28
32
|
getCollectionPropertiesSync: {
|
|
29
|
-
(driver: ITypedDriver<ConnType>, collection: string): Record<string, IProperty
|
|
30
|
-
}
|
|
33
|
+
(driver: ITypedDriver<ConnType>, collection: string): Record<string, IProperty>
|
|
34
|
+
}
|
|
31
35
|
getCollectionIndexes: {
|
|
32
|
-
(driver: ITypedDriver<ConnType>, collection: string, cb: FxOrmCoreCallbackNS.ExecutionCallback<Record<string, FxOrmSqlDDLSync__DbIndex.DbIndexInfo>>): void
|
|
33
|
-
}
|
|
36
|
+
(driver: ITypedDriver<ConnType>, collection: string, cb: FxOrmCoreCallbackNS.ExecutionCallback<Record<string, FxOrmSqlDDLSync__DbIndex.DbIndexInfo>>): void
|
|
37
|
+
}
|
|
34
38
|
getCollectionIndexesSync: {
|
|
35
|
-
(driver: ITypedDriver<ConnType>, collection: string): Record<string, FxOrmSqlDDLSync__DbIndex.DbIndexInfo
|
|
36
|
-
}
|
|
39
|
+
(driver: ITypedDriver<ConnType>, collection: string): Record<string, FxOrmSqlDDLSync__DbIndex.DbIndexInfo>
|
|
40
|
+
}
|
|
37
41
|
addIndex: {
|
|
38
|
-
(driver: ITypedDriver<ConnType>, name: string, unique: boolean, collection: FxOrmSqlDDLSync.TableName, columns: string[], cb: FxOrmCoreCallbackNS.ExecutionCallback<any>): void
|
|
39
|
-
}
|
|
42
|
+
(driver: ITypedDriver<ConnType>, name: string, unique: boolean, collection: FxOrmSqlDDLSync.TableName, columns: string[], cb: FxOrmCoreCallbackNS.ExecutionCallback<any>): void
|
|
43
|
+
}
|
|
40
44
|
addIndexSync: {
|
|
41
|
-
(driver: ITypedDriver<ConnType>, name: string, unique: boolean, collection: FxOrmSqlDDLSync.TableName, columns: string[]): any
|
|
42
|
-
}
|
|
45
|
+
(driver: ITypedDriver<ConnType>, name: string, unique: boolean, collection: FxOrmSqlDDLSync.TableName, columns: string[]): any
|
|
46
|
+
}
|
|
43
47
|
removeIndex: {
|
|
44
|
-
(driver: ITypedDriver<ConnType>, name: string, collection: FxOrmSqlDDLSync.TableName, cb: FxOrmCoreCallbackNS.ExecutionCallback<any>): void
|
|
45
|
-
}
|
|
48
|
+
(driver: ITypedDriver<ConnType>, name: string, collection: FxOrmSqlDDLSync.TableName, cb: FxOrmCoreCallbackNS.ExecutionCallback<any>): void
|
|
49
|
+
}
|
|
46
50
|
removeIndexSync: {
|
|
47
|
-
(driver: ITypedDriver<ConnType>, name: string, collection: FxOrmSqlDDLSync.TableName): any
|
|
48
|
-
}
|
|
51
|
+
(driver: ITypedDriver<ConnType>, name: string, collection: FxOrmSqlDDLSync.TableName): any
|
|
52
|
+
}
|
|
49
53
|
/**
|
|
50
54
|
* @description transform semantic property to raw string in db
|
|
51
55
|
* @experimental
|
|
52
56
|
*/
|
|
53
|
-
toRawType: (
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
57
|
+
toRawType: (
|
|
58
|
+
property: PropTransformerParams[0],
|
|
59
|
+
ctx: PropTransformerParams[1] & {
|
|
60
|
+
driver?: ITypedDriver<ConnType>,
|
|
61
|
+
userOptions?: {
|
|
62
|
+
useDefaultValue?: boolean
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
) => ReturnType<IPropTransformer<any>['toStorageType']>
|
|
66
|
+
|
|
59
67
|
/**
|
|
60
68
|
* process composite keys
|
|
61
69
|
*/
|
|
62
70
|
processKeys?: {
|
|
63
|
-
(keys: string[]): string[]
|
|
64
|
-
}
|
|
71
|
+
(keys: string[]): string[]
|
|
72
|
+
}
|
|
65
73
|
/**
|
|
66
74
|
* transform type between property and column
|
|
67
75
|
*/
|
|
68
76
|
supportsType?: {
|
|
69
|
-
(type: string): string
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
|
|
77
|
+
(type: string): string
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
convertIndexes?: <T extends FxOrmSqlDDLSync__DbIndex.DbIndexInfo>(
|
|
81
|
+
collection: FxOrmSqlDDLSync__Collection.Collection['name'],
|
|
82
|
+
db_idxes: T[]
|
|
83
|
+
) => (typeof db_idxes)
|
|
84
|
+
|
|
85
|
+
[extra: string]: any
|
|
73
86
|
}
|
|
87
|
+
|
|
74
88
|
type PropTransformerParams = Parameters<IPropTransformer<any>['toStorageType']>;
|
|
89
|
+
|
|
75
90
|
export interface TypeResult<T = any> {
|
|
76
|
-
|
|
77
|
-
before?: false | (() => any)
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
export
|
|
81
|
-
}
|
|
91
|
+
value: T,
|
|
92
|
+
before?: false | (() => any)
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export type DialectResult<T = any> = TypeResult<T>
|
|
96
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import type { IDbDriver } from "../../db-driver/index";
|
|
2
|
+
import type { FxOrmCoreCallbackNS } from "../../orm-core/index";
|
|
3
|
+
import type { IProperty } from "../../orm-property/index";
|
|
4
|
+
|
|
5
|
+
import type { FxOrmSqlDDLSync__Dialect } from "./Dialect";
|
|
6
|
+
import type { FxOrmSqlDDLSync__DbIndex } from "./DbIndex";
|
|
7
|
+
|
|
8
|
+
export namespace FxOrmSqlDDLSync__Driver {
|
|
9
|
+
export interface CustomPropertyType<T extends IDbDriver.IConnTypeEnum = IDbDriver.IConnTypeEnum> {
|
|
10
|
+
datastoreType(
|
|
11
|
+
prop?: IProperty,
|
|
12
|
+
opts?: {
|
|
13
|
+
collection: string
|
|
14
|
+
driver: IDbDriver<T>
|
|
15
|
+
}
|
|
16
|
+
): string
|
|
17
|
+
valueToProperty?(value?: any, prop?: any): any
|
|
18
|
+
propertyToValue?(value?: any, prop?: any): any
|
|
19
|
+
|
|
20
|
+
[ext_cfg_name: string]: any
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* @description one protocol driver should implement
|
|
25
|
+
*/
|
|
26
|
+
export interface Driver<T extends IDbDriver.IConnTypeEnum> extends IDbDriver<T> {
|
|
27
|
+
dialect: FxOrmSqlDDLSync__Dialect.DialectType
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* @description sync table/collection
|
|
31
|
+
*/
|
|
32
|
+
sync: {
|
|
33
|
+
<T = any>(): T
|
|
34
|
+
<T = any>(cb: FxOrmCoreCallbackNS.ExecutionCallback<T>): void
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* @description drop table/collection
|
|
39
|
+
*/
|
|
40
|
+
drop: {
|
|
41
|
+
<T = any>(): T
|
|
42
|
+
<T = any>(cb: FxOrmCoreCallbackNS.ExecutionCallback<T>): void
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
customTypes?: {
|
|
46
|
+
[type_name: string]: CustomPropertyType<T>
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export interface DbIndexInfo_MySQL extends FxOrmSqlDDLSync__DbIndex.DbIndexInfo {
|
|
51
|
+
index_name: string
|
|
52
|
+
column_name: string
|
|
53
|
+
|
|
54
|
+
non_unique: number|boolean
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export interface DbIndexInfo_PostgreSQL extends FxOrmSqlDDLSync__DbIndex.DbIndexInfo {
|
|
58
|
+
indisprimary: "1" | "0" | boolean
|
|
59
|
+
indisunique: "1" | "0" | boolean
|
|
60
|
+
relname: string
|
|
61
|
+
attname: string
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export interface DbIndexInfo_SQLite extends FxOrmSqlDDLSync__DbIndex.DbIndexInfo {
|
|
65
|
+
unique: boolean
|
|
66
|
+
}
|
|
67
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
export namespace FxOrmSqlDDLSync__SQL {
|
|
2
|
+
export interface TableOptions {
|
|
3
|
+
name: string
|
|
4
|
+
|
|
5
|
+
keys?: string[]
|
|
6
|
+
columns?: string[]
|
|
7
|
+
|
|
8
|
+
comment?: string
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export interface IndexOptions extends TableOptions {
|
|
12
|
+
unique?: boolean
|
|
13
|
+
// table/collection name
|
|
14
|
+
collection?: string
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface TableColumnOptionsBase {
|
|
18
|
+
// table/collection name
|
|
19
|
+
name: string
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface CheckTableHasColumnOptions {
|
|
23
|
+
// table/collection name
|
|
24
|
+
name: string
|
|
25
|
+
// column name
|
|
26
|
+
column: string
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export interface AddColumnOptions extends TableColumnOptionsBase {
|
|
30
|
+
// column name
|
|
31
|
+
column: string
|
|
32
|
+
first?: boolean
|
|
33
|
+
after?: string|false
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export interface AlterColumnOptions extends TableColumnOptionsBase {
|
|
37
|
+
// column name
|
|
38
|
+
column: string
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export interface AlertColumnRenameOptions extends TableColumnOptionsBase {
|
|
42
|
+
oldColName: string
|
|
43
|
+
newColName: string
|
|
44
|
+
}
|
|
45
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import type { IDbDriver } from "../../db-driver/index";
|
|
2
|
+
|
|
3
|
+
import type { IProperty } from '../../orm-property/index';
|
|
4
|
+
import type { ColumnInfoSQLite } from '../../orm-property/transformers/sqlite';
|
|
5
|
+
import type { ColumnInfoMySQL } from '../../orm-property/transformers/mysql';
|
|
6
|
+
import type { ColumnInfoPostgreSQL } from '../../orm-property/transformers/postgresql';
|
|
7
|
+
|
|
8
|
+
import type { FxOrmSqlDDLSync__Dialect } from "./Dialect";
|
|
9
|
+
|
|
10
|
+
export namespace FxOrmSqlDDLSync {
|
|
11
|
+
export type TableName = string
|
|
12
|
+
export type ColumnName = string
|
|
13
|
+
|
|
14
|
+
export interface SyncOptions<ConnType extends IDbDriver.IConnTypeEnum = IDbDriver.IConnTypeEnum> {
|
|
15
|
+
dbdriver: IDbDriver<ConnType>
|
|
16
|
+
debug?: ((...args: any[]) => any) | false
|
|
17
|
+
/**
|
|
18
|
+
* @default true
|
|
19
|
+
*/
|
|
20
|
+
suppressColumnDrop?: boolean
|
|
21
|
+
syncStrategy?: FxOrmSqlDDLSync.SyncCollectionOptions['strategy']
|
|
22
|
+
}
|
|
23
|
+
export interface SyncResult {
|
|
24
|
+
changes: number
|
|
25
|
+
}
|
|
26
|
+
export interface SyncCollectionOptions {
|
|
27
|
+
columns?: Record<string, IProperty>,
|
|
28
|
+
/**
|
|
29
|
+
* @deprecated
|
|
30
|
+
*/
|
|
31
|
+
strategy?: 'soft' | 'hard' | 'mixed'
|
|
32
|
+
/**
|
|
33
|
+
* @default true
|
|
34
|
+
*/
|
|
35
|
+
suppressColumnDrop?: boolean
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
type ITransformCtx = {
|
|
39
|
+
/**
|
|
40
|
+
* @description database's version
|
|
41
|
+
*/
|
|
42
|
+
version?: string
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* @description database's type
|
|
46
|
+
*/
|
|
47
|
+
type?: FxOrmSqlDDLSync__Dialect.DialectType
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* @description collection name
|
|
51
|
+
*/
|
|
52
|
+
collection?: string
|
|
53
|
+
}
|
|
54
|
+
type IGetColumnInfo<T extends IDbDriver.ISQLConn> = T extends Class_MySQL
|
|
55
|
+
? ColumnInfoMySQL
|
|
56
|
+
: T extends Class_SQLite
|
|
57
|
+
? ColumnInfoSQLite
|
|
58
|
+
: any
|
|
59
|
+
}
|
|
@@ -0,0 +1,291 @@
|
|
|
1
|
+
import { createRequire } from 'node:module';
|
|
2
|
+
const require = createRequire(import.meta.url);
|
|
3
|
+
const coroutine = require('coroutine');
|
|
4
|
+
import type { IDbDriver } from "../db-driver/index";
|
|
5
|
+
import type { FxDbDriverNS } from "../db-driver/Typo";
|
|
6
|
+
import type { IProperty } from "../orm-property/index";
|
|
7
|
+
|
|
8
|
+
import type { FxOrmSqlDDLSync } from "./Typo/_common";
|
|
9
|
+
|
|
10
|
+
import type { FxOrmSqlDDLSync__Collection } from "./Typo/Collection";
|
|
11
|
+
|
|
12
|
+
export function logJson (group: string, detail: any) {
|
|
13
|
+
let json = null;
|
|
14
|
+
try {
|
|
15
|
+
json = JSON.stringify(detail, null, '\t');
|
|
16
|
+
} catch (e) {
|
|
17
|
+
throw 'Error occured when trying to log detail';
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
if (process.env.DEBUG)
|
|
21
|
+
console.notice(json)
|
|
22
|
+
|
|
23
|
+
return json
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
import * as sqlQueryDialects from '../sql-query/Dialects';
|
|
27
|
+
import type { FxOrmSqlDDLSync__DbIndex } from './Typo/DbIndex';
|
|
28
|
+
type ISqlQueryDialects = typeof sqlQueryDialects;
|
|
29
|
+
|
|
30
|
+
// ES module namespace objects are not extensible. Keep registered dialects in
|
|
31
|
+
// a separate mutable map instead of trying to add properties to the imported
|
|
32
|
+
// namespace.
|
|
33
|
+
const extraSqlQueryDialects: { [type: string]: any } = Object.create(null);
|
|
34
|
+
|
|
35
|
+
export function addSqlQueryDialect (type: string, Dialect: any) {
|
|
36
|
+
extraSqlQueryDialects[type] = Dialect;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function getAllSqlQueryDialects (type: string) {
|
|
40
|
+
return {
|
|
41
|
+
...sqlQueryDialects,
|
|
42
|
+
...extraSqlQueryDialects,
|
|
43
|
+
psql: sqlQueryDialects['postgresql']
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export function getSqlQueryDialect (type: FxDbDriverNS.DriverType | 'postgresql'): ISqlQueryDialects[keyof ISqlQueryDialects] {
|
|
48
|
+
if (extraSqlQueryDialects[type])
|
|
49
|
+
return extraSqlQueryDialects[type];
|
|
50
|
+
|
|
51
|
+
switch (type) {
|
|
52
|
+
default:
|
|
53
|
+
// some times others libs could mount faked dialect to sqlQueryDialects, allow return it
|
|
54
|
+
return (sqlQueryDialects as any)[type] || null;
|
|
55
|
+
case 'redis':
|
|
56
|
+
throw new Error('[getSqlQueryDialect] unsupported driver type: ' + type)
|
|
57
|
+
case 'postgresql':
|
|
58
|
+
case 'psql':
|
|
59
|
+
return sqlQueryDialects['postgresql'];
|
|
60
|
+
case 'sqlite':
|
|
61
|
+
case 'mysql':
|
|
62
|
+
case 'dm':
|
|
63
|
+
case 'mssql':
|
|
64
|
+
return sqlQueryDialects[type];
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export function arraify<T = any> (item: T | T[]): T[] {
|
|
69
|
+
return Array.isArray(item) ? item : [item]
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export function getCollectionMapsTo_PropertyNameDict (collection: FxOrmSqlDDLSync__Collection.Collection) {
|
|
73
|
+
const hash = {} as {[k: string]: string}
|
|
74
|
+
|
|
75
|
+
Object.keys(collection.properties).forEach(pname => {
|
|
76
|
+
const prop = collection.properties[pname]
|
|
77
|
+
if (prop.mapsTo)
|
|
78
|
+
hash[prop.mapsTo] = pname
|
|
79
|
+
})
|
|
80
|
+
|
|
81
|
+
return hash;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export function filterPropertyDefaultValue (
|
|
85
|
+
property: IProperty,
|
|
86
|
+
ctx: {
|
|
87
|
+
collection: string,
|
|
88
|
+
property: IProperty,
|
|
89
|
+
driver: IDbDriver
|
|
90
|
+
}
|
|
91
|
+
) {
|
|
92
|
+
let _dftValue
|
|
93
|
+
if (property.hasOwnProperty('defaultValue'))
|
|
94
|
+
if (typeof property.defaultValue === 'function') {
|
|
95
|
+
_dftValue = property.defaultValue(ctx)
|
|
96
|
+
} else
|
|
97
|
+
_dftValue = property.defaultValue
|
|
98
|
+
|
|
99
|
+
return _dftValue
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export function filterSyncStrategy (
|
|
103
|
+
strategy: FxOrmSqlDDLSync.SyncCollectionOptions['strategy']
|
|
104
|
+
) {
|
|
105
|
+
switch (strategy) {
|
|
106
|
+
case 'hard':
|
|
107
|
+
case 'soft':
|
|
108
|
+
case 'mixed':
|
|
109
|
+
break
|
|
110
|
+
default:
|
|
111
|
+
strategy = 'soft'
|
|
112
|
+
break
|
|
113
|
+
}
|
|
114
|
+
return strategy
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export function filterSuppressColumnDrop (
|
|
118
|
+
suppressColumnDrop: boolean, db_type: FxDbDriverNS.DriverType
|
|
119
|
+
) {
|
|
120
|
+
if (db_type === 'sqlite')
|
|
121
|
+
return true
|
|
122
|
+
|
|
123
|
+
return !!suppressColumnDrop
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
export function psqlGetEnumTypeName (
|
|
127
|
+
collection_name: string,
|
|
128
|
+
column_name: string
|
|
129
|
+
) {
|
|
130
|
+
return `${collection_name}_enum_${column_name.toLowerCase()}`
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
export function psqlRepairEnumTypes (
|
|
134
|
+
columns: Record<string, IProperty> | IProperty[],
|
|
135
|
+
collection_name: string,
|
|
136
|
+
dbdriver: IDbDriver.ITypedDriver<Class_DbConnection>
|
|
137
|
+
) {
|
|
138
|
+
const enumProperties = Object.values(columns).filter(col => col.type === 'enum');
|
|
139
|
+
if (!enumProperties.length) return ;
|
|
140
|
+
|
|
141
|
+
const sqlQueryDialect = getSqlQueryDialect('psql');
|
|
142
|
+
|
|
143
|
+
const rows = dbdriver.execute<{ typname: string }[]>(
|
|
144
|
+
`SELECT * FROM pg_catalog.pg_type WHERE typname IN ${[ `(${enumProperties.map(p =>
|
|
145
|
+
sqlQueryDialect.escapeVal(
|
|
146
|
+
psqlGetEnumTypeName(collection_name, p.name)
|
|
147
|
+
)
|
|
148
|
+
).join(', ')})`]}`
|
|
149
|
+
);
|
|
150
|
+
const allExistedTypes = new Set(rows.map(row => row.typname));
|
|
151
|
+
const missingEnumTypeProperties = enumProperties.filter(p => !allExistedTypes.has(
|
|
152
|
+
psqlGetEnumTypeName(collection_name, p.name)
|
|
153
|
+
))
|
|
154
|
+
|
|
155
|
+
coroutine.parallel(missingEnumTypeProperties, (property: IProperty) => {
|
|
156
|
+
const type = psqlGetEnumTypeName(collection_name, property.mapsTo!.toLowerCase());
|
|
157
|
+
|
|
158
|
+
const values = property.values!.map(function (val) {
|
|
159
|
+
return sqlQueryDialect.escapeVal(val);
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
dbdriver.execute(`CREATE TYPE ${type} AS ENUM (${values})`);
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* @description compute system's index name by dialect type
|
|
168
|
+
*
|
|
169
|
+
* @param collection collection to indexed
|
|
170
|
+
* @param prop column's property
|
|
171
|
+
*/
|
|
172
|
+
function getIndexName (
|
|
173
|
+
collection: string,
|
|
174
|
+
prop: IProperty,
|
|
175
|
+
dialect_type: string
|
|
176
|
+
) {
|
|
177
|
+
const post = prop.unique ? 'unique' : 'index';
|
|
178
|
+
|
|
179
|
+
if (dialect_type == 'sqlite') {
|
|
180
|
+
return collection + '_' + prop.name + '_' + post;
|
|
181
|
+
} else {
|
|
182
|
+
return prop.name + '_' + post;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* @internal
|
|
187
|
+
*/
|
|
188
|
+
export function extractCollectionIndexes (
|
|
189
|
+
collection: FxOrmSqlDDLSync__Collection.Collection['name'],
|
|
190
|
+
property_key: string,
|
|
191
|
+
property: IProperty,
|
|
192
|
+
driver_type: string,
|
|
193
|
+
ret_indexes: FxOrmSqlDDLSync__DbIndex.CollectionDbIndexInfo[] = []
|
|
194
|
+
): FxOrmSqlDDLSync__DbIndex.CollectionDbIndexInfo[] {
|
|
195
|
+
let found: boolean;
|
|
196
|
+
|
|
197
|
+
if (property.unique) {
|
|
198
|
+
let mixed_arr_unique: (string | true)[] = property.unique as string[]
|
|
199
|
+
if (!Array.isArray(property.unique)) {
|
|
200
|
+
mixed_arr_unique = [ property.unique ];
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
for (let i = 0; i < mixed_arr_unique.length; i++) {
|
|
204
|
+
if (mixed_arr_unique[i] === true) {
|
|
205
|
+
ret_indexes.push({
|
|
206
|
+
collection,
|
|
207
|
+
name : getIndexName(collection, property, driver_type),
|
|
208
|
+
unique : true,
|
|
209
|
+
columns : [ property_key ]
|
|
210
|
+
});
|
|
211
|
+
} else {
|
|
212
|
+
found = false;
|
|
213
|
+
|
|
214
|
+
for (let j = 0; j < ret_indexes.length; j++) {
|
|
215
|
+
if (ret_indexes[j].name == mixed_arr_unique[i]) {
|
|
216
|
+
found = true;
|
|
217
|
+
ret_indexes[j].columns.push(property_key);
|
|
218
|
+
break;
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
if (!found) {
|
|
223
|
+
ret_indexes.push({
|
|
224
|
+
collection,
|
|
225
|
+
name : mixed_arr_unique[i] as string,
|
|
226
|
+
unique : true,
|
|
227
|
+
columns : [ property_key ]
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
if (property.index) {
|
|
235
|
+
let mixed_arr_index: (string | true)[] = property.index as string[]
|
|
236
|
+
if (!Array.isArray(property.index)) {
|
|
237
|
+
mixed_arr_index = [ property.index ];
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
for (let i = 0; i < mixed_arr_index.length; i++) {
|
|
241
|
+
if (mixed_arr_index[i] === true) {
|
|
242
|
+
ret_indexes.push({
|
|
243
|
+
collection,
|
|
244
|
+
name: getIndexName(collection, property, driver_type),
|
|
245
|
+
unique: false,
|
|
246
|
+
columns: [ property_key ]
|
|
247
|
+
});
|
|
248
|
+
} else {
|
|
249
|
+
found = false;
|
|
250
|
+
|
|
251
|
+
for (let j = 0; j < ret_indexes.length; j++) {
|
|
252
|
+
if (ret_indexes[j].name == mixed_arr_index[i]) {
|
|
253
|
+
found = true;
|
|
254
|
+
ret_indexes[j].columns.push(property_key);
|
|
255
|
+
break;
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
if (!found) {
|
|
259
|
+
ret_indexes.push({
|
|
260
|
+
collection,
|
|
261
|
+
name: mixed_arr_index[i] as string,
|
|
262
|
+
columns: [ property_key ],
|
|
263
|
+
unique: false,
|
|
264
|
+
});
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
return ret_indexes;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
/** @internal this will change input */
|
|
274
|
+
export function normalizeDefinedProperty (
|
|
275
|
+
property: IProperty,
|
|
276
|
+
driver_type: string,
|
|
277
|
+
) {
|
|
278
|
+
if (driver_type === 'mysql') {
|
|
279
|
+
/**
|
|
280
|
+
* for mysql, on creating table, column with meta auto_increment
|
|
281
|
+
* should be specified as primary key explicitly on table-level
|
|
282
|
+
*/
|
|
283
|
+
if (property.serial || property.type === 'serial') {
|
|
284
|
+
property.type = 'serial';
|
|
285
|
+
property.key = true;
|
|
286
|
+
property.primary = true;
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
return property;
|
|
291
|
+
}
|