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,371 +0,0 @@
|
|
|
1
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2
|
-
exports.Sync = exports.dialect = void 0;
|
|
3
|
-
const FxORMCore = require("../orm-core/index");
|
|
4
|
-
const util = require("util");
|
|
5
|
-
const Utils_1 = require("./Utils");
|
|
6
|
-
require("./Dialects");
|
|
7
|
-
const index_1 = require("../orm-property/index");
|
|
8
|
-
const SQL_1 = require("./SQL");
|
|
9
|
-
const noOp = () => { };
|
|
10
|
-
function dialect(name) {
|
|
11
|
-
const Dialects = require('./Dialects');
|
|
12
|
-
switch (name) {
|
|
13
|
-
case 'psql':
|
|
14
|
-
case 'postgresql':
|
|
15
|
-
return Dialects['postgresql'];
|
|
16
|
-
case 'sqlite':
|
|
17
|
-
case 'mssql':
|
|
18
|
-
case 'mysql':
|
|
19
|
-
case 'dm':
|
|
20
|
-
return Dialects[name];
|
|
21
|
-
default:
|
|
22
|
-
throw new Error(`no dialect with name '${name}'`);
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
exports.dialect = dialect;
|
|
26
|
-
function alterCollectionComment(collection, dbdriver) {
|
|
27
|
-
if (dbdriver.type === 'sqlite')
|
|
28
|
-
return;
|
|
29
|
-
// don't remove old comment if not provided
|
|
30
|
-
if (!collection.comment)
|
|
31
|
-
return '';
|
|
32
|
-
dbdriver.execute((0, SQL_1.ALTER_TABLE_COMMENT)(dbdriver.type, collection.name, collection.comment));
|
|
33
|
-
}
|
|
34
|
-
function updateColumnsComment(collection, dbdriver, remote_properties) {
|
|
35
|
-
if (dbdriver.type !== 'psql' && dbdriver.type !== 'dm')
|
|
36
|
-
return;
|
|
37
|
-
// TODO: support mysql also
|
|
38
|
-
const dialect = (0, Utils_1.getSqlQueryDialect)(dbdriver.type);
|
|
39
|
-
for (let k in collection.properties) {
|
|
40
|
-
const prop = collection.properties[k];
|
|
41
|
-
if (!prop.comment)
|
|
42
|
-
continue;
|
|
43
|
-
const remote_prop = remote_properties[k];
|
|
44
|
-
const mapsTo = prop.mapsTo || k;
|
|
45
|
-
if (!mapsTo) {
|
|
46
|
-
this.debug(`[updateColumnsComment] No mapsTo for property '${k}' in collection '${collection.name}'`);
|
|
47
|
-
continue;
|
|
48
|
-
}
|
|
49
|
-
if (remote_prop.comment === prop.comment)
|
|
50
|
-
continue;
|
|
51
|
-
dbdriver.execute(dialect.escape(`comment on column ??.?? is ?`, [collection.name, mapsTo, prop.comment]));
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* @description iterate collection, create property's column which didn't exist.
|
|
56
|
-
*
|
|
57
|
-
* @param collection
|
|
58
|
-
* @param force_sync (dangerous) if force re-syncing property to column
|
|
59
|
-
*/
|
|
60
|
-
function processCollection(syncInstnace, collection, opts) {
|
|
61
|
-
let has;
|
|
62
|
-
let is_processed = false;
|
|
63
|
-
has = syncInstnace.Dialect.hasCollectionSync(syncInstnace.dbdriver, collection.name);
|
|
64
|
-
if (!has) {
|
|
65
|
-
syncInstnace.createCollection(collection);
|
|
66
|
-
is_processed = true;
|
|
67
|
-
}
|
|
68
|
-
const { strategy = syncInstnace.strategy } = opts || {};
|
|
69
|
-
alterCollectionComment(collection, syncInstnace.dbdriver);
|
|
70
|
-
switch (strategy) {
|
|
71
|
-
case 'soft':
|
|
72
|
-
return is_processed;
|
|
73
|
-
case 'mixed':
|
|
74
|
-
case 'hard':
|
|
75
|
-
break;
|
|
76
|
-
}
|
|
77
|
-
syncInstnace.syncCollection(collection, { strategy });
|
|
78
|
-
return true;
|
|
79
|
-
}
|
|
80
|
-
/**
|
|
81
|
-
* @param collection_name table where column created
|
|
82
|
-
* @param prop column's property
|
|
83
|
-
*/
|
|
84
|
-
function getColumnTypeRaw(syncInstance, collection_name, prop, opts) {
|
|
85
|
-
var _a;
|
|
86
|
-
let type;
|
|
87
|
-
/**
|
|
88
|
-
* get type, customTypes first
|
|
89
|
-
*/
|
|
90
|
-
if (syncInstance.types.hasOwnProperty(prop.type)) {
|
|
91
|
-
type = syncInstance.types[prop.type].datastoreType(prop);
|
|
92
|
-
}
|
|
93
|
-
else { // fallback to driver's types
|
|
94
|
-
const { for: _for = 'create_table' } = opts || {};
|
|
95
|
-
const dbtype = syncInstance.dbdriver.type;
|
|
96
|
-
type = (0, index_1.transformer)(dbtype).toStorageType(prop, {
|
|
97
|
-
collection: collection_name,
|
|
98
|
-
customTypes: (_a = syncInstance.dbdriver) === null || _a === void 0 ? void 0 : _a.customTypes,
|
|
99
|
-
escapeVal: (0, Utils_1.getSqlQueryDialect)(dbtype).escapeVal,
|
|
100
|
-
userOptions: {
|
|
101
|
-
useDefaultValue: _for === 'create_table' || (dbtype === 'sqlite' && ['add_column', 'alter_column'].includes(_for)),
|
|
102
|
-
}
|
|
103
|
-
}).typeValue;
|
|
104
|
-
}
|
|
105
|
-
if (!type)
|
|
106
|
-
return false;
|
|
107
|
-
if (typeof type == "string") {
|
|
108
|
-
type = { value: type };
|
|
109
|
-
}
|
|
110
|
-
if (prop.mapsTo === undefined)
|
|
111
|
-
throw new Error("undefined prop.mapsTo" + JSON.stringify(prop));
|
|
112
|
-
return {
|
|
113
|
-
value: (0, Utils_1.getSqlQueryDialect)(syncInstance.dbdriver.type).escapeId(prop.mapsTo) + " " + type.value,
|
|
114
|
-
};
|
|
115
|
-
}
|
|
116
|
-
class Sync {
|
|
117
|
-
constructor(options) {
|
|
118
|
-
this.strategy = 'soft';
|
|
119
|
-
const dbdriver = options.dbdriver;
|
|
120
|
-
this.suppressColumnDrop = (0, Utils_1.filterSuppressColumnDrop)(options.suppressColumnDrop !== false, dbdriver.type);
|
|
121
|
-
this.strategy = (0, Utils_1.filterSyncStrategy)(options.syncStrategy);
|
|
122
|
-
this.debug = typeof options.debug === 'function' ? options.debug : noOp;
|
|
123
|
-
Object.defineProperty(this, 'types', { value: {}, writable: false });
|
|
124
|
-
Object.defineProperty(this, 'collections', { value: [], writable: false });
|
|
125
|
-
Object.defineProperty(this, 'dbdriver', { value: dbdriver, writable: false });
|
|
126
|
-
Object.defineProperty(this, 'Dialect', { value: dialect(dbdriver.type), writable: false });
|
|
127
|
-
}
|
|
128
|
-
defineCollection(collection_name, properties, options) {
|
|
129
|
-
let collectionIdx = this.collections.findIndex(collection => collection.name === collection_name);
|
|
130
|
-
if (collectionIdx >= 0)
|
|
131
|
-
this.collections.splice(collectionIdx, 1);
|
|
132
|
-
properties = Object.assign({}, properties);
|
|
133
|
-
let index_defs = [];
|
|
134
|
-
for (let k in properties) {
|
|
135
|
-
// reassign it
|
|
136
|
-
properties[k] = Object.assign({}, properties[k]);
|
|
137
|
-
properties[k].mapsTo = properties[k].mapsTo || k;
|
|
138
|
-
(0, Utils_1.extractCollectionIndexes)(collection_name, k, properties[k], this.dbdriver.type, index_defs);
|
|
139
|
-
(0, Utils_1.normalizeDefinedProperty)(properties[k], this.dbdriver.type);
|
|
140
|
-
}
|
|
141
|
-
if (typeof this.Dialect.convertIndexes === 'function') {
|
|
142
|
-
index_defs = this.Dialect.convertIndexes(collection_name, index_defs);
|
|
143
|
-
}
|
|
144
|
-
this.collections.push({
|
|
145
|
-
name: collection_name,
|
|
146
|
-
properties,
|
|
147
|
-
index_defs,
|
|
148
|
-
comment: options === null || options === void 0 ? void 0 : options.comment,
|
|
149
|
-
});
|
|
150
|
-
return this;
|
|
151
|
-
}
|
|
152
|
-
findCollection(collection_name) {
|
|
153
|
-
return this.collections.find(collection => collection.name === collection_name) || null;
|
|
154
|
-
}
|
|
155
|
-
defineType(type, proto) {
|
|
156
|
-
this.types[type] = proto;
|
|
157
|
-
return this;
|
|
158
|
-
}
|
|
159
|
-
/**
|
|
160
|
-
* @description
|
|
161
|
-
* create collection in db if it doesn't exist, then sync all columns for it.
|
|
162
|
-
*
|
|
163
|
-
* @param collection collection relation to create
|
|
164
|
-
*/
|
|
165
|
-
createCollection(collection) {
|
|
166
|
-
const columns = [];
|
|
167
|
-
let keys = [];
|
|
168
|
-
for (let k in collection.properties) {
|
|
169
|
-
let property = collection.properties[k], col;
|
|
170
|
-
col = getColumnTypeRaw(this, collection.name, property, { for: 'create_table' });
|
|
171
|
-
if (col === false) {
|
|
172
|
-
(0, Utils_1.logJson)('createCollection', property);
|
|
173
|
-
throw new Error(`Invalid type definition for property '${k}'.`);
|
|
174
|
-
}
|
|
175
|
-
if (property.key)
|
|
176
|
-
keys.push(property.mapsTo);
|
|
177
|
-
columns.push(col.value);
|
|
178
|
-
}
|
|
179
|
-
this.debug("Creating " + collection.name);
|
|
180
|
-
// ? TODO: what it means?
|
|
181
|
-
if (typeof this.Dialect.processKeys === "function")
|
|
182
|
-
keys = this.Dialect.processKeys(keys);
|
|
183
|
-
this.total_changes += 1;
|
|
184
|
-
if (this.dbdriver.type === 'psql') {
|
|
185
|
-
(0, Utils_1.psqlRepairEnumTypes)(collection.properties, collection.name, this.dbdriver);
|
|
186
|
-
}
|
|
187
|
-
const result_1 = this.Dialect.createCollectionSync(this.dbdriver, collection.name, columns, keys, { comment: collection.comment });
|
|
188
|
-
this.syncIndexes(collection.name, collection.index_defs);
|
|
189
|
-
updateColumnsComment(collection, this.dbdriver, this.Dialect.getCollectionPropertiesSync(this.dbdriver, collection.name));
|
|
190
|
-
return result_1;
|
|
191
|
-
}
|
|
192
|
-
/**
|
|
193
|
-
* @description
|
|
194
|
-
* compare/diff properties between definition ones and the real ones,
|
|
195
|
-
* then sync column in definition but missing in the real
|
|
196
|
-
*
|
|
197
|
-
* @param collection collection properties user provided
|
|
198
|
-
* @param opts
|
|
199
|
-
* - opts.columns: properties from user(default from db)
|
|
200
|
-
* - opts.strategy: (default soft) strategy when conflict between local and remote db, see details below
|
|
201
|
-
*
|
|
202
|
-
* @strategy
|
|
203
|
-
* - 'soft': no change
|
|
204
|
-
* - 'mixed': add missing columns, but never change existed column in db
|
|
205
|
-
* - 'hard': modify existed columns in db
|
|
206
|
-
*/
|
|
207
|
-
syncCollection(_collection, opts) {
|
|
208
|
-
const collection = typeof _collection === 'string' ? this.findCollection(_collection) : _collection;
|
|
209
|
-
if (!collection)
|
|
210
|
-
throw new Error('[syncCollection] invalid collection');
|
|
211
|
-
let { columns = this.Dialect.getCollectionPropertiesSync(this.dbdriver, collection.name), strategy = this.strategy, suppressColumnDrop = this.suppressColumnDrop } = opts || {};
|
|
212
|
-
suppressColumnDrop = (0, Utils_1.filterSuppressColumnDrop)(suppressColumnDrop, this.dbdriver.type);
|
|
213
|
-
strategy = (0, Utils_1.filterSyncStrategy)(strategy);
|
|
214
|
-
let last_k = null;
|
|
215
|
-
this.debug("Synchronizing " + collection.name);
|
|
216
|
-
if (strategy !== 'soft') {
|
|
217
|
-
for (let k in collection.properties) {
|
|
218
|
-
const prop = collection.properties[k];
|
|
219
|
-
if (!columns.hasOwnProperty(k)) {
|
|
220
|
-
prop.mapsTo = prop.mapsTo || k;
|
|
221
|
-
const col = getColumnTypeRaw(this, collection.name, prop, { for: 'add_column' });
|
|
222
|
-
if (col === false) {
|
|
223
|
-
(0, Utils_1.logJson)('syncCollection', prop);
|
|
224
|
-
throw new Error(`Invalid type definition for property '${k}'.`);
|
|
225
|
-
}
|
|
226
|
-
this.debug("Adding column " + collection.name + "." + k + ": " + col.value);
|
|
227
|
-
// check existence again
|
|
228
|
-
if (!this.Dialect.hasCollectionColumnsSync(this.dbdriver, collection.name, prop.mapsTo)) {
|
|
229
|
-
this.Dialect.addCollectionColumnSync(this.dbdriver, collection.name, col.value,
|
|
230
|
-
// for sqlite, added column must be the last one,
|
|
231
|
-
// we pass empty string to make `addCollectionColumnSync`
|
|
232
|
-
// find last column automatically
|
|
233
|
-
this.dbdriver.type === 'sqlite' ? '' : last_k);
|
|
234
|
-
this.total_changes += 1;
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
else if (strategy === 'hard' &&
|
|
238
|
-
this.dbdriver.type !== 'sqlite'
|
|
239
|
-
&& this.needDefinitionToColumn(prop, columns[k], { collection: collection.name })) {
|
|
240
|
-
const col = getColumnTypeRaw(this, collection.name, prop, { for: 'alter_column' });
|
|
241
|
-
if (col === false) {
|
|
242
|
-
(0, Utils_1.logJson)('syncCollection', prop);
|
|
243
|
-
throw new Error(`Invalid type definition for property '${k}'.`);
|
|
244
|
-
}
|
|
245
|
-
this.debug("Modifying column " + collection.name + "." + k + ": " + col.value);
|
|
246
|
-
// check existence again
|
|
247
|
-
if (this.Dialect.hasCollectionColumnsSync(this.dbdriver, collection.name, prop.mapsTo)) {
|
|
248
|
-
this.Dialect.modifyCollectionColumnSync(this.dbdriver, collection.name, col.value);
|
|
249
|
-
this.total_changes += 1;
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
last_k = k;
|
|
253
|
-
}
|
|
254
|
-
if (strategy === 'hard' && !suppressColumnDrop) {
|
|
255
|
-
const hash = (0, Utils_1.getCollectionMapsTo_PropertyNameDict)(collection);
|
|
256
|
-
for (let colname in columns) {
|
|
257
|
-
if (collection.properties.hasOwnProperty(colname))
|
|
258
|
-
continue;
|
|
259
|
-
/* colname maybe mapsTo */
|
|
260
|
-
if (hash.hasOwnProperty(colname))
|
|
261
|
-
continue;
|
|
262
|
-
this.debug(`Dropping column ${collection.name}.${colname}`);
|
|
263
|
-
this.total_changes += 1;
|
|
264
|
-
this.Dialect.dropCollectionColumnSync(this.dbdriver, collection.name, colname);
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
this.syncIndexes(collection.name, collection.index_defs);
|
|
269
|
-
}
|
|
270
|
-
syncIndexes(collection_name, index_defs) {
|
|
271
|
-
if (index_defs.length == 0)
|
|
272
|
-
return;
|
|
273
|
-
const db_indexes = this.Dialect.getCollectionIndexesSync(this.dbdriver, collection_name);
|
|
274
|
-
for (let i = 0; i < index_defs.length; i++) {
|
|
275
|
-
if (!db_indexes.hasOwnProperty(index_defs[i].name)) {
|
|
276
|
-
this.debug("Adding index " + collection_name + "." + index_defs[i].name + " (" + index_defs[i].columns.join(", ") + ")");
|
|
277
|
-
this.total_changes += 1;
|
|
278
|
-
const index = index_defs[i];
|
|
279
|
-
this.Dialect.addIndexSync(this.dbdriver, index.name, index.unique, collection_name, index.columns);
|
|
280
|
-
continue;
|
|
281
|
-
}
|
|
282
|
-
else if (!db_indexes[index_defs[i].name].unique != !index_defs[i].unique) {
|
|
283
|
-
this.debug("Replacing index " + collection_name + "." + index_defs[i].name);
|
|
284
|
-
this.total_changes += 1;
|
|
285
|
-
const index = index_defs[i];
|
|
286
|
-
this.Dialect.removeIndexSync(this.dbdriver, index.name, collection_name);
|
|
287
|
-
this.Dialect.addIndexSync(this.dbdriver, index.name, index.unique, collection_name, index.columns);
|
|
288
|
-
}
|
|
289
|
-
delete db_indexes[index_defs[i].name];
|
|
290
|
-
}
|
|
291
|
-
for (let idx in db_indexes) {
|
|
292
|
-
this.debug("Removing index " + collection_name + "." + idx);
|
|
293
|
-
this.total_changes += 1;
|
|
294
|
-
this.Dialect.removeIndexSync(this.dbdriver, collection_name, idx);
|
|
295
|
-
}
|
|
296
|
-
}
|
|
297
|
-
sync(cb) {
|
|
298
|
-
const exposedErrResults = FxORMCore.Utils.exposeErrAndResultFromSyncMethod(() => {
|
|
299
|
-
this.total_changes = 0;
|
|
300
|
-
this.collections.forEach(collection => processCollection(this, collection, { strategy: this.strategy }));
|
|
301
|
-
return {
|
|
302
|
-
changes: this.total_changes
|
|
303
|
-
};
|
|
304
|
-
});
|
|
305
|
-
FxORMCore.Utils.throwErrOrCallabckErrResult(exposedErrResults, { no_throw: !!cb, callback: cb });
|
|
306
|
-
return exposedErrResults.result;
|
|
307
|
-
}
|
|
308
|
-
;
|
|
309
|
-
forceSync(cb) {
|
|
310
|
-
const exposedErrResults = FxORMCore.Utils.exposeErrAndResultFromSyncMethod(() => {
|
|
311
|
-
this.total_changes = 0;
|
|
312
|
-
this.collections.forEach(collection => processCollection(this, collection, { strategy: 'hard' }));
|
|
313
|
-
return {
|
|
314
|
-
changes: this.total_changes
|
|
315
|
-
};
|
|
316
|
-
});
|
|
317
|
-
FxORMCore.Utils.throwErrOrCallabckErrResult(exposedErrResults, { no_throw: !!cb, callback: cb });
|
|
318
|
-
return exposedErrResults.result;
|
|
319
|
-
}
|
|
320
|
-
;
|
|
321
|
-
/**
|
|
322
|
-
* @description if sync one column
|
|
323
|
-
*
|
|
324
|
-
* @param property existed property in collection
|
|
325
|
-
* @param column column expected to be synced
|
|
326
|
-
*/
|
|
327
|
-
needDefinitionToColumn(property, column, options) {
|
|
328
|
-
if (property.serial && property.type === "number") {
|
|
329
|
-
property.type = "serial";
|
|
330
|
-
}
|
|
331
|
-
/* if type not equal, sync is required */
|
|
332
|
-
if (property.type != column.type) {
|
|
333
|
-
if (typeof this.Dialect.supportsType !== "function") {
|
|
334
|
-
return true;
|
|
335
|
-
}
|
|
336
|
-
if (this.Dialect.supportsType(property.type) !== column.type) {
|
|
337
|
-
return true;
|
|
338
|
-
}
|
|
339
|
-
}
|
|
340
|
-
/* deal with type which maybe require sync as type equals between two sides :start */
|
|
341
|
-
if (property.type === 'serial') {
|
|
342
|
-
return false; // serial columns have a fixed form, nothing more to check
|
|
343
|
-
}
|
|
344
|
-
if (property.required !== column.required && !property.key) {
|
|
345
|
-
return true;
|
|
346
|
-
}
|
|
347
|
-
const { collection: collection_name = undefined } = options || {};
|
|
348
|
-
if (property.hasOwnProperty('defaultValue')
|
|
349
|
-
&& (0, Utils_1.filterPropertyDefaultValue)(property, {
|
|
350
|
-
collection: collection_name,
|
|
351
|
-
property,
|
|
352
|
-
driver: this.dbdriver
|
|
353
|
-
}) != column.defaultValue) {
|
|
354
|
-
return true;
|
|
355
|
-
}
|
|
356
|
-
if (property.type === 'number' || property.type === 'integer') {
|
|
357
|
-
if (column.hasOwnProperty('size') && (property.size || 4) != column.size) {
|
|
358
|
-
return true;
|
|
359
|
-
}
|
|
360
|
-
}
|
|
361
|
-
if (property.type === 'enum' && column.type === 'enum') {
|
|
362
|
-
if (util.difference(property.values, column.values).length > 0
|
|
363
|
-
|| util.difference(column.values, property.values).length > 0) {
|
|
364
|
-
return true;
|
|
365
|
-
}
|
|
366
|
-
}
|
|
367
|
-
/* deal with type which maybe require sync as type equals between two sides :end */
|
|
368
|
-
return false;
|
|
369
|
-
}
|
|
370
|
-
}
|
|
371
|
-
exports.Sync = Sync;
|
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
function between(a, b, opts) {
|
|
2
|
-
return createSpecialObject({
|
|
3
|
-
from: a, to: b, asIdentifier: !!(opts === null || opts === void 0 ? void 0 : opts.asIdentifier)
|
|
4
|
-
}, 'between');
|
|
5
|
-
}
|
|
6
|
-
;
|
|
7
|
-
function not_between(a, b, opts) {
|
|
8
|
-
return createSpecialObject({
|
|
9
|
-
from: a, to: b, asIdentifier: !!(opts === null || opts === void 0 ? void 0 : opts.asIdentifier)
|
|
10
|
-
}, 'not_between');
|
|
11
|
-
}
|
|
12
|
-
;
|
|
13
|
-
function like(expr, opts) {
|
|
14
|
-
return createSpecialObject({
|
|
15
|
-
expr: expr, asIdentifier: !!(opts === null || opts === void 0 ? void 0 : opts.asIdentifier)
|
|
16
|
-
}, 'like');
|
|
17
|
-
}
|
|
18
|
-
;
|
|
19
|
-
function not_like(expr, opts) {
|
|
20
|
-
return createSpecialObject({
|
|
21
|
-
expr: expr, asIdentifier: !!(opts === null || opts === void 0 ? void 0 : opts.asIdentifier)
|
|
22
|
-
}, 'not_like');
|
|
23
|
-
}
|
|
24
|
-
;
|
|
25
|
-
function eq(v, opts) {
|
|
26
|
-
return createSpecialObject({
|
|
27
|
-
val: v, asIdentifier: !!(opts === null || opts === void 0 ? void 0 : opts.asIdentifier)
|
|
28
|
-
}, 'eq');
|
|
29
|
-
}
|
|
30
|
-
;
|
|
31
|
-
function ne(v, opts) {
|
|
32
|
-
return createSpecialObject({
|
|
33
|
-
val: v, asIdentifier: !!(opts === null || opts === void 0 ? void 0 : opts.asIdentifier)
|
|
34
|
-
}, 'ne');
|
|
35
|
-
}
|
|
36
|
-
;
|
|
37
|
-
function gt(v, opts) {
|
|
38
|
-
return createSpecialObject({
|
|
39
|
-
val: v, asIdentifier: !!(opts === null || opts === void 0 ? void 0 : opts.asIdentifier)
|
|
40
|
-
}, 'gt');
|
|
41
|
-
}
|
|
42
|
-
;
|
|
43
|
-
function gte(v, opts) {
|
|
44
|
-
return createSpecialObject({
|
|
45
|
-
val: v, asIdentifier: !!(opts === null || opts === void 0 ? void 0 : opts.asIdentifier)
|
|
46
|
-
}, 'gte');
|
|
47
|
-
}
|
|
48
|
-
;
|
|
49
|
-
function lt(v, opts) {
|
|
50
|
-
return createSpecialObject({
|
|
51
|
-
val: v, asIdentifier: !!(opts === null || opts === void 0 ? void 0 : opts.asIdentifier)
|
|
52
|
-
}, 'lt');
|
|
53
|
-
}
|
|
54
|
-
;
|
|
55
|
-
function lte(v, opts) {
|
|
56
|
-
return createSpecialObject({
|
|
57
|
-
val: v, asIdentifier: !!(opts === null || opts === void 0 ? void 0 : opts.asIdentifier)
|
|
58
|
-
}, 'lte');
|
|
59
|
-
}
|
|
60
|
-
;
|
|
61
|
-
function _in(v, opts) {
|
|
62
|
-
return createSpecialObject({
|
|
63
|
-
val: v, asIdentifier: !!(opts === null || opts === void 0 ? void 0 : opts.asIdentifier)
|
|
64
|
-
}, 'in');
|
|
65
|
-
}
|
|
66
|
-
;
|
|
67
|
-
function not_in(v, opts) {
|
|
68
|
-
return createSpecialObject({
|
|
69
|
-
val: v, asIdentifier: !!(opts === null || opts === void 0 ? void 0 : opts.asIdentifier)
|
|
70
|
-
}, 'not_in');
|
|
71
|
-
}
|
|
72
|
-
;
|
|
73
|
-
function createSpecialObject(obj, tag) {
|
|
74
|
-
Object.defineProperty(obj, "sql_comparator", {
|
|
75
|
-
configurable: false,
|
|
76
|
-
enumerable: false,
|
|
77
|
-
value: function () { return tag; }
|
|
78
|
-
});
|
|
79
|
-
return obj;
|
|
80
|
-
}
|
|
81
|
-
module.exports = {
|
|
82
|
-
between,
|
|
83
|
-
not_between,
|
|
84
|
-
like,
|
|
85
|
-
not_like,
|
|
86
|
-
eq,
|
|
87
|
-
ne,
|
|
88
|
-
gt,
|
|
89
|
-
gte,
|
|
90
|
-
lt,
|
|
91
|
-
lte,
|
|
92
|
-
in: _in,
|
|
93
|
-
not_in,
|
|
94
|
-
};
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { ChainBuilderBase } from "./Helpers";
|
|
2
|
-
import { FxSqlQueryDialect } from "./Typo/Dialect";
|
|
3
|
-
import { FxSqlQueryColumns } from "./Typo/Field";
|
|
4
|
-
import { FxSqlQueryChainBuilder } from "./Typo/Query-ChainBuilder";
|
|
5
|
-
/**
|
|
6
|
-
* Instantiate a new CREATE-type query builder
|
|
7
|
-
* @param Dialect
|
|
8
|
-
* @returns {{table: table, field: field, fields: fields, build: build}}
|
|
9
|
-
* @constructor
|
|
10
|
-
*/
|
|
11
|
-
export declare class CreateQuery extends ChainBuilderBase implements FxSqlQueryChainBuilder.ChainBuilder__Create {
|
|
12
|
-
tableName: string;
|
|
13
|
-
structure: FxSqlQueryColumns.FieldItemTypeMap;
|
|
14
|
-
constructor(Dialect: FxSqlQueryDialect.Dialect);
|
|
15
|
-
/**
|
|
16
|
-
* Set the table name
|
|
17
|
-
* @param table_name
|
|
18
|
-
*/
|
|
19
|
-
table(table_name: string): this;
|
|
20
|
-
/**
|
|
21
|
-
* Add a field
|
|
22
|
-
* @param name
|
|
23
|
-
* @param type
|
|
24
|
-
*/
|
|
25
|
-
field(name: string, type: FxSqlQueryDialect.DialectFieldType): this;
|
|
26
|
-
/**
|
|
27
|
-
* Set all the fields
|
|
28
|
-
* @param fields
|
|
29
|
-
*/
|
|
30
|
-
fields(fields?: FxSqlQueryColumns.FieldItemTypeMap): any;
|
|
31
|
-
/**
|
|
32
|
-
* Build a query from the passed params
|
|
33
|
-
*/
|
|
34
|
-
build(): string;
|
|
35
|
-
}
|
package/lib/sql-query/Create.js
DELETED
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2
|
-
exports.CreateQuery = void 0;
|
|
3
|
-
const Helpers_1 = require("./Helpers");
|
|
4
|
-
/**
|
|
5
|
-
* Instantiate a new CREATE-type query builder
|
|
6
|
-
* @param Dialect
|
|
7
|
-
* @returns {{table: table, field: field, fields: fields, build: build}}
|
|
8
|
-
* @constructor
|
|
9
|
-
*/
|
|
10
|
-
class CreateQuery extends Helpers_1.ChainBuilderBase {
|
|
11
|
-
constructor(Dialect) {
|
|
12
|
-
super(Dialect);
|
|
13
|
-
this.tableName = null;
|
|
14
|
-
this.structure = {};
|
|
15
|
-
}
|
|
16
|
-
/**
|
|
17
|
-
* Set the table name
|
|
18
|
-
* @param table_name
|
|
19
|
-
*/
|
|
20
|
-
table(table_name) {
|
|
21
|
-
this.tableName = table_name;
|
|
22
|
-
return this;
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* Add a field
|
|
26
|
-
* @param name
|
|
27
|
-
* @param type
|
|
28
|
-
*/
|
|
29
|
-
field(name, type) {
|
|
30
|
-
this.structure[name] = type;
|
|
31
|
-
return this;
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* Set all the fields
|
|
35
|
-
* @param fields
|
|
36
|
-
*/
|
|
37
|
-
fields(fields) {
|
|
38
|
-
if (!fields) {
|
|
39
|
-
return this.structure;
|
|
40
|
-
}
|
|
41
|
-
this.structure = fields;
|
|
42
|
-
return this;
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* Build a query from the passed params
|
|
46
|
-
*/
|
|
47
|
-
build() {
|
|
48
|
-
if (!this.tableName) {
|
|
49
|
-
return '';
|
|
50
|
-
}
|
|
51
|
-
const structure = this.structure;
|
|
52
|
-
const sqlBuilder = this.Dialect.knex.schema.createTable(this.tableName, function (t) {
|
|
53
|
-
Object.keys(structure).forEach(field => {
|
|
54
|
-
const desc = structure[field];
|
|
55
|
-
switch (desc) {
|
|
56
|
-
case 'id':
|
|
57
|
-
t.increments(field);
|
|
58
|
-
break;
|
|
59
|
-
case 'int':
|
|
60
|
-
t.integer(field);
|
|
61
|
-
break;
|
|
62
|
-
case 'float':
|
|
63
|
-
t.float(field, 12, 2);
|
|
64
|
-
break;
|
|
65
|
-
case 'bool':
|
|
66
|
-
t.specificType(field, 'TINYINT(1)');
|
|
67
|
-
break;
|
|
68
|
-
case 'text':
|
|
69
|
-
t.text(field);
|
|
70
|
-
break;
|
|
71
|
-
}
|
|
72
|
-
});
|
|
73
|
-
});
|
|
74
|
-
return sqlBuilder.toQuery();
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
exports.CreateQuery = CreateQuery;
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2
|
-
exports.dm = exports.mssql = exports.sqlite = exports.postgresql = exports.mysql = void 0;
|
|
3
|
-
const mysql = require("./mysql");
|
|
4
|
-
exports.mysql = mysql;
|
|
5
|
-
const postgresql = require("./postgresql");
|
|
6
|
-
exports.postgresql = postgresql;
|
|
7
|
-
const sqlite = require("./sqlite");
|
|
8
|
-
exports.sqlite = sqlite;
|
|
9
|
-
const mssql = require("./mssql");
|
|
10
|
-
exports.mssql = mssql;
|
|
11
|
-
const dm = require("./dm");
|
|
12
|
-
exports.dm = dm;
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
/// <reference types="@fibjs/types" />
|
|
2
|
-
const util = require("util");
|
|
3
|
-
const helpers = require("../Helpers");
|
|
4
|
-
const DataTypes = {
|
|
5
|
-
id: 'INT IDENTITY(1,1) NOT NULL PRIMARY KEY',
|
|
6
|
-
int: 'INT',
|
|
7
|
-
float: 'FLOAT',
|
|
8
|
-
bool: 'BIT',
|
|
9
|
-
text: 'TEXT'
|
|
10
|
-
};
|
|
11
|
-
const escape = function (query, args) {
|
|
12
|
-
return helpers.escapeQuery(Dialect, query, args);
|
|
13
|
-
};
|
|
14
|
-
function escapeId(...els) {
|
|
15
|
-
return els.map(function (el) {
|
|
16
|
-
if (typeof el == "object") {
|
|
17
|
-
return el.str.replace(/\?:(id|value)/g, function (m) {
|
|
18
|
-
if (m == "?:id") {
|
|
19
|
-
return escapeId(el.escapes.shift());
|
|
20
|
-
}
|
|
21
|
-
return escapeVal(el.escapes.shift());
|
|
22
|
-
});
|
|
23
|
-
}
|
|
24
|
-
return "[" + el + "]";
|
|
25
|
-
}).join(".");
|
|
26
|
-
}
|
|
27
|
-
;
|
|
28
|
-
const escapeVal = function (val, timeZone) {
|
|
29
|
-
if (val === undefined || val === null || typeof val === "symbol") {
|
|
30
|
-
return 'NULL';
|
|
31
|
-
}
|
|
32
|
-
if (Array.isArray(val)) {
|
|
33
|
-
if (val.length === 1 && Array.isArray(val[0])) {
|
|
34
|
-
return "(" + val[0].map(escapeVal.bind(this)) + ")";
|
|
35
|
-
}
|
|
36
|
-
return "(" + val.map(escapeVal.bind(this)).join(", ") + ")";
|
|
37
|
-
}
|
|
38
|
-
if (util.isDate(val)) {
|
|
39
|
-
return "'" + helpers.dateToString(val, timeZone || "local", { dialect: 'mssql' }) + "'";
|
|
40
|
-
}
|
|
41
|
-
if (Buffer.isBuffer(val)) {
|
|
42
|
-
return helpers.bufferToString(val, 'mssql');
|
|
43
|
-
}
|
|
44
|
-
switch (typeof val) {
|
|
45
|
-
case "number":
|
|
46
|
-
if (!isFinite(val)) {
|
|
47
|
-
val = val.toString();
|
|
48
|
-
break;
|
|
49
|
-
}
|
|
50
|
-
return val;
|
|
51
|
-
case "boolean":
|
|
52
|
-
return val ? 1 : 0;
|
|
53
|
-
case "function":
|
|
54
|
-
return val(Dialect);
|
|
55
|
-
case "string":
|
|
56
|
-
break;
|
|
57
|
-
case "bigint":
|
|
58
|
-
return val.toString();
|
|
59
|
-
default:
|
|
60
|
-
val = JSON.stringify(val);
|
|
61
|
-
}
|
|
62
|
-
return "'" + val.replace(/\'/g, "''") + "'";
|
|
63
|
-
};
|
|
64
|
-
const Dialect = {
|
|
65
|
-
type: 'mssql',
|
|
66
|
-
DataTypes,
|
|
67
|
-
escape,
|
|
68
|
-
escapeId,
|
|
69
|
-
escapeVal,
|
|
70
|
-
limitAsTop: true,
|
|
71
|
-
knex: null
|
|
72
|
-
};
|
|
73
|
-
module.exports = Dialect;
|