fib-orm 2.1.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 +37 -34
- package/{lib/cli/commands/ddlFrom.js → src/cli/commands/ddlFrom.ts} +40 -27
- package/{lib/cli/commands/dumpModel.js → src/cli/commands/dumpModel.ts} +78 -32
- package/{lib/cli/commands/escape.js → src/cli/commands/escape.ts} +51 -29
- package/{lib/cli/commands/spinner.js → src/cli/commands/spinner.ts} +20 -11
- package/{lib/cli/commands/upgrade.js → src/cli/commands/upgrade.ts} +53 -34
- 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 -86
- 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 -174
- 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 -69
- 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 -22
- 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 -2
- 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 -25
- package/lib/cli/helpers/package.js +0 -56
- package/lib/cli/index.d.ts +0 -2
- package/lib/cli/index.js +0 -19
- package/lib/db-driver/Typo.d.ts +0 -111
- package/lib/db-driver/Typo.js +0 -2
- package/lib/db-driver/built-ins/base.class.d.ts +0 -91
- package/lib/db-driver/built-ins/base.class.js +0 -187
- package/lib/db-driver/built-ins/driver-dm.d.ts +0 -17
- package/lib/db-driver/built-ins/driver-dm.js +0 -54
- package/lib/db-driver/built-ins/driver-mongodb.d.ts +0 -23
- package/lib/db-driver/built-ins/driver-mongodb.js +0 -47
- package/lib/db-driver/built-ins/driver-mysql.d.ts +0 -17
- package/lib/db-driver/built-ins/driver-mysql.js +0 -38
- package/lib/db-driver/built-ins/driver-postgresql.d.ts +0 -21
- package/lib/db-driver/built-ins/driver-postgresql.js +0 -77
- package/lib/db-driver/built-ins/driver-redis.d.ts +0 -11
- package/lib/db-driver/built-ins/driver-redis.js +0 -36
- package/lib/db-driver/built-ins/driver-sqlite.d.ts +0 -16
- package/lib/db-driver/built-ins/driver-sqlite.js +0 -35
- package/lib/db-driver/index.d.ts +0 -3
- package/lib/db-driver/index.js +0 -5
- 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 -4
- package/lib/knex/sandbox.d.ts +0 -4
- package/lib/knex/sandbox.js +0 -23
- 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 -177
- 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 -16
- 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 -14
- package/lib/orm/Associations/_utils.js +0 -53
- package/lib/orm/ChainFind.d.ts +0 -3
- package/lib/orm/ChainFind.js +0 -328
- package/lib/orm/ChainInstance.d.ts +0 -6
- package/lib/orm/ChainInstance.js +0 -74
- package/lib/orm/Debug.d.ts +0 -2
- package/lib/orm/Debug.js +0 -17
- package/lib/orm/Drivers/DB/base.d.ts +0 -2
- package/lib/orm/Drivers/DB/base.js +0 -4
- package/lib/orm/Drivers/DB/dm.d.ts +0 -9
- package/lib/orm/Drivers/DB/dm.js +0 -24
- package/lib/orm/Drivers/DB/mysql.d.ts +0 -9
- package/lib/orm/Drivers/DB/mysql.js +0 -24
- package/lib/orm/Drivers/DB/postgres.d.ts +0 -9
- package/lib/orm/Drivers/DB/postgres.js +0 -23
- package/lib/orm/Drivers/DB/sqlite3.d.ts +0 -14
- package/lib/orm/Drivers/DB/sqlite3.js +0 -40
- package/lib/orm/Drivers/DML/_ddl-sql.d.ts +0 -3
- package/lib/orm/Drivers/DML/_ddl-sql.js +0 -52
- 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 -39
- 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 -3
- 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 -7
- package/lib/orm/Drivers/DML/mysql.d.ts +0 -2
- package/lib/orm/Drivers/DML/mysql.js +0 -252
- package/lib/orm/Drivers/DML/postgres.d.ts +0 -2
- package/lib/orm/Drivers/DML/postgres.js +0 -277
- package/lib/orm/Drivers/DML/sqlite.d.ts +0 -2
- package/lib/orm/Drivers/DML/sqlite.js +0 -267
- package/lib/orm/Error.d.ts +0 -11
- package/lib/orm/Error.js +0 -41
- package/lib/orm/Helpers.d.ts +0 -35
- package/lib/orm/Helpers.js +0 -234
- package/lib/orm/Hook.d.ts +0 -13
- package/lib/orm/Hook.js +0 -100
- package/lib/orm/Instance.d.ts +0 -2
- package/lib/orm/Instance.js +0 -698
- package/lib/orm/LazyLoad.d.ts +0 -4
- package/lib/orm/LazyLoad.js +0 -76
- package/lib/orm/Model.d.ts +0 -6
- package/lib/orm/Model.js +0 -974
- package/lib/orm/ORM.d.ts +0 -37
- package/lib/orm/ORM.js +0 -242
- 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 -14
- 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 -120
- package/lib/orm/Singleton.d.ts +0 -5
- package/lib/orm/Singleton.js +0 -73
- package/lib/orm/Typo/Adapter.d.ts +0 -5
- package/lib/orm/Typo/Adapter.js +0 -2
- package/lib/orm/Typo/DMLDriver.d.ts +0 -209
- package/lib/orm/Typo/DMLDriver.js +0 -2
- package/lib/orm/Typo/Db.d.ts +0 -35
- package/lib/orm/Typo/Db.js +0 -2
- package/lib/orm/Typo/Error.d.ts +0 -29
- package/lib/orm/Typo/Error.js +0 -2
- package/lib/orm/Typo/ORM.d.ts +0 -231
- package/lib/orm/Typo/ORM.js +0 -4
- package/lib/orm/Typo/Validators.d.ts +0 -31
- package/lib/orm/Typo/Validators.js +0 -3
- package/lib/orm/Typo/_common.d.ts +0 -37
- package/lib/orm/Typo/_common.js +0 -2
- package/lib/orm/Typo/assoc.d.ts +0 -221
- package/lib/orm/Typo/assoc.js +0 -2
- package/lib/orm/Typo/hook.d.ts +0 -42
- package/lib/orm/Typo/hook.js +0 -2
- package/lib/orm/Typo/instance.d.ts +0 -156
- package/lib/orm/Typo/instance.js +0 -2
- package/lib/orm/Typo/model.js +0 -7
- package/lib/orm/Typo/patch.d.ts +0 -31
- package/lib/orm/Typo/patch.js +0 -2
- package/lib/orm/Typo/property.d.ts +0 -57
- package/lib/orm/Typo/property.js +0 -2
- package/lib/orm/Typo/query.d.ts +0 -216
- package/lib/orm/Typo/query.js +0 -2
- package/lib/orm/Typo/settings.js +0 -6
- package/lib/orm/Typo/synchronous.js +0 -2
- package/lib/orm/Utilities.d.ts +0 -178
- package/lib/orm/Utilities.js +0 -975
- package/lib/orm/Validators.d.ts +0 -33
- package/lib/orm/Validators.js +0 -101
- 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 -67
- package/lib/orm/index.js +0 -158
- package/lib/orm-core/callback.d.ts +0 -12
- package/lib/orm-core/callback.js +0 -2
- package/lib/orm-core/dialect.js +0 -2
- package/lib/orm-core/error.d.ts +0 -16
- package/lib/orm-core/error.js +0 -29
- package/lib/orm-core/index.js +0 -7
- package/lib/orm-core/sync.d.ts +0 -12
- package/lib/orm-core/sync.js +0 -2
- package/lib/orm-core/utils.d.ts +0 -1
- package/lib/orm-core/utils.js +0 -6
- package/lib/orm-property/Property.d.ts +0 -78
- package/lib/orm-property/Property.js +0 -2
- 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 -23
- 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 -6
- package/lib/orm-property/transformers/mysql.d.ts +0 -101
- package/lib/orm-property/transformers/mysql.js +0 -262
- package/lib/orm-property/transformers/postgresql.d.ts +0 -54
- package/lib/orm-property/transformers/postgresql.js +0 -190
- package/lib/orm-property/transformers/sqlite.d.ts +0 -19
- package/lib/orm-property/transformers/sqlite.js +0 -172
- package/lib/sql-ddl-sync/Dialects/dm.d.ts +0 -39
- package/lib/sql-ddl-sync/Dialects/dm.js +0 -297
- package/lib/sql-ddl-sync/Dialects/index.d.ts +0 -6
- package/lib/sql-ddl-sync/Dialects/index.js +0 -8
- package/lib/sql-ddl-sync/Dialects/mysql.d.ts +0 -38
- package/lib/sql-ddl-sync/Dialects/mysql.js +0 -241
- package/lib/sql-ddl-sync/Dialects/postgresql.d.ts +0 -39
- package/lib/sql-ddl-sync/Dialects/postgresql.js +0 -287
- package/lib/sql-ddl-sync/Dialects/sqlite.d.ts +0 -43
- package/lib/sql-ddl-sync/Dialects/sqlite.js +0 -257
- 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 -2
- package/lib/sql-ddl-sync/Typo/DbIndex.d.ts +0 -13
- package/lib/sql-ddl-sync/Typo/DbIndex.js +0 -2
- package/lib/sql-ddl-sync/Typo/Dialect.js +0 -2
- package/lib/sql-ddl-sync/Typo/Driver.d.ts +0 -53
- package/lib/sql-ddl-sync/Typo/Driver.js +0 -2
- package/lib/sql-ddl-sync/Typo/Query.d.ts +0 -7
- package/lib/sql-ddl-sync/Typo/Query.js +0 -2
- package/lib/sql-ddl-sync/Typo/SQL.d.ts +0 -31
- package/lib/sql-ddl-sync/Typo/SQL.js +0 -2
- package/lib/sql-ddl-sync/Typo/_common.d.ts +0 -29
- package/lib/sql-ddl-sync/Typo/_common.js +0 -2
- package/lib/sql-ddl-sync/Utils.d.ts +0 -39
- 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 -372
- package/lib/sql-query/Comparators.d.ts +0 -3
- package/lib/sql-query/Comparators.js +0 -95
- package/lib/sql-query/Create.d.ts +0 -35
- package/lib/sql-query/Create.js +0 -78
- package/lib/sql-query/Dialects/dm.d.ts +0 -3
- package/lib/sql-query/Dialects/index.js +0 -13
- package/lib/sql-query/Dialects/mssql.d.ts +0 -3
- package/lib/sql-query/Dialects/mssql.js +0 -74
- package/lib/sql-query/Dialects/mysql.d.ts +0 -3
- package/lib/sql-query/Dialects/mysql.js +0 -101
- package/lib/sql-query/Dialects/postgresql.d.ts +0 -3
- package/lib/sql-query/Dialects/postgresql.js +0 -77
- package/lib/sql-query/Dialects/sqlite.d.ts +0 -3
- package/lib/sql-query/Dialects/sqlite.js +0 -62
- package/lib/sql-query/Helpers.d.ts +0 -37
- package/lib/sql-query/Helpers.js +0 -260
- package/lib/sql-query/Insert.d.ts +0 -12
- package/lib/sql-query/Insert.js +0 -34
- package/lib/sql-query/Query.d.ts +0 -28
- package/lib/sql-query/Query.js +0 -120
- package/lib/sql-query/Remove.d.ts +0 -16
- package/lib/sql-query/Remove.js +0 -94
- package/lib/sql-query/Select.d.ts +0 -62
- package/lib/sql-query/Select.js +0 -534
- 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 -2
- package/lib/sql-query/Typo/Comparators.d.ts +0 -140
- package/lib/sql-query/Typo/Comparators.js +0 -2
- package/lib/sql-query/Typo/Dialect.d.ts +0 -39
- package/lib/sql-query/Typo/Dialect.js +0 -2
- package/lib/sql-query/Typo/Field.d.ts +0 -8
- package/lib/sql-query/Typo/Field.js +0 -2
- package/lib/sql-query/Typo/Helper.d.ts +0 -4
- package/lib/sql-query/Typo/Helper.js +0 -2
- package/lib/sql-query/Typo/Query-ChainBuilder.d.ts +0 -80
- package/lib/sql-query/Typo/Query-ChainBuilder.js +0 -2
- package/lib/sql-query/Typo/Query.d.ts +0 -34
- package/lib/sql-query/Typo/Query.js +0 -17
- package/lib/sql-query/Typo/Sql.d.ts +0 -143
- package/lib/sql-query/Typo/Sql.js +0 -2
- package/lib/sql-query/Typo/SubQuery.d.ts +0 -39
- package/lib/sql-query/Typo/SubQuery.js +0 -2
- package/lib/sql-query/Typo/index.js +0 -2
- package/lib/sql-query/Update.d.ts +0 -15
- package/lib/sql-query/Update.js +0 -39
- 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,52 @@
|
|
|
1
|
+
import type { FxSqlQueryComparator } from "./Comparators"
|
|
2
|
+
import type { FxSqlQuerySql } from "./Sql"
|
|
3
|
+
|
|
4
|
+
export namespace FxSqlQuerySubQuery {
|
|
5
|
+
export interface SubQueryBuildDescriptor {
|
|
6
|
+
// table name or its alias name
|
|
7
|
+
table: string
|
|
8
|
+
// where conditions
|
|
9
|
+
/**
|
|
10
|
+
* there may be 3 kinds of normalized key-value:
|
|
11
|
+
* - FxSqlQueryComparator.SubQueryInput[]
|
|
12
|
+
* - FxSqlQueryComparator.InputValueType
|
|
13
|
+
* - FxSqlQueryComparator.QueryComparatorObject
|
|
14
|
+
* - FxSqlQueryComparator.QueryComparatorLiteralObject
|
|
15
|
+
*/
|
|
16
|
+
wheres: {
|
|
17
|
+
[k: string]: ConjunctionInputValue | NonConjunctionInputValue
|
|
18
|
+
}
|
|
19
|
+
// exists query info
|
|
20
|
+
exists?: FxSqlQuerySql.QueryWhereExtendItem
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export type SubQueryConditions = SubQueryBuildDescriptor['wheres']
|
|
24
|
+
|
|
25
|
+
// {'__sql': [..., ?[...]]}
|
|
26
|
+
export type UnderscoreSqlInput = [FxSqlQuerySql.SqlAssignmentTuple]
|
|
27
|
+
export type ConjunctionInputValue = FxSqlQueryComparator.SubQueryInput[]
|
|
28
|
+
export type NonConjunctionInputValue =
|
|
29
|
+
FxSqlQueryComparator.InputValueType
|
|
30
|
+
| FxSqlQueryComparator.QueryComparatorObject
|
|
31
|
+
| FxSqlQueryComparator.QueryComparatorLiteralObject
|
|
32
|
+
| UnderscoreSqlInput
|
|
33
|
+
|
|
34
|
+
export type WhereExistsTuple_Flatten = [
|
|
35
|
+
// ['table1', {col1: 'v1'}, 'table2', {col2: Query.gte('v2')}]
|
|
36
|
+
string, FxSqlQueryComparator.SubQueryInput, string, FxSqlQueryComparator.SubQueryInput
|
|
37
|
+
]
|
|
38
|
+
|
|
39
|
+
// only for sample
|
|
40
|
+
export interface ConjunctionInput__Sample {
|
|
41
|
+
or?: FxSqlQueryComparator.SubQueryInput[]
|
|
42
|
+
and?: FxSqlQueryComparator.SubQueryInput[]
|
|
43
|
+
not_or?: FxSqlQueryComparator.SubQueryInput[]
|
|
44
|
+
not_and?: FxSqlQueryComparator.SubQueryInput[]
|
|
45
|
+
not?: FxSqlQueryComparator.SubQueryInput[]
|
|
46
|
+
}
|
|
47
|
+
export type KeyOf_ConjunctionInput = keyof ConjunctionInput__Sample
|
|
48
|
+
// only for sample
|
|
49
|
+
export interface NonConjunctionInput__Sample {
|
|
50
|
+
[k: string]: FxSqlQueryComparator.InputValueType
|
|
51
|
+
}
|
|
52
|
+
}
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
export type { FxSqlAggregation } from './Aggregation';
|
|
2
|
-
export type {
|
|
2
|
+
export type {
|
|
3
|
+
FxSqlQueryComparator,
|
|
4
|
+
FxSqlQueryComparatorFunction
|
|
5
|
+
} from './Comparators';
|
|
3
6
|
export type { FxSqlQueryDialect } from './Dialect';
|
|
4
7
|
export type { FxSqlQueryColumns } from './Field';
|
|
5
8
|
export type { FxSqlQueryHelpler } from './Helper';
|
|
6
9
|
export type { FxSqlQueryChainBuilder } from './Query-ChainBuilder';
|
|
7
10
|
export type { FxSqlQuery } from './Query';
|
|
8
11
|
export type { FxSqlQuerySql } from './Sql';
|
|
9
|
-
export type { FxSqlQuerySubQuery } from './SubQuery';
|
|
12
|
+
export type { FxSqlQuerySubQuery } from './SubQuery';
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { createRequire } from 'node:module';
|
|
2
|
+
const require = createRequire(import.meta.url);
|
|
3
|
+
import * as UpdateSet from './Set';
|
|
4
|
+
import * as Where from './Where';
|
|
5
|
+
|
|
6
|
+
import type { FxSqlQuerySql } from "./Typo/Sql";
|
|
7
|
+
import type { FxSqlQuery } from "./Typo/Query";
|
|
8
|
+
import type { FxSqlQueryDialect } from "./Typo/Dialect";
|
|
9
|
+
import type { FxSqlQuerySubQuery } from "./Typo/SubQuery";
|
|
10
|
+
import type { FxSqlQueryChainBuilder } from "./Typo/Query-ChainBuilder";
|
|
11
|
+
import { ChainBuilderBase } from "./Helpers";
|
|
12
|
+
|
|
13
|
+
export class UpdateQuery extends ChainBuilderBase implements FxSqlQueryChainBuilder.ChainBuilder__Update {
|
|
14
|
+
private opts: FxSqlQuery.QueryOptions;
|
|
15
|
+
|
|
16
|
+
private sql: FxSqlQuerySql.SqlQueryChainDescriptor = {
|
|
17
|
+
where : []
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
constructor(Dialect: FxSqlQueryDialect.Dialect, opts: FxSqlQuery.QueryOptions) {
|
|
21
|
+
super(Dialect);
|
|
22
|
+
this.opts = opts;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
into(table: string) {
|
|
26
|
+
this.sql.table = table;
|
|
27
|
+
return this;
|
|
28
|
+
}
|
|
29
|
+
set (values: FxSqlQuerySql.DataToSet) {
|
|
30
|
+
this.sql.set = values;
|
|
31
|
+
return this;
|
|
32
|
+
}
|
|
33
|
+
where (...whereConditions: FxSqlQuerySubQuery.SubQueryBuildDescriptor['wheres'][]) {
|
|
34
|
+
for (let i = 0; i < whereConditions.length; i++) {
|
|
35
|
+
this.sql.where!.push({
|
|
36
|
+
table: null as any,
|
|
37
|
+
wheres: whereConditions[i]
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
return this;
|
|
41
|
+
}
|
|
42
|
+
build () {
|
|
43
|
+
const sqlBuilder = this.Dialect.knex(this.sql.table)
|
|
44
|
+
|
|
45
|
+
UpdateSet.build(sqlBuilder, this.Dialect, this.sql.set!, this.opts)
|
|
46
|
+
Where.build(sqlBuilder, this.Dialect, this.sql.where!, this.opts)
|
|
47
|
+
|
|
48
|
+
return sqlBuilder.toQuery();
|
|
49
|
+
}
|
|
50
|
+
}
|
|
@@ -0,0 +1,435 @@
|
|
|
1
|
+
import { createRequire } from 'node:module';
|
|
2
|
+
const require = createRequire(import.meta.url);
|
|
3
|
+
import * as Helpers from './Helpers';
|
|
4
|
+
import ComparatorsHash from './Comparators';
|
|
5
|
+
|
|
6
|
+
import type { FxSqlQuerySubQuery } from './Typo/SubQuery';
|
|
7
|
+
import type { FxSqlQuerySql } from './Typo/Sql';
|
|
8
|
+
import type { FxSqlQueryDialect } from './Typo/Dialect';
|
|
9
|
+
import type { FxSqlQueryChainBuilder } from './Typo/Query-ChainBuilder';
|
|
10
|
+
import type { FxSqlQueryComparator } from './Typo/Comparators';
|
|
11
|
+
|
|
12
|
+
export function build (
|
|
13
|
+
knexQueryBuilder: import('../knex/types').Knex.QueryBuilder,
|
|
14
|
+
Dialect: FxSqlQueryDialect.Dialect,
|
|
15
|
+
whereList: FxSqlQuerySubQuery.SubQueryBuildDescriptor[],
|
|
16
|
+
opts: FxSqlQueryChainBuilder.ChainBuilderOptions
|
|
17
|
+
): void {
|
|
18
|
+
if (whereList.length === 0) {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
for (let i = 0; i < whereList.length; i++) {
|
|
23
|
+
buildOrGroup(knexQueryBuilder, Dialect, whereList[i], opts);
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
const WHERE_CONJUNCTIONS = [ "or", "and", "not_or", "not_and", "not" ];
|
|
28
|
+
const NOT_PREFIX_LEN = 'not_'.length;
|
|
29
|
+
|
|
30
|
+
function isKeyConjunctionNot (k: string) {
|
|
31
|
+
return k.indexOf("_") >= 0
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
type SelectedWhereOperator =
|
|
35
|
+
'where'
|
|
36
|
+
| 'andWhere'
|
|
37
|
+
| 'orWhere'
|
|
38
|
+
| 'whereNot'
|
|
39
|
+
| 'andWhereNot'
|
|
40
|
+
| 'orWhereNot'
|
|
41
|
+
| 'whereRaw'
|
|
42
|
+
| 'orWhereRaw'
|
|
43
|
+
| 'andWhereRaw'
|
|
44
|
+
| 'whereWrapped'
|
|
45
|
+
| 'havingWrapped'
|
|
46
|
+
| 'whereExists'
|
|
47
|
+
| 'orWhereExists'
|
|
48
|
+
| 'whereNotExists'
|
|
49
|
+
| 'orWhereNotExists'
|
|
50
|
+
| 'whereIn'
|
|
51
|
+
| 'orWhereIn'
|
|
52
|
+
| 'whereNotIn'
|
|
53
|
+
| 'orWhereNotIn'
|
|
54
|
+
| 'whereNull'
|
|
55
|
+
| 'orWhereNull'
|
|
56
|
+
| 'whereNotNull'
|
|
57
|
+
| 'orWhereNotNull'
|
|
58
|
+
| 'whereBetween'
|
|
59
|
+
| 'orWhereBetween'
|
|
60
|
+
| 'andWhereBetween'
|
|
61
|
+
| 'whereNotBetween'
|
|
62
|
+
| 'orWhereNotBetween'
|
|
63
|
+
| 'andWhereNotBetween'
|
|
64
|
+
|
|
65
|
+
function buildOrGroup(
|
|
66
|
+
knexQueryBuilder: import('../knex/types').Knex.QueryBuilder,
|
|
67
|
+
Dialect: FxSqlQueryDialect.Dialect,
|
|
68
|
+
where: FxSqlQuerySubQuery.SubQueryBuildDescriptor,
|
|
69
|
+
opts: FxSqlQueryChainBuilder.ChainBuilderOptions,
|
|
70
|
+
nextPrefixedOpWord?: FxSqlQueryComparator.QueryConjunctionWord,
|
|
71
|
+
innerInfo?: {
|
|
72
|
+
innerOperator?: SelectedWhereOperator,
|
|
73
|
+
innerSuffix?: SelectedWhereSuffix,
|
|
74
|
+
innerPrefix?: SelectedWherePrefix,
|
|
75
|
+
}
|
|
76
|
+
): FxSqlQuerySql.SqlFragmentStr[] | FxSqlQuerySql.SqlResultStr | false {
|
|
77
|
+
opts = opts || {};
|
|
78
|
+
|
|
79
|
+
if (where.exists) {
|
|
80
|
+
buildExistsSqlFragments(knexQueryBuilder, Dialect, where, opts);
|
|
81
|
+
return false;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
let query: string[] = [],
|
|
85
|
+
op: FxSqlQueryComparator.QueryComparatorType = 'eq',
|
|
86
|
+
transformed_result_op = '';
|
|
87
|
+
|
|
88
|
+
for (let k in where.wheres) {
|
|
89
|
+
let where_conditem_value = where.wheres[k];
|
|
90
|
+
if (where_conditem_value === null || where_conditem_value === undefined) {
|
|
91
|
+
// ? in subquery
|
|
92
|
+
knexQueryBuilder.whereNull(k);
|
|
93
|
+
continue;
|
|
94
|
+
}
|
|
95
|
+
// `not` is an alias for `not_and`
|
|
96
|
+
if (isConjunctionWhereConditionInput(k, where_conditem_value)) {
|
|
97
|
+
let conjunctionWord = (k.toLocaleLowerCase() as FxSqlQueryComparator.QueryConjunctionWord);
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* @values FxSqlQueryComparator.QueryConjunctionWord
|
|
101
|
+
*/
|
|
102
|
+
transformed_result_op = (k == "not" ? "and" : (isKeyConjunctionNot(k) ? k.substr(NOT_PREFIX_LEN) : k)).toUpperCase();
|
|
103
|
+
|
|
104
|
+
const conjunction_where_list = where_conditem_value;
|
|
105
|
+
|
|
106
|
+
let {
|
|
107
|
+
nextOperator: parentConjuncWhereClosureOperator,
|
|
108
|
+
} = selectWhereOperatorByCtx(nextPrefixedOpWord);
|
|
109
|
+
|
|
110
|
+
let {
|
|
111
|
+
nextOperator: wrapperConjuncWhereClosureOperator,
|
|
112
|
+
conjunction: innerConjunction,
|
|
113
|
+
suffix: innerSuffix,
|
|
114
|
+
} = selectWhereOperatorByCtx(conjunctionWord);
|
|
115
|
+
|
|
116
|
+
if (wrapperConjuncWhereClosureOperator === 'whereNot')
|
|
117
|
+
wrapperConjuncWhereClosureOperator = selectWhereOperatorByCtx('not', innerSuffix, innerConjunction).nextOperator
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
const p_call = function (cb: (...args: any[]) => any) {
|
|
121
|
+
;(knexQueryBuilder as any)[ parentConjuncWhereClosureOperator ].call(
|
|
122
|
+
knexQueryBuilder,
|
|
123
|
+
cb
|
|
124
|
+
)
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
const loop_inner_call = function (this: any) {
|
|
128
|
+
const innerOperator = selectWhereOperatorByCtx(undefined as any, innerSuffix, innerConjunction).nextOperator
|
|
129
|
+
|
|
130
|
+
for (let j = 0; j < conjunction_where_list.length; j++) {
|
|
131
|
+
const conj_c = conjunction_where_list[j];
|
|
132
|
+
|
|
133
|
+
;(this[ wrapperConjuncWhereClosureOperator ] as (...args: any[]) => any).call(
|
|
134
|
+
this,
|
|
135
|
+
function (this: any) {
|
|
136
|
+
buildOrGroup(
|
|
137
|
+
this,
|
|
138
|
+
Dialect,
|
|
139
|
+
{ table: where.table, wheres: conj_c },
|
|
140
|
+
opts,
|
|
141
|
+
undefined,
|
|
142
|
+
{
|
|
143
|
+
innerOperator: j === 0 ? undefined : innerOperator
|
|
144
|
+
}
|
|
145
|
+
);
|
|
146
|
+
}
|
|
147
|
+
)
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
p_call(loop_inner_call);
|
|
152
|
+
|
|
153
|
+
continue;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
let {
|
|
157
|
+
innerOperator = 'where' as SelectedWhereOperator,
|
|
158
|
+
} = innerInfo || {};
|
|
159
|
+
|
|
160
|
+
const normalizedKey = getComparisonKey(Dialect, where.table, k);
|
|
161
|
+
|
|
162
|
+
let non_conj_where_conditem_value: FxSqlQuerySubQuery.NonConjunctionInputValue
|
|
163
|
+
= transformSqlComparatorLiteralObject(where_conditem_value) || where_conditem_value;
|
|
164
|
+
|
|
165
|
+
if (isSqlComparatorPayload(non_conj_where_conditem_value)) {
|
|
166
|
+
op = non_conj_where_conditem_value.sql_comparator();
|
|
167
|
+
|
|
168
|
+
switch (op) {
|
|
169
|
+
case "between":
|
|
170
|
+
innerOperator = selectWhereOperatorByCtx(nextPrefixedOpWord, 'between').nextOperator
|
|
171
|
+
;(knexQueryBuilder[innerOperator] as (...args: any[]) => any).call(knexQueryBuilder, normalizedKey, [non_conj_where_conditem_value.from, non_conj_where_conditem_value.to])
|
|
172
|
+
break;
|
|
173
|
+
case "not_between":
|
|
174
|
+
|
|
175
|
+
innerOperator = selectWhereOperatorByCtx(nextPrefixedOpWord, 'notBetween').nextOperator
|
|
176
|
+
;(knexQueryBuilder[innerOperator] as (...args: any[]) => any).call(knexQueryBuilder, normalizedKey, [non_conj_where_conditem_value.from, non_conj_where_conditem_value.to])
|
|
177
|
+
break;
|
|
178
|
+
case "like":
|
|
179
|
+
innerOperator = innerOperator || selectWhereOperatorByCtx(nextPrefixedOpWord).nextOperator
|
|
180
|
+
;(knexQueryBuilder[innerOperator] as (...args: any[]) => any).call(knexQueryBuilder, normalizedKey, 'like', Helpers.escapeValForKnex(non_conj_where_conditem_value.expr, Dialect, opts || {}))
|
|
181
|
+
break;
|
|
182
|
+
case "not_like":
|
|
183
|
+
innerOperator = innerOperator || selectWhereOperatorByCtx(nextPrefixedOpWord).nextOperator
|
|
184
|
+
;(knexQueryBuilder[innerOperator] as (...args: any[]) => any).call(knexQueryBuilder, normalizedKey, 'not like', Helpers.escapeValForKnex(non_conj_where_conditem_value.expr, Dialect, opts || {}))
|
|
185
|
+
break;
|
|
186
|
+
case "eq":
|
|
187
|
+
case "ne":
|
|
188
|
+
case "gt":
|
|
189
|
+
case "gte":
|
|
190
|
+
case "lt":
|
|
191
|
+
case "lte":
|
|
192
|
+
case "in":
|
|
193
|
+
case "not_in":
|
|
194
|
+
switch (op) {
|
|
195
|
+
case "eq" : transformed_result_op = (non_conj_where_conditem_value.val === null ? "IS" : "="); break;
|
|
196
|
+
case "ne" : transformed_result_op = (non_conj_where_conditem_value.val === null ? "IS NOT" : "<>"); break;
|
|
197
|
+
case "gt" : transformed_result_op = ">"; break;
|
|
198
|
+
case "gte" : transformed_result_op = ">="; break;
|
|
199
|
+
case "lt" : transformed_result_op = "<"; break;
|
|
200
|
+
case "lte" : transformed_result_op = "<="; break;
|
|
201
|
+
case "in" : transformed_result_op = "IN"; break;
|
|
202
|
+
case "not_in" : transformed_result_op = "NOT IN"; break;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
let val = non_conj_where_conditem_value.val
|
|
206
|
+
innerOperator = innerOperator || selectWhereOperatorByCtx(nextPrefixedOpWord).nextOperator
|
|
207
|
+
if (
|
|
208
|
+
!isInStyleOperator(op, non_conj_where_conditem_value)
|
|
209
|
+
&& val !== null
|
|
210
|
+
&& non_conj_where_conditem_value.asIdentifier) {
|
|
211
|
+
val = Dialect.knex.ref(val);
|
|
212
|
+
}
|
|
213
|
+
;(knexQueryBuilder[innerOperator] as (...args: any[]) => any).call(knexQueryBuilder, normalizedKey, transformed_result_op, Helpers.escapeValForKnex(val, Dialect, opts || {}))
|
|
214
|
+
|
|
215
|
+
break;
|
|
216
|
+
}
|
|
217
|
+
continue;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
if (isUnderscoreSqlInput(k, non_conj_where_conditem_value)) {
|
|
221
|
+
if (
|
|
222
|
+
!Array.isArray(non_conj_where_conditem_value)
|
|
223
|
+
|| (non_conj_where_conditem_value[0] && non_conj_where_conditem_value[0].length < 1)
|
|
224
|
+
) {
|
|
225
|
+
throw new Error(`invalid value for ${k}, expected its 2 dimension array like __sql: [ ['expr with ? or ??', ['value', 'id']], ['SQL'], ... ]`)
|
|
226
|
+
}
|
|
227
|
+
for (let i = 0; i < non_conj_where_conditem_value.length; i++) {
|
|
228
|
+
knexQueryBuilder.whereRaw(
|
|
229
|
+
normalizeSqlConditions(Dialect, non_conj_where_conditem_value[i])
|
|
230
|
+
)
|
|
231
|
+
}
|
|
232
|
+
} else {
|
|
233
|
+
/**
|
|
234
|
+
* array as 'IN'
|
|
235
|
+
*/
|
|
236
|
+
if (Array.isArray(non_conj_where_conditem_value)) {
|
|
237
|
+
innerOperator = selectWhereOperatorByCtx(nextPrefixedOpWord, 'in').nextOperator
|
|
238
|
+
;(knexQueryBuilder[innerOperator] as (...args: any[]) => any).call(knexQueryBuilder, normalizedKey, Helpers.escapeValForKnex(non_conj_where_conditem_value, Dialect, opts || {}))
|
|
239
|
+
} else { // finally, simplest where-equal
|
|
240
|
+
const simple_value = non_conj_where_conditem_value as any
|
|
241
|
+
|
|
242
|
+
innerOperator = innerOperator || selectWhereOperatorByCtx(nextPrefixedOpWord).nextOperator
|
|
243
|
+
|
|
244
|
+
;(knexQueryBuilder[innerOperator] as (...args: any[]) => any).call(knexQueryBuilder, normalizedKey, Helpers.escapeValForKnex(simple_value, Dialect, opts))
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
if (query.length === 0) {
|
|
250
|
+
return false;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
return query.join(" AND ");
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
type SelectedWhereSuffix = 'null' | 'between' | 'notBetween' | 'in' | 'notIn'
|
|
257
|
+
type SelectedWherePrefix = 'or' | 'and'
|
|
258
|
+
|
|
259
|
+
function selectWhereOperatorByCtx (
|
|
260
|
+
conjunctionWord?: FxSqlQueryComparator.QueryConjunctionWord,
|
|
261
|
+
suffix?: SelectedWhereSuffix,
|
|
262
|
+
prefix?: SelectedWherePrefix
|
|
263
|
+
): {
|
|
264
|
+
nextOperator: SelectedWhereOperator,
|
|
265
|
+
conjunction: FxSqlQueryComparator.SimpleQueryConjunctionWord_NonNegetive,
|
|
266
|
+
suffix?: SelectedWhereSuffix,
|
|
267
|
+
prefix?: SelectedWherePrefix
|
|
268
|
+
} {
|
|
269
|
+
const result: any = {
|
|
270
|
+
nextOperator: 'where' as SelectedWhereOperator,
|
|
271
|
+
conjunction: 'and' as FxSqlQueryComparator.SimpleQueryConjunctionWord_NonNegetive,
|
|
272
|
+
suffix: undefined,
|
|
273
|
+
prefix: undefined,
|
|
274
|
+
};
|
|
275
|
+
|
|
276
|
+
switch (conjunctionWord) {
|
|
277
|
+
case 'not_and':
|
|
278
|
+
case 'not':
|
|
279
|
+
result.nextOperator = 'whereNot'
|
|
280
|
+
result.conjunction = 'and'
|
|
281
|
+
break
|
|
282
|
+
case 'and':
|
|
283
|
+
result.nextOperator = 'where'
|
|
284
|
+
break
|
|
285
|
+
case 'or':
|
|
286
|
+
result.nextOperator = 'orWhere'
|
|
287
|
+
result.conjunction = 'or'
|
|
288
|
+
break
|
|
289
|
+
case 'not_or':
|
|
290
|
+
result.nextOperator = 'whereNot'
|
|
291
|
+
result.conjunction = 'or'
|
|
292
|
+
break
|
|
293
|
+
default:
|
|
294
|
+
result.nextOperator = 'where'
|
|
295
|
+
break
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
if (result.suffix = suffix)
|
|
299
|
+
result.nextOperator = `${result.nextOperator}${Helpers.ucfirst(suffix)}` as SelectedWhereOperator
|
|
300
|
+
|
|
301
|
+
if (result.prefix = prefix)
|
|
302
|
+
result.nextOperator = `${prefix}${Helpers.ucfirst(result.nextOperator)}` as SelectedWhereOperator
|
|
303
|
+
|
|
304
|
+
return result
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
function buildExistsSqlFragments (
|
|
308
|
+
knexQueryBuilder: import('../knex/types').Knex.QueryBuilder,
|
|
309
|
+
Dialect: FxSqlQueryDialect.Dialect,
|
|
310
|
+
where: FxSqlQuerySubQuery.SubQueryBuildDescriptor,
|
|
311
|
+
opts: FxSqlQueryChainBuilder.ChainBuilderOptions
|
|
312
|
+
) {
|
|
313
|
+
/* start of deal with case `whereExists` */
|
|
314
|
+
const exists = where.exists;
|
|
315
|
+
if (!exists) return;
|
|
316
|
+
|
|
317
|
+
const link_table = exists.table_linked;
|
|
318
|
+
|
|
319
|
+
knexQueryBuilder.whereExists(function () {
|
|
320
|
+
this.select('*')
|
|
321
|
+
.from(exists.table)
|
|
322
|
+
|
|
323
|
+
/**
|
|
324
|
+
* @example whereExists('table2', 'table1', [['fid1', 'fid2'], ['id1', 'id2']], { col1: 1, col2: 2 })
|
|
325
|
+
*/
|
|
326
|
+
if (Array.isArray(exists.link_info[0]) && Array.isArray(exists.link_info[1])) {
|
|
327
|
+
const col_tuple_for_aligning_from = exists.link_info[0];
|
|
328
|
+
const col_tuple_for_aligning_to = exists.link_info[1];
|
|
329
|
+
|
|
330
|
+
for (let i = 0; i < col_tuple_for_aligning_from.length; i++) {
|
|
331
|
+
this.where(
|
|
332
|
+
// `${col_tuple_for_aligning_from}.${col_tuple_for_aligning_from[i]}`,
|
|
333
|
+
`${col_tuple_for_aligning_from[i]}`,
|
|
334
|
+
Dialect.knex.ref(col_tuple_for_aligning_to[i]).withSchema(link_table)
|
|
335
|
+
)
|
|
336
|
+
}
|
|
337
|
+
} else {
|
|
338
|
+
const [table_from, table_to] = exists.link_info
|
|
339
|
+
/**
|
|
340
|
+
* @example whereExists('table2', 'table1', ['fid', 'id'], { col1: 1, col2: 2 })
|
|
341
|
+
*/
|
|
342
|
+
if (table_from && table_to) {
|
|
343
|
+
this.where(
|
|
344
|
+
// `${exists.table}.${table_from}`,
|
|
345
|
+
`${table_from}`,
|
|
346
|
+
Dialect.knex.ref(table_to).withSchema(link_table)
|
|
347
|
+
)
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
buildOrGroup(this, Dialect, { table: null as any, wheres: where.wheres }, opts)
|
|
352
|
+
});
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
function getComparisonKey(Dialect: FxSqlQueryDialect.Dialect, table: string, column: string) {
|
|
356
|
+
if (!table)
|
|
357
|
+
return column;
|
|
358
|
+
|
|
359
|
+
return Dialect.knex.ref(column).withSchema(table);
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
function normalizeSqlConditions(Dialect: FxSqlQueryDialect.Dialect, queryArray: FxSqlQuerySql.SqlAssignmentTuple) {
|
|
363
|
+
if (queryArray.length == 1) {
|
|
364
|
+
return queryArray[0];
|
|
365
|
+
}
|
|
366
|
+
return Helpers.escapeQuery(Dialect, queryArray[0], queryArray[1]!);
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
function isSqlComparatorPayload (
|
|
370
|
+
non_special_kv: FxSqlQuerySubQuery.NonConjunctionInputValue
|
|
371
|
+
): non_special_kv is FxSqlQuerySql.DetailedQueryWhereCondition {
|
|
372
|
+
if (typeof non_special_kv !== 'object') return false;
|
|
373
|
+
if (! ('sql_comparator' in non_special_kv)) return false;
|
|
374
|
+
|
|
375
|
+
return typeof non_special_kv.sql_comparator === "function"
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
function transformSqlComparatorLiteralObject (
|
|
379
|
+
non_special_kv: FxSqlQuerySubQuery.NonConjunctionInputValue,
|
|
380
|
+
): false | FxSqlQueryComparator.QueryComparatorObject {
|
|
381
|
+
if (typeof non_special_kv !== 'object') return false;
|
|
382
|
+
|
|
383
|
+
const keys = Object.keys(non_special_kv) as [FxSqlQueryComparator.ComparatorNameType]
|
|
384
|
+
const op: FxSqlQueryComparator.ComparatorNameType = keys.find(k => k in ComparatorsHash)!;
|
|
385
|
+
|
|
386
|
+
if (!op)
|
|
387
|
+
return false;
|
|
388
|
+
|
|
389
|
+
const literal_kv = non_special_kv as FxSqlQueryComparator.QueryComparatorLiteralObject;
|
|
390
|
+
const modifiers = literal_kv.modifiers = literal_kv.modifiers || {};
|
|
391
|
+
|
|
392
|
+
const fn = ComparatorsHash[op] as FxSqlQueryComparator.ComparatorHash[FxSqlQueryComparator.ComparatorNameType]
|
|
393
|
+
|
|
394
|
+
let input = literal_kv[op];
|
|
395
|
+
// non in-style tuple op contains: `between`, `not_between`
|
|
396
|
+
const is_in_style = ['not_in', 'in'].includes(op);
|
|
397
|
+
const in_input_arr = Array.isArray(input);
|
|
398
|
+
if (modifiers.is_date) {
|
|
399
|
+
let to_filter = in_input_arr ? input : [input]
|
|
400
|
+
const args_0 = (to_filter)
|
|
401
|
+
.map((x: any) => new Date(x))
|
|
402
|
+
.filter((x: Date) => x + '' !== 'Invalid Date')
|
|
403
|
+
|
|
404
|
+
if (args_0.length === to_filter.length) {
|
|
405
|
+
to_filter = args_0
|
|
406
|
+
input = in_input_arr ? to_filter : to_filter[0]
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
const apply_args = in_input_arr && !is_in_style ? input : [input];
|
|
411
|
+
const result = (fn as any).apply(null, apply_args);
|
|
412
|
+
|
|
413
|
+
return result;
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
function isConjunctionWhereConditionInput (
|
|
417
|
+
k: string,
|
|
418
|
+
where_conditem_value: FxSqlQuerySubQuery.SubQueryBuildDescriptor['wheres'][string]
|
|
419
|
+
): where_conditem_value is FxSqlQuerySubQuery.ConjunctionInputValue {
|
|
420
|
+
return WHERE_CONJUNCTIONS.indexOf(k) >= 0;
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
function isUnderscoreSqlInput (
|
|
424
|
+
k: string,
|
|
425
|
+
where_conditem_value: FxSqlQuerySubQuery.SubQueryBuildDescriptor['wheres'][string]
|
|
426
|
+
): where_conditem_value is FxSqlQuerySubQuery.UnderscoreSqlInput {
|
|
427
|
+
return k === '__sql';
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
function isInStyleOperator (
|
|
431
|
+
op: string,
|
|
432
|
+
where_conditem_value: FxSqlQuerySql.DetailedQueryWhereCondition<any>
|
|
433
|
+
): where_conditem_value is FxSqlQuerySql.DetailedQueryWhereCondition__InStyle {
|
|
434
|
+
return !!~['in', 'not_in'].indexOf(op);
|
|
435
|
+
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
declare const fibCache: any;
|
|
2
1
|
declare module "fib-cache" {
|
|
3
2
|
interface LRUOptions {
|
|
4
3
|
max?: number;
|
|
5
4
|
ttl?: number;
|
|
6
5
|
resolver?: (key: string) => any;
|
|
7
6
|
}
|
|
7
|
+
|
|
8
8
|
interface LRUItem {
|
|
9
9
|
expiry: number;
|
|
10
10
|
key: string;
|
|
@@ -14,7 +14,8 @@ declare module "fib-cache" {
|
|
|
14
14
|
value: any;
|
|
15
15
|
ready: Class_Event;
|
|
16
16
|
}
|
|
17
|
-
|
|
17
|
+
|
|
18
|
+
export class LRU {
|
|
18
19
|
constructor(options?: LRUOptions);
|
|
19
20
|
items: Record<string, LRUItem>;
|
|
20
21
|
size: number;
|
|
@@ -23,6 +24,7 @@ declare module "fib-cache" {
|
|
|
23
24
|
max: number;
|
|
24
25
|
ttl: number;
|
|
25
26
|
resolver: (key: string) => any;
|
|
27
|
+
|
|
26
28
|
clear(): LRU;
|
|
27
29
|
delete_item(item: LRUItem): LRU;
|
|
28
30
|
delete(key: string): LRU;
|
package/lib/cli/helpers/ddl.d.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { IDbDriver } from "../../db-driver/index";
|
|
2
|
-
import { Sync } from '../../sql-ddl-sync/index';
|
|
3
|
-
export declare function getAllTableNames(driver: IDbDriver.ISQLDriver): string[];
|
|
4
|
-
export type IModelProperties = ReturnType<Sync['Dialect']['getCollectionPropertiesSync']>;
|
|
5
|
-
export type IRawColumns = ReturnType<Sync['Dialect']['getCollectionColumnsSync']>;
|
|
6
|
-
export declare function getTableDDLs(sync: Sync, { tableNames, afterGetTableDDL }?: {
|
|
7
|
-
tableNames?: string[];
|
|
8
|
-
afterGetTableDDL?: (ddl: {
|
|
9
|
-
collection: string;
|
|
10
|
-
properties: IModelProperties;
|
|
11
|
-
rawColumns: IRawColumns;
|
|
12
|
-
}) => void;
|
|
13
|
-
}): {
|
|
14
|
-
collection: string;
|
|
15
|
-
rawColumns: IRawColumns;
|
|
16
|
-
properties: IModelProperties;
|
|
17
|
-
}[];
|
package/lib/cli/helpers/ddl.js
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getAllTableNames = getAllTableNames;
|
|
4
|
-
exports.getTableDDLs = getTableDDLs;
|
|
5
|
-
const coroutine = require("coroutine");
|
|
6
|
-
function getAllTableNames(driver) {
|
|
7
|
-
let tableNames = [];
|
|
8
|
-
switch (driver.type) {
|
|
9
|
-
case 'psql': {
|
|
10
|
-
const result = driver.execute('SELECT * FROM information_schema.tables');
|
|
11
|
-
result.forEach((x) => {
|
|
12
|
-
// skip system tables
|
|
13
|
-
if (x.table_name.startsWith('pg_'))
|
|
14
|
-
return;
|
|
15
|
-
// skip non public tables
|
|
16
|
-
if (x.table_schema !== 'public')
|
|
17
|
-
return;
|
|
18
|
-
tableNames.push(x.table_name);
|
|
19
|
-
});
|
|
20
|
-
break;
|
|
21
|
-
}
|
|
22
|
-
case 'mysql': {
|
|
23
|
-
const result = driver.execute('show tables;');
|
|
24
|
-
tableNames = result.reduce((accu, x) => (accu.push(Object.entries(x)[0][1]),
|
|
25
|
-
accu), []);
|
|
26
|
-
break;
|
|
27
|
-
}
|
|
28
|
-
case 'sqlite': {
|
|
29
|
-
const result = driver.execute(`SELECT name FROM sqlite_schema WHERE type='table' ORDER BY name`);
|
|
30
|
-
result.forEach((x) => {
|
|
31
|
-
// skip system tables
|
|
32
|
-
if (x.name.startsWith('sqlite_'))
|
|
33
|
-
return;
|
|
34
|
-
tableNames.push(x.name);
|
|
35
|
-
});
|
|
36
|
-
break;
|
|
37
|
-
}
|
|
38
|
-
default:
|
|
39
|
-
throw new Error(`[getAllTableNames] unsupported driver type: ${driver.type}`);
|
|
40
|
-
}
|
|
41
|
-
return tableNames;
|
|
42
|
-
}
|
|
43
|
-
function getTableDDLs(sync, { tableNames, afterGetTableDDL } = {}) {
|
|
44
|
-
tableNames = (tableNames === null || tableNames === void 0 ? void 0 : tableNames.length) ? tableNames : getAllTableNames(sync.dbdriver);
|
|
45
|
-
const tableDDLs = coroutine.parallel(tableNames, (tableName) => {
|
|
46
|
-
const ddl = {
|
|
47
|
-
collection: tableName,
|
|
48
|
-
properties: sync.Dialect.getCollectionPropertiesSync(sync.dbdriver, tableName),
|
|
49
|
-
rawColumns: sync.Dialect.getCollectionColumnsSync(sync.dbdriver, tableName),
|
|
50
|
-
};
|
|
51
|
-
afterGetTableDDL === null || afterGetTableDDL === void 0 ? void 0 : afterGetTableDDL(ddl);
|
|
52
|
-
return ddl;
|
|
53
|
-
});
|
|
54
|
-
return tableDDLs;
|
|
55
|
-
}
|