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
|
@@ -0,0 +1,439 @@
|
|
|
1
|
+
import { createRequire } from 'node:module';
|
|
2
|
+
const require = createRequire(import.meta.url);
|
|
3
|
+
import * as FxORMCore from '../../orm-core/index';
|
|
4
|
+
import {type ExtractColumnInfo, transformer} from "../../orm-property/index";
|
|
5
|
+
import type { PropertySQLite } from '../../orm-property/transformers/sqlite';
|
|
6
|
+
|
|
7
|
+
import * as SQL from '../SQL';
|
|
8
|
+
import type { FxOrmSqlDDLSync__Dialect } from "../Typo/Dialect";
|
|
9
|
+
import type { FxOrmSqlDDLSync__Driver } from "../Typo/Driver";
|
|
10
|
+
|
|
11
|
+
import { getSqlQueryDialect, arraify, filterPropertyDefaultValue } from '../Utils';
|
|
12
|
+
|
|
13
|
+
const Transformer = transformer('sqlite')
|
|
14
|
+
|
|
15
|
+
type IDialect = FxOrmSqlDDLSync__Dialect.Dialect<Class_SQLite>;
|
|
16
|
+
|
|
17
|
+
// @see https://www.sqlite.org/lang_altertable.html
|
|
18
|
+
export const hasCollectionSync: IDialect['hasCollectionSync'] = function (
|
|
19
|
+
dbdriver, name
|
|
20
|
+
) {
|
|
21
|
+
const rows = dbdriver.execute<any[]>(
|
|
22
|
+
getSqlQueryDialect('sqlite').escape(
|
|
23
|
+
"SELECT * FROM sqlite_master WHERE type = 'table' and name = ?", [name]
|
|
24
|
+
)
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
return rows.length > 0;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export const hasCollection: IDialect['hasCollection'] = function (
|
|
31
|
+
dbdriver, name, cb
|
|
32
|
+
) {
|
|
33
|
+
const exposedErrResults = FxORMCore.Utils.exposeErrAndResultFromSyncMethod(
|
|
34
|
+
() => hasCollectionSync(dbdriver, name)
|
|
35
|
+
)
|
|
36
|
+
FxORMCore.Utils.throwErrOrCallabckErrResult(exposedErrResults, { no_throw: true, callback: cb });
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* @no_test
|
|
41
|
+
*/
|
|
42
|
+
export const addPrimaryKeySync: IDialect['addPrimaryKeySync'] = function (
|
|
43
|
+
dbdriver, tableName, columnName
|
|
44
|
+
) {
|
|
45
|
+
return dbdriver.execute(
|
|
46
|
+
getSqlQueryDialect('sqlite').escape(
|
|
47
|
+
"ALTER TABLE ?? ADD CONSTRAINT ?? PRIMARY KEY(??);",
|
|
48
|
+
[tableName, columnName + "PK", columnName]
|
|
49
|
+
)
|
|
50
|
+
)
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
export const addPrimaryKey: IDialect['addPrimaryKey'] = function (
|
|
54
|
+
dbdriver, tableName, columnName, cb
|
|
55
|
+
) {
|
|
56
|
+
const exposedErrResults = FxORMCore.Utils.exposeErrAndResultFromSyncMethod(
|
|
57
|
+
() => addPrimaryKeySync(dbdriver, tableName, columnName)
|
|
58
|
+
)
|
|
59
|
+
FxORMCore.Utils.throwErrOrCallabckErrResult(exposedErrResults, { no_throw: true, callback: cb });
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
export const dropPrimaryKeySync: IDialect['dropPrimaryKeySync'] = function (
|
|
63
|
+
dbdriver, tableName, columnName
|
|
64
|
+
) {
|
|
65
|
+
return dbdriver.execute(
|
|
66
|
+
getSqlQueryDialect('sqlite').escape(
|
|
67
|
+
"ALTER TABLE ?? DROP CONSTRAINT ??;",
|
|
68
|
+
[tableName, columnName + "PK"]
|
|
69
|
+
)
|
|
70
|
+
)
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
export const dropPrimaryKey: IDialect['dropPrimaryKey'] = function (
|
|
74
|
+
dbdriver, tableName, columnName, cb
|
|
75
|
+
) {
|
|
76
|
+
const exposedErrResults = FxORMCore.Utils.exposeErrAndResultFromSyncMethod(
|
|
77
|
+
() => dropPrimaryKeySync(dbdriver, tableName, columnName)
|
|
78
|
+
)
|
|
79
|
+
FxORMCore.Utils.throwErrOrCallabckErrResult(exposedErrResults, { no_throw: true, callback: cb });
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
export const addForeignKeySync: IDialect['addForeignKeySync'] = function (
|
|
83
|
+
dbdriver, tableName, options
|
|
84
|
+
) {
|
|
85
|
+
return dbdriver.execute(
|
|
86
|
+
getSqlQueryDialect('sqlite').escape(
|
|
87
|
+
"ALTER TABLE ?? ADD FOREIGN KEY(??) REFERENCES ??(??);",
|
|
88
|
+
[tableName, options.name, options.references.table, options.references.column]
|
|
89
|
+
)
|
|
90
|
+
)
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
export const addForeignKey: IDialect['addForeignKey'] = function (
|
|
94
|
+
dbdriver, tableName, options, cb
|
|
95
|
+
) {
|
|
96
|
+
const exposedErrResults = FxORMCore.Utils.exposeErrAndResultFromSyncMethod(
|
|
97
|
+
() => addForeignKeySync(dbdriver, tableName, options)
|
|
98
|
+
)
|
|
99
|
+
FxORMCore.Utils.throwErrOrCallabckErrResult(exposedErrResults, { no_throw: true, callback: cb });
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
export const dropForeignKeySync: IDialect['dropForeignKeySync'] = function (
|
|
103
|
+
dbdriver, tableName, columnName
|
|
104
|
+
) {
|
|
105
|
+
return dbdriver.execute(
|
|
106
|
+
getSqlQueryDialect('sqlite').escape(
|
|
107
|
+
"ALTER TABLE ?? DROP CONSTRAINT ??;",
|
|
108
|
+
[tableName, tableName + "_" + columnName + "_fkey"]
|
|
109
|
+
)
|
|
110
|
+
)
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
export const dropForeignKey: IDialect['dropForeignKey'] = function (
|
|
114
|
+
dbdriver, tableName, columnName, cb
|
|
115
|
+
) {
|
|
116
|
+
const exposedErrResults = FxORMCore.Utils.exposeErrAndResultFromSyncMethod(
|
|
117
|
+
() => dropForeignKeySync(dbdriver, tableName, columnName)
|
|
118
|
+
)
|
|
119
|
+
FxORMCore.Utils.throwErrOrCallabckErrResult(exposedErrResults, { no_throw: true, callback: cb });
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
export const getCollectionColumnsSync: IDialect['getCollectionColumnsSync'] = function (
|
|
123
|
+
dbdriver, name
|
|
124
|
+
) {
|
|
125
|
+
return dbdriver.execute(
|
|
126
|
+
getSqlQueryDialect('sqlite').escape(
|
|
127
|
+
"PRAGMA table_info(??)", [name]
|
|
128
|
+
)
|
|
129
|
+
)
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
export const getCollectionColumns: IDialect['getCollectionColumns'] = function (
|
|
133
|
+
dbdriver, name, cb
|
|
134
|
+
) {
|
|
135
|
+
const exposedErrResults = FxORMCore.Utils.exposeErrAndResultFromSyncMethod(
|
|
136
|
+
() => getCollectionColumnsSync(dbdriver, name)
|
|
137
|
+
)
|
|
138
|
+
FxORMCore.Utils.throwErrOrCallabckErrResult(exposedErrResults, { no_throw: true, callback: cb });
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
export const getCollectionPropertiesSync: IDialect['getCollectionPropertiesSync'] = function (
|
|
142
|
+
dbdriver, name
|
|
143
|
+
) {
|
|
144
|
+
const cols = getCollectionColumnsSync(dbdriver, name)
|
|
145
|
+
|
|
146
|
+
let columns = {} as { [col: string]: PropertySQLite };
|
|
147
|
+
|
|
148
|
+
for (let i = 0; i < cols.length; i++) {
|
|
149
|
+
const dCol = cols[i];
|
|
150
|
+
|
|
151
|
+
columns[dCol.name] = Transformer.rawToProperty(dCol, {
|
|
152
|
+
collection: name,
|
|
153
|
+
}).property;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
return columns;
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
export const getCollectionProperties: IDialect['getCollectionProperties'] = function (
|
|
160
|
+
dbdriver, name, cb
|
|
161
|
+
) {
|
|
162
|
+
const exposedErrResults = FxORMCore.Utils.exposeErrAndResultFromSyncMethod(
|
|
163
|
+
() => getCollectionPropertiesSync(dbdriver, name)
|
|
164
|
+
)
|
|
165
|
+
FxORMCore.Utils.throwErrOrCallabckErrResult(exposedErrResults, { no_throw: true, callback: cb });
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
export const createCollectionSync: IDialect['createCollectionSync'] = function (
|
|
169
|
+
dbdriver, name, columns, keys, opts
|
|
170
|
+
) {
|
|
171
|
+
return dbdriver.execute(
|
|
172
|
+
SQL.CREATE_TABLE({
|
|
173
|
+
name: name,
|
|
174
|
+
columns: columns,
|
|
175
|
+
keys: keys,
|
|
176
|
+
comment: opts?.comment
|
|
177
|
+
}, 'sqlite')
|
|
178
|
+
)
|
|
179
|
+
};
|
|
180
|
+
|
|
181
|
+
export const createCollection: IDialect['createCollection'] = function (
|
|
182
|
+
dbdriver, name, columns, keys, opts, cb
|
|
183
|
+
) {
|
|
184
|
+
const exposedErrResults = FxORMCore.Utils.exposeErrAndResultFromSyncMethod(
|
|
185
|
+
() => createCollectionSync(dbdriver, name, columns, keys)
|
|
186
|
+
)
|
|
187
|
+
FxORMCore.Utils.throwErrOrCallabckErrResult(exposedErrResults, { no_throw: true, callback: cb });
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
export const dropCollectionSync: IDialect['dropCollectionSync'] = function (
|
|
191
|
+
dbdriver, name
|
|
192
|
+
) {
|
|
193
|
+
return dbdriver.execute(
|
|
194
|
+
SQL.DROP_TABLE({ name: name }, 'sqlite')
|
|
195
|
+
)
|
|
196
|
+
};
|
|
197
|
+
|
|
198
|
+
export const dropCollection: IDialect['dropCollection'] = function (
|
|
199
|
+
dbdriver, name, cb
|
|
200
|
+
) {
|
|
201
|
+
const exposedErrResults = FxORMCore.Utils.exposeErrAndResultFromSyncMethod(
|
|
202
|
+
() => dropCollectionSync(dbdriver, name)
|
|
203
|
+
)
|
|
204
|
+
FxORMCore.Utils.throwErrOrCallabckErrResult(exposedErrResults, { no_throw: true, callback: cb });
|
|
205
|
+
};
|
|
206
|
+
|
|
207
|
+
export const hasCollectionColumnsSync: IDialect['hasCollectionColumnsSync'] = function (
|
|
208
|
+
dbdriver, name, column
|
|
209
|
+
) {
|
|
210
|
+
const cols = getCollectionColumnsSync<ExtractColumnInfo<typeof Transformer>>(dbdriver, name)
|
|
211
|
+
|
|
212
|
+
return arraify(column).every(
|
|
213
|
+
column_name => cols.find(col => col.name === column_name)
|
|
214
|
+
)
|
|
215
|
+
};
|
|
216
|
+
|
|
217
|
+
export const hasCollectionColumns: IDialect['hasCollectionColumns'] = function (
|
|
218
|
+
dbdriver, name, column, cb
|
|
219
|
+
) {
|
|
220
|
+
const exposedErrResults = FxORMCore.Utils.exposeErrAndResultFromSyncMethod(
|
|
221
|
+
() => hasCollectionColumnsSync(dbdriver, name, column)
|
|
222
|
+
)
|
|
223
|
+
FxORMCore.Utils.throwErrOrCallabckErrResult(exposedErrResults, { no_throw: true, callback: cb });
|
|
224
|
+
};
|
|
225
|
+
|
|
226
|
+
export const addCollectionColumnSync: IDialect['addCollectionColumnSync'] = function (
|
|
227
|
+
dbdriver, name, column, after_column
|
|
228
|
+
) {
|
|
229
|
+
// const rows = dbdriver.execute<any[]>(
|
|
230
|
+
// getSqlQueryDialect('sqlite').escape(
|
|
231
|
+
// "SELECT name FROM pragma_table_info(?) ORDER BY cid DESC LIMIT 1;", [name]
|
|
232
|
+
// )
|
|
233
|
+
// )
|
|
234
|
+
|
|
235
|
+
// const lastColName = rows[0].name;
|
|
236
|
+
|
|
237
|
+
// if (after_column && lastColName.toLowerCase() !== after_column.toLowerCase()) {
|
|
238
|
+
// throw new Error(`Only support add column after last column ${lastColName}`);
|
|
239
|
+
// }
|
|
240
|
+
|
|
241
|
+
// after_column = lastColName;
|
|
242
|
+
|
|
243
|
+
return dbdriver.execute(
|
|
244
|
+
SQL.ALTER_TABLE_ADD_COLUMN({
|
|
245
|
+
name: name,
|
|
246
|
+
column: column,
|
|
247
|
+
after: undefined,
|
|
248
|
+
first: undefined
|
|
249
|
+
}, 'sqlite')
|
|
250
|
+
)
|
|
251
|
+
};
|
|
252
|
+
|
|
253
|
+
export const addCollectionColumn: IDialect['addCollectionColumn'] = function (
|
|
254
|
+
dbdriver, name, column, after_column, cb
|
|
255
|
+
) {
|
|
256
|
+
const exposedErrResults = FxORMCore.Utils.exposeErrAndResultFromSyncMethod(
|
|
257
|
+
() => addCollectionColumnSync(dbdriver, name, column, after_column)
|
|
258
|
+
)
|
|
259
|
+
FxORMCore.Utils.throwErrOrCallabckErrResult(exposedErrResults, { no_throw: true, callback: cb });
|
|
260
|
+
};
|
|
261
|
+
|
|
262
|
+
export const renameCollectionColumnSync: IDialect['renameCollectionColumnSync'] = function (
|
|
263
|
+
dbdriver, name,
|
|
264
|
+
oldColName: string,
|
|
265
|
+
newColName: string
|
|
266
|
+
) {
|
|
267
|
+
return dbdriver.execute(
|
|
268
|
+
SQL.ALTER_TABLE_RENAME_COLUMN({
|
|
269
|
+
name: name, oldColName: oldColName, newColName: newColName
|
|
270
|
+
}, 'sqlite')
|
|
271
|
+
)
|
|
272
|
+
};
|
|
273
|
+
|
|
274
|
+
export const renameCollectionColumn: IDialect['renameCollectionColumn'] = function (
|
|
275
|
+
dbdriver, name,
|
|
276
|
+
oldColName: string,
|
|
277
|
+
newColName: string, cb
|
|
278
|
+
) {
|
|
279
|
+
const exposedErrResults = FxORMCore.Utils.exposeErrAndResultFromSyncMethod(
|
|
280
|
+
() => renameCollectionColumnSync(dbdriver, name, oldColName, newColName)
|
|
281
|
+
)
|
|
282
|
+
FxORMCore.Utils.throwErrOrCallabckErrResult(exposedErrResults, { no_throw: true, callback: cb });
|
|
283
|
+
};
|
|
284
|
+
|
|
285
|
+
export const modifyCollectionColumnSync: IDialect['modifyCollectionColumnSync'] = function (
|
|
286
|
+
dbdriver, name, column
|
|
287
|
+
) {
|
|
288
|
+
return dbdriver.execute(
|
|
289
|
+
SQL.ALTER_TABLE_MODIFY_COLUMN({
|
|
290
|
+
name: name,
|
|
291
|
+
column: column
|
|
292
|
+
}, 'sqlite')
|
|
293
|
+
)
|
|
294
|
+
};
|
|
295
|
+
|
|
296
|
+
export const modifyCollectionColumn: IDialect['modifyCollectionColumn'] = function (
|
|
297
|
+
dbdriver, name, column, cb
|
|
298
|
+
) {
|
|
299
|
+
const exposedErrResults = FxORMCore.Utils.exposeErrAndResultFromSyncMethod(
|
|
300
|
+
() => modifyCollectionColumnSync(dbdriver, name, column)
|
|
301
|
+
)
|
|
302
|
+
FxORMCore.Utils.throwErrOrCallabckErrResult(exposedErrResults, { no_throw: true, callback: cb });
|
|
303
|
+
};
|
|
304
|
+
|
|
305
|
+
export const dropCollectionColumnSync: IDialect['dropCollectionColumnSync'] = function (
|
|
306
|
+
dbdriver, name, column
|
|
307
|
+
) {
|
|
308
|
+
throw new Error('sqlite does not support dropping columns')
|
|
309
|
+
};
|
|
310
|
+
|
|
311
|
+
export const dropCollectionColumn: IDialect['dropCollectionColumn'] = function (
|
|
312
|
+
dbdriver, name, column, cb
|
|
313
|
+
) {
|
|
314
|
+
const exposedErrResults = FxORMCore.Utils.exposeErrAndResultFromSyncMethod(
|
|
315
|
+
() => dropCollectionColumnSync(dbdriver, name, column)
|
|
316
|
+
)
|
|
317
|
+
FxORMCore.Utils.throwErrOrCallabckErrResult(exposedErrResults, { no_throw: true, callback: cb });
|
|
318
|
+
};
|
|
319
|
+
|
|
320
|
+
export const getCollectionIndexesSync: IDialect['getCollectionIndexesSync'] = function (
|
|
321
|
+
dbdriver, name
|
|
322
|
+
) {
|
|
323
|
+
const rows = dbdriver.execute<FxOrmSqlDDLSync__Driver.DbIndexInfo_SQLite[]>(
|
|
324
|
+
"PRAGMA index_list(" + getSqlQueryDialect('sqlite').escapeId(name) + ")"
|
|
325
|
+
)
|
|
326
|
+
|
|
327
|
+
const indexes = convertIndexRows(rows);
|
|
328
|
+
|
|
329
|
+
for (let k in indexes) {
|
|
330
|
+
if (k.match(/^sqlite_autoindex/)) {
|
|
331
|
+
delete indexes[k];
|
|
332
|
+
continue;
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
const rows = dbdriver.execute<{ name: string }[]>(
|
|
336
|
+
`PRAGMA index_info(${getSqlQueryDialect('sqlite').escapeVal(k)})`
|
|
337
|
+
)
|
|
338
|
+
|
|
339
|
+
for (let i = 0; i < rows.length; i++) {
|
|
340
|
+
indexes[k].columns.push(rows[i].name);
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
return indexes;
|
|
345
|
+
};
|
|
346
|
+
|
|
347
|
+
export const getCollectionIndexes: IDialect['getCollectionIndexes'] = function (
|
|
348
|
+
dbdriver, name, cb
|
|
349
|
+
) {
|
|
350
|
+
const exposedErrResults = FxORMCore.Utils.exposeErrAndResultFromSyncMethod(
|
|
351
|
+
() => getCollectionIndexesSync(dbdriver, name)
|
|
352
|
+
)
|
|
353
|
+
FxORMCore.Utils.throwErrOrCallabckErrResult(exposedErrResults, { no_throw: true, callback: cb });
|
|
354
|
+
};
|
|
355
|
+
|
|
356
|
+
export const addIndexSync: IDialect['addIndexSync'] = function (
|
|
357
|
+
dbdriver, name, unique, collection, columns
|
|
358
|
+
) {
|
|
359
|
+
return dbdriver.execute(
|
|
360
|
+
SQL.CREATE_INDEX({
|
|
361
|
+
name: name,
|
|
362
|
+
unique: unique,
|
|
363
|
+
collection: collection,
|
|
364
|
+
columns: columns
|
|
365
|
+
}, 'sqlite')
|
|
366
|
+
)
|
|
367
|
+
};
|
|
368
|
+
|
|
369
|
+
export const addIndex: IDialect['addIndex'] = function (
|
|
370
|
+
dbdriver, name, unique, collection, columns, cb
|
|
371
|
+
) {
|
|
372
|
+
const exposedErrResults = FxORMCore.Utils.exposeErrAndResultFromSyncMethod(
|
|
373
|
+
() => addIndexSync(dbdriver, name, unique, collection, columns)
|
|
374
|
+
)
|
|
375
|
+
FxORMCore.Utils.throwErrOrCallabckErrResult(exposedErrResults, { no_throw: true, callback: cb });
|
|
376
|
+
};
|
|
377
|
+
|
|
378
|
+
export const removeIndexSync: IDialect['removeIndexSync'] = function (
|
|
379
|
+
dbdriver, collection, name
|
|
380
|
+
) {
|
|
381
|
+
|
|
382
|
+
return dbdriver.execute(
|
|
383
|
+
`DROP INDEX IF EXISTS ${getSqlQueryDialect('sqlite').escapeId(name)}`
|
|
384
|
+
)
|
|
385
|
+
};
|
|
386
|
+
|
|
387
|
+
export const removeIndex: IDialect['removeIndex'] = function (
|
|
388
|
+
dbdriver, collection, name, cb
|
|
389
|
+
) {
|
|
390
|
+
const exposedErrResults = FxORMCore.Utils.exposeErrAndResultFromSyncMethod(
|
|
391
|
+
() => removeIndexSync(dbdriver, collection, name)
|
|
392
|
+
)
|
|
393
|
+
FxORMCore.Utils.throwErrOrCallabckErrResult(exposedErrResults, { no_throw: true, callback: cb });
|
|
394
|
+
};
|
|
395
|
+
|
|
396
|
+
export const processKeys: IDialect['processKeys'] = function (keys) {
|
|
397
|
+
if (keys.length === 1) {
|
|
398
|
+
return [];
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
return keys;
|
|
402
|
+
};
|
|
403
|
+
|
|
404
|
+
export const supportsType: IDialect['supportsType'] = function (type) {
|
|
405
|
+
switch (type) {
|
|
406
|
+
case "boolean":
|
|
407
|
+
case "enum":
|
|
408
|
+
return "number";
|
|
409
|
+
}
|
|
410
|
+
return type;
|
|
411
|
+
};
|
|
412
|
+
|
|
413
|
+
export const toRawType: IDialect['toRawType'] = function (property, ctx) {
|
|
414
|
+
return Transformer.toStorageType(property, {
|
|
415
|
+
collection: ctx.collection,
|
|
416
|
+
customTypes: ctx.driver?.customTypes,
|
|
417
|
+
escapeVal: getSqlQueryDialect(ctx.driver?.type || 'sqlite').escapeVal,
|
|
418
|
+
userOptions: {
|
|
419
|
+
useDefaultValue: ctx.userOptions?.useDefaultValue,
|
|
420
|
+
}
|
|
421
|
+
});
|
|
422
|
+
};
|
|
423
|
+
|
|
424
|
+
function convertIndexRows(
|
|
425
|
+
rows: FxOrmSqlDDLSync__Driver.DbIndexInfo_SQLite[]
|
|
426
|
+
): {[k: string]: FxOrmSqlDDLSync__Driver.DbIndexInfo_SQLite} {
|
|
427
|
+
const indexes = {} as {[k: string]: FxOrmSqlDDLSync__Driver.DbIndexInfo_SQLite};
|
|
428
|
+
|
|
429
|
+
for (let i = 0; i < rows.length; i++) {
|
|
430
|
+
if (!indexes.hasOwnProperty(rows[i].name!)) {
|
|
431
|
+
indexes[rows[i].name!] = {
|
|
432
|
+
columns: [],
|
|
433
|
+
unique: rows[i].unique
|
|
434
|
+
};
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
return indexes;
|
|
439
|
+
}
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import type { FxOrmSqlDDLSync__SQL } from './Typo/SQL';
|
|
2
|
+
import { getSqlQueryDialect } from './Utils';
|
|
3
|
+
import type { FxDbDriverNS } from "../db-driver/Typo";
|
|
4
|
+
|
|
5
|
+
export function CREATE_TABLE (
|
|
6
|
+
options: FxOrmSqlDDLSync__SQL.TableOptions,
|
|
7
|
+
db_type: FxDbDriverNS.DriverType,
|
|
8
|
+
) {
|
|
9
|
+
let sql = "CREATE TABLE " + getSqlQueryDialect(db_type).escapeId(options.name) + " (" + options.columns!.join(", ");
|
|
10
|
+
|
|
11
|
+
if (options.keys && options.keys.length > 0) {
|
|
12
|
+
sql += ", PRIMARY KEY (" + options.keys.map(function (val) {
|
|
13
|
+
return getSqlQueryDialect(db_type).escapeId(val);
|
|
14
|
+
}).join(", ") + ")";
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
sql += ")";
|
|
18
|
+
|
|
19
|
+
if (options.comment && db_type === 'mysql') {
|
|
20
|
+
sql += ` COMMENT ${getSqlQueryDialect(db_type).escapeVal(options.comment)}`;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return sql;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export function ALTER_TABLE_COMMENT (
|
|
27
|
+
db_type: FxDbDriverNS.DriverType,
|
|
28
|
+
table: string,
|
|
29
|
+
comment?: string
|
|
30
|
+
) {
|
|
31
|
+
switch (db_type) {
|
|
32
|
+
case 'mysql': {
|
|
33
|
+
return `ALTER TABLE ${getSqlQueryDialect(db_type).escapeId(table)} COMMENT ${getSqlQueryDialect(db_type).escapeVal(comment || '')}`;
|
|
34
|
+
}
|
|
35
|
+
case 'psql': {
|
|
36
|
+
return `COMMENT ON TABLE ${getSqlQueryDialect(db_type).escapeId(table)} IS ${comment ? getSqlQueryDialect(db_type).escapeVal(comment) : 'null'}`;
|
|
37
|
+
}
|
|
38
|
+
case 'dm': {
|
|
39
|
+
return `COMMENT ON TABLE ${getSqlQueryDialect(db_type).escapeId(table)} IS ${comment ? getSqlQueryDialect(db_type).escapeVal(comment) : 'null'}`;
|
|
40
|
+
}
|
|
41
|
+
case 'mssql': {
|
|
42
|
+
const nv = (value: string) => `N'${String(value).replace(/'/g, "''")}'`;
|
|
43
|
+
const args = `@name=N'MS_Description', @value=${nv(comment || '')}, @level0type=N'SCHEMA', @level0name=@schema, @level1type=N'TABLE', @level1name=${nv(table)}`;
|
|
44
|
+
return `DECLARE @schema sysname = SCHEMA_NAME(); BEGIN TRY EXEC sp_updateextendedproperty ${args} END TRY BEGIN CATCH EXEC sp_addextendedproperty ${args} END CATCH`;
|
|
45
|
+
}
|
|
46
|
+
case 'sqlite':
|
|
47
|
+
default: {
|
|
48
|
+
throw new Error(`[SQL] ALTER_TABLE_COMMENT: not supported db_type: ${db_type}!`)
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export function DROP_TABLE (
|
|
54
|
+
options: FxOrmSqlDDLSync__SQL.TableOptions,
|
|
55
|
+
db_type: FxDbDriverNS.DriverType,
|
|
56
|
+
) {
|
|
57
|
+
const sql = "DROP TABLE " + getSqlQueryDialect(db_type).escapeId(options.name);
|
|
58
|
+
|
|
59
|
+
return sql;
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
export function CHECK_TABLE_HAS_COLUMN (
|
|
63
|
+
options: FxOrmSqlDDLSync__SQL.CheckTableHasColumnOptions,
|
|
64
|
+
db_type: FxDbDriverNS.DriverType,
|
|
65
|
+
) {
|
|
66
|
+
const eid = getSqlQueryDialect(db_type).escapeId;
|
|
67
|
+
const evalue = getSqlQueryDialect(db_type).escapeVal;
|
|
68
|
+
const sql = [
|
|
69
|
+
db_type === 'mysql'
|
|
70
|
+
? `SHOW FULL COLUMNS FROM ${eid(options.name)} LIKE ${evalue(options.column)}`
|
|
71
|
+
: db_type === 'dm'
|
|
72
|
+
? `SELECT COLUMN_NAME FROM ALL_TAB_COLUMNS WHERE TABLE_NAME = UPPER(${evalue(options.name)}) AND COLUMN_NAME = UPPER(${evalue(options.column)}) AND OWNER = USER`
|
|
73
|
+
: db_type === 'mssql'
|
|
74
|
+
? `SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = ${evalue(options.name)} AND COLUMN_NAME = ${evalue(options.column)} AND TABLE_SCHEMA = SCHEMA_NAME()`
|
|
75
|
+
: `SHOW COLUMNS FROM ${eid(options.name)} LIKE ${evalue(options.column)}`
|
|
76
|
+
].filter(x => x).join('')
|
|
77
|
+
|
|
78
|
+
return sql;
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
export function ALTER_TABLE_ADD_COLUMN (
|
|
82
|
+
options: FxOrmSqlDDLSync__SQL.AddColumnOptions,
|
|
83
|
+
db_type: FxDbDriverNS.DriverType,
|
|
84
|
+
) {
|
|
85
|
+
const sql = [
|
|
86
|
+
"ALTER TABLE " + getSqlQueryDialect(db_type).escapeId(options.name),
|
|
87
|
+
" ADD " + options.column,
|
|
88
|
+
db_type !== 'dm' && db_type !== 'mssql' && options.after && " AFTER " + getSqlQueryDialect(db_type).escapeId(options.after),
|
|
89
|
+
db_type !== 'dm' && db_type !== 'mssql' && options.first && " FIRST",
|
|
90
|
+
].filter(x => x).join('')
|
|
91
|
+
|
|
92
|
+
return sql;
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
export function ALTER_TABLE_RENAME_COLUMN (
|
|
96
|
+
opts: FxOrmSqlDDLSync__SQL.AlertColumnRenameOptions,
|
|
97
|
+
db_type: FxDbDriverNS.DriverType,
|
|
98
|
+
) {
|
|
99
|
+
const eid = getSqlQueryDialect(db_type).escapeId;
|
|
100
|
+
const evalue = getSqlQueryDialect(db_type).escapeVal;
|
|
101
|
+
|
|
102
|
+
if (db_type === 'mssql') {
|
|
103
|
+
return `EXEC sp_rename ${evalue(`${opts.name}.${opts.oldColName}`)}, ${evalue(opts.newColName)}, 'COLUMN'`;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
const sql = "ALTER TABLE " + eid(opts.name) +
|
|
107
|
+
" RENAME COLUMN " + eid(opts.oldColName) + " TO " + eid(opts.newColName);
|
|
108
|
+
|
|
109
|
+
return sql;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export function ALTER_TABLE_MODIFY_COLUMN (
|
|
113
|
+
options: FxOrmSqlDDLSync__SQL.AlterColumnOptions,
|
|
114
|
+
db_type: FxDbDriverNS.DriverType,
|
|
115
|
+
) {
|
|
116
|
+
const sql = "ALTER TABLE " + getSqlQueryDialect(db_type).escapeId(options.name) +
|
|
117
|
+
(db_type === 'mssql' ? " ALTER COLUMN " : " MODIFY ") + options.column;
|
|
118
|
+
|
|
119
|
+
return sql;
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
export function ALTER_TABLE_DROP_COLUMN (
|
|
123
|
+
options: FxOrmSqlDDLSync__SQL.AlterColumnOptions,
|
|
124
|
+
db_type: FxDbDriverNS.DriverType,
|
|
125
|
+
) {
|
|
126
|
+
const sql = "ALTER TABLE " + getSqlQueryDialect(db_type).escapeId(options.name) +
|
|
127
|
+
(db_type === 'dm' || db_type === 'mssql' ? " DROP COLUMN " : " DROP ") + getSqlQueryDialect(db_type).escapeId(options.column);
|
|
128
|
+
|
|
129
|
+
return sql;
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
export function CREATE_INDEX (
|
|
133
|
+
options: FxOrmSqlDDLSync__SQL.IndexOptions,
|
|
134
|
+
db_type: FxDbDriverNS.DriverType,
|
|
135
|
+
) {
|
|
136
|
+
const sql = "CREATE" + (options.unique ? " UNIQUE" : "") + " INDEX " + getSqlQueryDialect(db_type).escapeId(options.name) +
|
|
137
|
+
" ON " + getSqlQueryDialect(db_type).escapeId(options.collection!) +
|
|
138
|
+
" (" + options.columns!.map(function (col) { return getSqlQueryDialect(db_type).escapeId(col); }) + ")";
|
|
139
|
+
|
|
140
|
+
return sql;
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
export function DROP_INDEX (
|
|
144
|
+
options: FxOrmSqlDDLSync__SQL.IndexOptions,
|
|
145
|
+
db_type: FxDbDriverNS.DriverType,
|
|
146
|
+
) {
|
|
147
|
+
const sql = db_type === 'dm'
|
|
148
|
+
? "DROP INDEX " + getSqlQueryDialect(db_type).escapeId(options.name)
|
|
149
|
+
: "DROP INDEX " + getSqlQueryDialect(db_type).escapeId(options.name) +
|
|
150
|
+
" ON " + getSqlQueryDialect(db_type).escapeId(options.collection!);
|
|
151
|
+
|
|
152
|
+
return sql;
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
// export function RENAME_TABLE (options, driver: FxOrmSqlDDLSync__Driver.Driver) {
|
|
156
|
+
// const sql = "ALTER TABLE " + options.oldCollectionName + " RENAME TO " + options.newCollectionName + " ;";
|
|
157
|
+
// }
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { IProperty } from "../../orm-property/index";
|
|
2
|
+
import type { FxOrmSqlDDLSync__DbIndex } from "./DbIndex";
|
|
3
|
+
|
|
4
|
+
export namespace FxOrmSqlDDLSync__Collection {
|
|
5
|
+
export interface Collection {
|
|
6
|
+
// table name
|
|
7
|
+
name: string
|
|
8
|
+
properties: Record<string, IProperty>
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* @description collection level comment, pointless for some database such as sqlite
|
|
12
|
+
*/
|
|
13
|
+
comment: string
|
|
14
|
+
|
|
15
|
+
index_defs: FxOrmSqlDDLSync__DbIndex.CollectionDbIndexInfo[]
|
|
16
|
+
|
|
17
|
+
// [ext_k: string]: any
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export namespace FxOrmSqlDDLSync__DbIndex {
|
|
2
|
+
export interface DbIndexInfo {
|
|
3
|
+
name?: string
|
|
4
|
+
columns: (string | { string: number, column: string })[]
|
|
5
|
+
unique?: boolean
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export interface CollectionDbIndexInfo extends Required<DbIndexInfo> {
|
|
9
|
+
collection: string
|
|
10
|
+
}
|
|
11
|
+
}
|