fib-orm 2.0.0 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +42 -6
- package/index.d.ts +11 -0
- package/index.js +15 -0
- package/package.json +36 -34
- package/{lib/cli/commands/ddlFrom.js → src/cli/commands/ddlFrom.ts} +40 -26
- package/{lib/cli/commands/dumpModel.js → src/cli/commands/dumpModel.ts} +78 -31
- package/{lib/cli/commands/escape.js → src/cli/commands/escape.ts} +51 -28
- package/{lib/cli/commands/spinner.js → src/cli/commands/spinner.ts} +20 -10
- package/{lib/cli/commands/upgrade.js → src/cli/commands/upgrade.ts} +53 -33
- package/src/cli/helpers/ddl.ts +84 -0
- package/src/cli/helpers/package.ts +81 -0
- package/src/cli/index.ts +24 -0
- package/src/cli/wrapSubcommand.ts +66 -0
- package/src/db-driver/Typo.d.ts +141 -0
- package/src/db-driver/built-ins/base.class.ts +260 -0
- package/src/db-driver/built-ins/driver-dm.ts +62 -0
- package/src/db-driver/built-ins/driver-mssql.ts +67 -0
- package/src/db-driver/built-ins/driver-mysql.ts +44 -0
- package/src/db-driver/built-ins/driver-postgresql.ts +94 -0
- package/src/db-driver/built-ins/driver-redis.ts +45 -0
- package/src/db-driver/built-ins/driver-sqlite.ts +41 -0
- package/src/db-driver/index.ts +6 -0
- package/src/db-driver/parseQueryString.ts +76 -0
- package/src/db-driver/utils.ts +204 -0
- package/src/knex/deps/tarn/PendingOperation.ts +56 -0
- package/src/knex/deps/tarn/Pool.ts +610 -0
- package/src/knex/deps/tarn/PromiseInspection.ts +29 -0
- package/src/knex/deps/tarn/Resource.ts +22 -0
- package/src/knex/deps/tarn/TimeoutError.ts +1 -0
- package/src/knex/deps/tarn/tarn.ts +7 -0
- package/src/knex/deps/tarn/utils.ts +62 -0
- package/src/knex/knex.ts +11 -0
- package/src/knex/result.d.ts +27 -0
- package/src/knex/sandbox.ts +45 -0
- package/src/knex/tables.d.ts +4 -0
- package/src/knex/types.d.ts +3228 -0
- package/src/orm/Adapters.ts +53 -0
- package/src/orm/AggregateFunctions.ts +254 -0
- package/src/orm/Associations/Extend.ts +405 -0
- package/src/orm/Associations/Many.ts +784 -0
- package/src/orm/Associations/One.ts +494 -0
- package/src/orm/Associations/_utils.ts +72 -0
- package/src/orm/ChainFind.ts +427 -0
- package/src/orm/ChainInstance.ts +97 -0
- package/src/orm/Debug.ts +21 -0
- package/src/orm/Drivers/DB/base.ts +7 -0
- package/src/orm/Drivers/DB/dm.ts +35 -0
- package/src/orm/Drivers/DB/mssql.ts +35 -0
- package/src/orm/Drivers/DB/mysql.ts +35 -0
- package/src/orm/Drivers/DB/postgres.ts +35 -0
- package/src/orm/Drivers/DB/sqlite3.ts +60 -0
- package/src/orm/Drivers/DML/_ddl-sql.ts +85 -0
- package/src/orm/Drivers/DML/_dml-helpers.ts +66 -0
- package/src/orm/Drivers/DML/_shared.ts +61 -0
- package/src/orm/Drivers/DML/_utils.ts +112 -0
- package/{lib/orm/Drivers/DML/dm.js → src/orm/Drivers/DML/dm.ts} +178 -85
- package/src/orm/Drivers/DML/index.ts +10 -0
- package/src/orm/Drivers/DML/mssql.ts +366 -0
- package/src/orm/Drivers/DML/mysql.ts +347 -0
- package/src/orm/Drivers/DML/postgres.ts +382 -0
- package/src/orm/Drivers/DML/sqlite.ts +361 -0
- package/src/orm/Error.ts +49 -0
- package/src/orm/Helpers.ts +297 -0
- package/src/orm/Hook.ts +125 -0
- package/src/orm/Instance.ts +944 -0
- package/src/orm/LazyLoad.ts +117 -0
- package/src/orm/Model.ts +1235 -0
- package/src/orm/ORM.ts +301 -0
- package/src/orm/Patch/fib-cache.ts +7 -0
- package/src/orm/Patch/plugin.ts +25 -0
- package/src/orm/Property.ts +86 -0
- package/src/orm/Settings.ts +134 -0
- package/src/orm/Singleton.ts +97 -0
- package/src/orm/Typo/Adapter.d.ts +5 -0
- package/src/orm/Typo/DMLDriver.d.ts +260 -0
- package/src/orm/Typo/Db.d.ts +100 -0
- package/src/orm/Typo/Error.d.ts +36 -0
- package/src/orm/Typo/ORM.d.ts +315 -0
- package/src/orm/Typo/Validators.d.ts +39 -0
- package/src/orm/Typo/_common.d.ts +44 -0
- package/src/orm/Typo/assoc.d.ts +280 -0
- package/src/orm/Typo/hook.d.ts +68 -0
- package/src/orm/Typo/instance.d.ts +214 -0
- package/{lib → src}/orm/Typo/model.d.ts +297 -176
- package/src/orm/Typo/patch.d.ts +39 -0
- package/src/orm/Typo/property.d.ts +79 -0
- package/src/orm/Typo/query.d.ts +266 -0
- package/{lib → src}/orm/Typo/settings.d.ts +14 -7
- package/{lib → src}/orm/Typo/synchronous.d.ts +51 -26
- package/src/orm/Utilities.ts +1313 -0
- package/src/orm/Validators.ts +127 -0
- package/src/orm/Where/common.ts +8 -0
- package/src/orm/Where/filterDate.ts +74 -0
- package/src/orm/cloneDeep.ts +45 -0
- package/src/orm/index.ts +231 -0
- package/src/orm-core/callback.d.ts +15 -0
- package/{lib → src}/orm-core/dialect.d.ts +75 -52
- package/src/orm-core/error.ts +71 -0
- package/{lib/orm-core/index.d.ts → src/orm-core/index.ts} +8 -2
- package/src/orm-core/sync.d.ts +14 -0
- package/src/orm-core/utils.ts +4 -0
- package/src/orm-property/Property.ts +110 -0
- package/src/orm-property/Utils.ts +26 -0
- package/src/orm-property/customTypes.ts +13 -0
- package/src/orm-property/index.ts +34 -0
- package/src/orm-property/transformer.ts +16 -0
- package/{lib/orm-property/transformers/dm.js → src/orm-property/transformers/dm.ts} +128 -68
- package/src/orm-property/transformers/index.ts +10 -0
- package/src/orm-property/transformers/mssql.ts +285 -0
- package/src/orm-property/transformers/mysql.ts +395 -0
- package/src/orm-property/transformers/postgresql.ts +267 -0
- package/src/orm-property/transformers/sqlite.ts +217 -0
- package/src/plugins/orm-plugin-uacl/Typo.d.ts +173 -0
- package/src/plugins/orm-plugin-uacl/_utils.ts +237 -0
- package/src/plugins/orm-plugin-uacl/acl-tree.ts +440 -0
- package/src/plugins/orm-plugin-uacl/config-acl-tree.ts +592 -0
- package/src/plugins/orm-plugin-uacl/index.ts +180 -0
- package/src/plugins/orm-plugin-uacl/tree.ts +331 -0
- package/src/sql-ddl-sync/Dialects/dm.ts +493 -0
- package/{lib/sql-query/Dialects/index.d.ts → src/sql-ddl-sync/Dialects/index.ts} +3 -3
- package/src/sql-ddl-sync/Dialects/mssql.ts +441 -0
- package/src/sql-ddl-sync/Dialects/mysql.ts +414 -0
- package/src/sql-ddl-sync/Dialects/postgresql.ts +474 -0
- package/src/sql-ddl-sync/Dialects/sqlite.ts +439 -0
- package/src/sql-ddl-sync/SQL.ts +157 -0
- package/src/sql-ddl-sync/Typo/Collection.d.ts +19 -0
- package/src/sql-ddl-sync/Typo/DbIndex.d.ts +11 -0
- package/{lib → src}/sql-ddl-sync/Typo/Dialect.d.ts +67 -52
- package/src/sql-ddl-sync/Typo/Driver.d.ts +67 -0
- package/src/sql-ddl-sync/Typo/Query.d.ts +8 -0
- package/src/sql-ddl-sync/Typo/SQL.d.ts +45 -0
- package/src/sql-ddl-sync/Typo/_common.d.ts +59 -0
- package/src/sql-ddl-sync/Utils.ts +291 -0
- package/src/sql-ddl-sync/index.ts +599 -0
- package/src/sql-query/Comparators.ts +115 -0
- package/src/sql-query/Create.ts +87 -0
- package/{lib/sql-query/Dialects/dm.js → src/sql-query/Dialects/dm.ts} +42 -21
- package/src/sql-query/Dialects/index.ts +14 -0
- package/src/sql-query/Dialects/mssql.ts +91 -0
- package/src/sql-query/Dialects/mysql.ts +120 -0
- package/src/sql-query/Dialects/postgresql.ts +99 -0
- package/src/sql-query/Dialects/sqlite.ts +80 -0
- package/src/sql-query/Helpers.ts +303 -0
- package/src/sql-query/Insert.ts +41 -0
- package/src/sql-query/Query.ts +140 -0
- package/src/sql-query/Remove.ts +111 -0
- package/src/sql-query/Select.ts +719 -0
- package/src/sql-query/Set.ts +25 -0
- package/src/sql-query/Typo/Aggregation.d.ts +34 -0
- package/src/sql-query/Typo/Comparators.d.ts +156 -0
- package/src/sql-query/Typo/Dialect.d.ts +51 -0
- package/src/sql-query/Typo/Field.d.ts +10 -0
- package/src/sql-query/Typo/Helper.d.ts +4 -0
- package/src/sql-query/Typo/Query-ChainBuilder.d.ts +110 -0
- package/src/sql-query/Typo/Query.d.ts +65 -0
- package/src/sql-query/Typo/Sql.d.ts +192 -0
- package/src/sql-query/Typo/SubQuery.d.ts +52 -0
- package/{lib/sql-query/Typo/index.d.ts → src/sql-query/Typo/index.ts} +5 -2
- package/src/sql-query/Update.ts +50 -0
- package/src/sql-query/Where.ts +435 -0
- package/{lib/orm/Patch → src/typings}/fib-cache.d.ts +4 -3
- package/lib/cli/commands/ddlFrom.d.ts +0 -2
- package/lib/cli/commands/dumpModel.d.ts +0 -2
- package/lib/cli/commands/escape.d.ts +0 -2
- package/lib/cli/commands/spinner.d.ts +0 -2
- package/lib/cli/commands/upgrade.d.ts +0 -2
- package/lib/cli/helpers/ddl.d.ts +0 -17
- package/lib/cli/helpers/ddl.js +0 -55
- package/lib/cli/helpers/package.d.ts +0 -26
- package/lib/cli/helpers/package.js +0 -56
- package/lib/cli/index.d.ts +0 -2
- package/lib/cli/index.js +0 -18
- package/lib/db-driver/Typo.d.ts +0 -112
- package/lib/db-driver/Typo.js +0 -1
- package/lib/db-driver/built-ins/base.class.d.ts +0 -96
- package/lib/db-driver/built-ins/base.class.js +0 -186
- package/lib/db-driver/built-ins/driver-dm.d.ts +0 -18
- package/lib/db-driver/built-ins/driver-dm.js +0 -53
- package/lib/db-driver/built-ins/driver-mongodb.d.ts +0 -24
- package/lib/db-driver/built-ins/driver-mongodb.js +0 -46
- package/lib/db-driver/built-ins/driver-mysql.d.ts +0 -18
- package/lib/db-driver/built-ins/driver-mysql.js +0 -37
- package/lib/db-driver/built-ins/driver-postgresql.d.ts +0 -22
- package/lib/db-driver/built-ins/driver-postgresql.js +0 -76
- package/lib/db-driver/built-ins/driver-redis.d.ts +0 -12
- package/lib/db-driver/built-ins/driver-redis.js +0 -35
- package/lib/db-driver/built-ins/driver-sqlite.d.ts +0 -17
- package/lib/db-driver/built-ins/driver-sqlite.js +0 -34
- package/lib/db-driver/index.d.ts +0 -3
- package/lib/db-driver/index.js +0 -4
- package/lib/db-driver/utils.d.ts +0 -14
- package/lib/db-driver/utils.js +0 -187
- package/lib/knex/deps/tarn/dist/PendingOperation.d.ts +0 -12
- package/lib/knex/deps/tarn/dist/PendingOperation.js +0 -48
- package/lib/knex/deps/tarn/dist/Pool.d.ts +0 -97
- package/lib/knex/deps/tarn/dist/Pool.js +0 -516
- package/lib/knex/deps/tarn/dist/PromiseInspection.d.ts +0 -16
- package/lib/knex/deps/tarn/dist/PromiseInspection.js +0 -21
- package/lib/knex/deps/tarn/dist/Resource.d.ts +0 -9
- package/lib/knex/deps/tarn/dist/Resource.js +0 -19
- package/lib/knex/deps/tarn/dist/TimeoutError.d.ts +0 -2
- package/lib/knex/deps/tarn/dist/TimeoutError.js +0 -5
- package/lib/knex/deps/tarn/dist/tarn.d.ts +0 -3
- package/lib/knex/deps/tarn/dist/tarn.js +0 -10
- package/lib/knex/deps/tarn/dist/utils.d.ts +0 -14
- package/lib/knex/deps/tarn/dist/utils.js +0 -60
- package/lib/knex/knex.d.ts +0 -2
- package/lib/knex/knex.js +0 -3
- package/lib/knex/sandbox.d.ts +0 -4
- package/lib/knex/sandbox.js +0 -22
- package/lib/orm/Adapters.d.ts +0 -3
- package/lib/orm/Adapters.js +0 -44
- package/lib/orm/AggregateFunctions.d.ts +0 -3
- package/lib/orm/AggregateFunctions.js +0 -176
- package/lib/orm/Associations/Extend.d.ts +0 -22
- package/lib/orm/Associations/Extend.js +0 -274
- package/lib/orm/Associations/Many.d.ts +0 -17
- package/lib/orm/Associations/Many.js +0 -569
- package/lib/orm/Associations/One.d.ts +0 -16
- package/lib/orm/Associations/One.js +0 -310
- package/lib/orm/Associations/_utils.d.ts +0 -15
- package/lib/orm/Associations/_utils.js +0 -52
- package/lib/orm/ChainFind.d.ts +0 -3
- package/lib/orm/ChainFind.js +0 -327
- package/lib/orm/ChainInstance.d.ts +0 -6
- package/lib/orm/ChainInstance.js +0 -73
- package/lib/orm/Debug.d.ts +0 -2
- package/lib/orm/Debug.js +0 -17
- package/lib/orm/Drivers/DB/base.d.ts +0 -3
- package/lib/orm/Drivers/DB/base.js +0 -3
- package/lib/orm/Drivers/DB/dm.d.ts +0 -11
- package/lib/orm/Drivers/DB/dm.js +0 -23
- package/lib/orm/Drivers/DB/mysql.d.ts +0 -11
- package/lib/orm/Drivers/DB/mysql.js +0 -23
- package/lib/orm/Drivers/DB/postgres.d.ts +0 -11
- package/lib/orm/Drivers/DB/postgres.js +0 -22
- package/lib/orm/Drivers/DB/sqlite3.d.ts +0 -16
- package/lib/orm/Drivers/DB/sqlite3.js +0 -39
- package/lib/orm/Drivers/DML/_ddl-sql.d.ts +0 -3
- package/lib/orm/Drivers/DML/_ddl-sql.js +0 -51
- package/lib/orm/Drivers/DML/_dml-helpers.d.ts +0 -19
- package/lib/orm/Drivers/DML/_dml-helpers.js +0 -51
- package/lib/orm/Drivers/DML/_shared.d.ts +0 -9
- package/lib/orm/Drivers/DML/_shared.js +0 -38
- package/lib/orm/Drivers/DML/_utils.d.ts +0 -8
- package/lib/orm/Drivers/DML/_utils.js +0 -67
- package/lib/orm/Drivers/DML/constants.d.ts +0 -3
- package/lib/orm/Drivers/DML/constants.js +0 -2
- package/lib/orm/Drivers/DML/dm.d.ts +0 -2
- package/lib/orm/Drivers/DML/index.d.ts +0 -4
- package/lib/orm/Drivers/DML/index.js +0 -6
- package/lib/orm/Drivers/DML/mysql.d.ts +0 -2
- package/lib/orm/Drivers/DML/mysql.js +0 -251
- package/lib/orm/Drivers/DML/postgres.d.ts +0 -3
- package/lib/orm/Drivers/DML/postgres.js +0 -276
- package/lib/orm/Drivers/DML/sqlite.d.ts +0 -2
- package/lib/orm/Drivers/DML/sqlite.js +0 -266
- package/lib/orm/Error.d.ts +0 -11
- package/lib/orm/Error.js +0 -40
- package/lib/orm/Helpers.d.ts +0 -35
- package/lib/orm/Helpers.js +0 -233
- package/lib/orm/Hook.d.ts +0 -13
- package/lib/orm/Hook.js +0 -99
- package/lib/orm/Instance.d.ts +0 -2
- package/lib/orm/Instance.js +0 -697
- package/lib/orm/LazyLoad.d.ts +0 -4
- package/lib/orm/LazyLoad.js +0 -76
- package/lib/orm/Model.d.ts +0 -7
- package/lib/orm/Model.js +0 -971
- package/lib/orm/ORM.d.ts +0 -37
- package/lib/orm/ORM.js +0 -241
- package/lib/orm/Patch/fib-cache.js +0 -2
- package/lib/orm/Patch/plugin.d.ts +0 -4
- package/lib/orm/Patch/plugin.js +0 -13
- package/lib/orm/Property.d.ts +0 -9
- package/lib/orm/Property.js +0 -71
- package/lib/orm/Settings.d.ts +0 -42
- package/lib/orm/Settings.js +0 -119
- package/lib/orm/Singleton.d.ts +0 -5
- package/lib/orm/Singleton.js +0 -72
- package/lib/orm/Typo/Adapter.d.ts +0 -5
- package/lib/orm/Typo/Adapter.js +0 -1
- package/lib/orm/Typo/DMLDriver.d.ts +0 -210
- package/lib/orm/Typo/DMLDriver.js +0 -1
- package/lib/orm/Typo/Db.d.ts +0 -38
- package/lib/orm/Typo/Db.js +0 -1
- package/lib/orm/Typo/Error.d.ts +0 -31
- package/lib/orm/Typo/Error.js +0 -1
- package/lib/orm/Typo/ORM.d.ts +0 -233
- package/lib/orm/Typo/ORM.js +0 -3
- package/lib/orm/Typo/Validators.d.ts +0 -32
- package/lib/orm/Typo/Validators.js +0 -2
- package/lib/orm/Typo/_common.d.ts +0 -38
- package/lib/orm/Typo/_common.js +0 -1
- package/lib/orm/Typo/assoc.d.ts +0 -221
- package/lib/orm/Typo/assoc.js +0 -1
- package/lib/orm/Typo/hook.d.ts +0 -42
- package/lib/orm/Typo/hook.js +0 -1
- package/lib/orm/Typo/instance.d.ts +0 -157
- package/lib/orm/Typo/instance.js +0 -1
- package/lib/orm/Typo/model.js +0 -6
- package/lib/orm/Typo/patch.d.ts +0 -31
- package/lib/orm/Typo/patch.js +0 -1
- package/lib/orm/Typo/property.d.ts +0 -57
- package/lib/orm/Typo/property.js +0 -1
- package/lib/orm/Typo/query.d.ts +0 -216
- package/lib/orm/Typo/query.js +0 -1
- package/lib/orm/Typo/settings.js +0 -5
- package/lib/orm/Typo/synchronous.js +0 -1
- package/lib/orm/Utilities.d.ts +0 -179
- package/lib/orm/Utilities.js +0 -975
- package/lib/orm/Validators.d.ts +0 -34
- package/lib/orm/Validators.js +0 -100
- package/lib/orm/Where/common.d.ts +0 -1
- package/lib/orm/Where/common.js +0 -7
- package/lib/orm/Where/filterDate.d.ts +0 -11
- package/lib/orm/Where/filterDate.js +0 -58
- package/lib/orm/index.d.ts +0 -68
- package/lib/orm/index.js +0 -157
- package/lib/orm-core/callback.d.ts +0 -12
- package/lib/orm-core/callback.js +0 -1
- package/lib/orm-core/dialect.js +0 -1
- package/lib/orm-core/error.d.ts +0 -16
- package/lib/orm-core/error.js +0 -29
- package/lib/orm-core/index.js +0 -6
- package/lib/orm-core/sync.d.ts +0 -12
- package/lib/orm-core/sync.js +0 -1
- package/lib/orm-core/utils.d.ts +0 -1
- package/lib/orm-core/utils.js +0 -5
- package/lib/orm-property/Property.d.ts +0 -78
- package/lib/orm-property/Property.js +0 -1
- package/lib/orm-property/Utils.d.ts +0 -9
- package/lib/orm-property/Utils.js +0 -13
- package/lib/orm-property/customTypes.d.ts +0 -2
- package/lib/orm-property/customTypes.js +0 -13
- package/lib/orm-property/index.d.ts +0 -10
- package/lib/orm-property/index.js +0 -22
- package/lib/orm-property/transformer.d.ts +0 -5
- package/lib/orm-property/transformer.js +0 -10
- package/lib/orm-property/transformers/dm.d.ts +0 -29
- package/lib/orm-property/transformers/index.d.ts +0 -4
- package/lib/orm-property/transformers/index.js +0 -5
- package/lib/orm-property/transformers/mysql.d.ts +0 -102
- package/lib/orm-property/transformers/mysql.js +0 -261
- package/lib/orm-property/transformers/postgresql.d.ts +0 -54
- package/lib/orm-property/transformers/postgresql.js +0 -189
- package/lib/orm-property/transformers/sqlite.d.ts +0 -19
- package/lib/orm-property/transformers/sqlite.js +0 -171
- package/lib/sql-ddl-sync/Dialects/dm.d.ts +0 -40
- package/lib/sql-ddl-sync/Dialects/dm.js +0 -296
- package/lib/sql-ddl-sync/Dialects/index.d.ts +0 -7
- package/lib/sql-ddl-sync/Dialects/index.js +0 -7
- package/lib/sql-ddl-sync/Dialects/mysql.d.ts +0 -39
- package/lib/sql-ddl-sync/Dialects/mysql.js +0 -240
- package/lib/sql-ddl-sync/Dialects/postgresql.d.ts +0 -40
- package/lib/sql-ddl-sync/Dialects/postgresql.js +0 -286
- package/lib/sql-ddl-sync/Dialects/sqlite.d.ts +0 -44
- package/lib/sql-ddl-sync/Dialects/sqlite.js +0 -256
- package/lib/sql-ddl-sync/SQL.d.ts +0 -12
- package/lib/sql-ddl-sync/SQL.js +0 -108
- package/lib/sql-ddl-sync/Typo/Collection.d.ts +0 -13
- package/lib/sql-ddl-sync/Typo/Collection.js +0 -1
- package/lib/sql-ddl-sync/Typo/DbIndex.d.ts +0 -13
- package/lib/sql-ddl-sync/Typo/DbIndex.js +0 -1
- package/lib/sql-ddl-sync/Typo/Dialect.js +0 -1
- package/lib/sql-ddl-sync/Typo/Driver.d.ts +0 -53
- package/lib/sql-ddl-sync/Typo/Driver.js +0 -1
- package/lib/sql-ddl-sync/Typo/Query.d.ts +0 -7
- package/lib/sql-ddl-sync/Typo/Query.js +0 -1
- package/lib/sql-ddl-sync/Typo/SQL.d.ts +0 -31
- package/lib/sql-ddl-sync/Typo/SQL.js +0 -1
- package/lib/sql-ddl-sync/Typo/_common.d.ts +0 -29
- package/lib/sql-ddl-sync/Typo/_common.js +0 -1
- package/lib/sql-ddl-sync/Utils.d.ts +0 -40
- package/lib/sql-ddl-sync/Utils.js +0 -217
- package/lib/sql-ddl-sync/index.d.ts +0 -87
- package/lib/sql-ddl-sync/index.js +0 -371
- package/lib/sql-query/Comparators.d.ts +0 -3
- package/lib/sql-query/Comparators.js +0 -94
- package/lib/sql-query/Create.d.ts +0 -35
- package/lib/sql-query/Create.js +0 -77
- package/lib/sql-query/Dialects/dm.d.ts +0 -3
- package/lib/sql-query/Dialects/index.js +0 -12
- package/lib/sql-query/Dialects/mssql.d.ts +0 -3
- package/lib/sql-query/Dialects/mssql.js +0 -73
- package/lib/sql-query/Dialects/mysql.d.ts +0 -3
- package/lib/sql-query/Dialects/mysql.js +0 -100
- package/lib/sql-query/Dialects/postgresql.d.ts +0 -3
- package/lib/sql-query/Dialects/postgresql.js +0 -76
- package/lib/sql-query/Dialects/sqlite.d.ts +0 -3
- package/lib/sql-query/Dialects/sqlite.js +0 -61
- package/lib/sql-query/Helpers.d.ts +0 -38
- package/lib/sql-query/Helpers.js +0 -259
- package/lib/sql-query/Insert.d.ts +0 -12
- package/lib/sql-query/Insert.js +0 -33
- package/lib/sql-query/Query.d.ts +0 -29
- package/lib/sql-query/Query.js +0 -119
- package/lib/sql-query/Remove.d.ts +0 -16
- package/lib/sql-query/Remove.js +0 -93
- package/lib/sql-query/Select.d.ts +0 -62
- package/lib/sql-query/Select.js +0 -533
- package/lib/sql-query/Set.d.ts +0 -4
- package/lib/sql-query/Set.js +0 -16
- package/lib/sql-query/Typo/Aggregation.d.ts +0 -32
- package/lib/sql-query/Typo/Aggregation.js +0 -1
- package/lib/sql-query/Typo/Comparators.d.ts +0 -140
- package/lib/sql-query/Typo/Comparators.js +0 -1
- package/lib/sql-query/Typo/Dialect.d.ts +0 -39
- package/lib/sql-query/Typo/Dialect.js +0 -1
- package/lib/sql-query/Typo/Field.d.ts +0 -8
- package/lib/sql-query/Typo/Field.js +0 -1
- package/lib/sql-query/Typo/Helper.d.ts +0 -4
- package/lib/sql-query/Typo/Helper.js +0 -1
- package/lib/sql-query/Typo/Query-ChainBuilder.d.ts +0 -80
- package/lib/sql-query/Typo/Query-ChainBuilder.js +0 -1
- package/lib/sql-query/Typo/Query.d.ts +0 -34
- package/lib/sql-query/Typo/Query.js +0 -16
- package/lib/sql-query/Typo/Sql.d.ts +0 -143
- package/lib/sql-query/Typo/Sql.js +0 -1
- package/lib/sql-query/Typo/SubQuery.d.ts +0 -39
- package/lib/sql-query/Typo/SubQuery.js +0 -1
- package/lib/sql-query/Typo/index.js +0 -1
- package/lib/sql-query/Update.d.ts +0 -15
- package/lib/sql-query/Update.js +0 -38
- package/lib/sql-query/Where.d.ts +0 -4
- package/lib/sql-query/Where.js +0 -280
- /package/{lib → src}/codepoints-map.json +0 -0
|
@@ -0,0 +1,427 @@
|
|
|
1
|
+
import { createRequire } from 'node:module';
|
|
2
|
+
const require = createRequire(import.meta.url);
|
|
3
|
+
const util = require('util');
|
|
4
|
+
|
|
5
|
+
import * as Utilities from './Utilities';
|
|
6
|
+
import ChainInstance from './ChainInstance';
|
|
7
|
+
|
|
8
|
+
import type { FxOrmQuery } from './Typo/query';
|
|
9
|
+
import type { FxOrmModel } from './Typo/model';
|
|
10
|
+
import type { FxOrmInstance } from './Typo/instance';
|
|
11
|
+
import type { FxOrmAssociation } from './Typo/assoc';
|
|
12
|
+
import type { FxOrmCommon } from './Typo/_common';
|
|
13
|
+
import type { FxOrmProperty } from './Typo/property';
|
|
14
|
+
|
|
15
|
+
import type {
|
|
16
|
+
FxSqlQueryComparator,
|
|
17
|
+
FxSqlQuerySql,
|
|
18
|
+
FxSqlQuerySubQuery
|
|
19
|
+
} from '../sql-query/Query';
|
|
20
|
+
import { pickPointTypeFields } from './Drivers/DML/_dml-helpers';
|
|
21
|
+
|
|
22
|
+
const MODEL_FUNCS = [
|
|
23
|
+
"hasOne", "hasMany",
|
|
24
|
+
"drop", "sync", "get", "clear", "create",
|
|
25
|
+
"exists", "settings", "aggregate"
|
|
26
|
+
];
|
|
27
|
+
|
|
28
|
+
const ChainFind = function (
|
|
29
|
+
this: void,
|
|
30
|
+
Model: FxOrmModel.Model,
|
|
31
|
+
opts: FxOrmQuery.ChainFindOptions
|
|
32
|
+
) {
|
|
33
|
+
const merges = opts.merge = Utilities.combineMergeInfoToArray( opts.merge );
|
|
34
|
+
|
|
35
|
+
const chainRunSync = function (): FxOrmInstance.Instance[] {
|
|
36
|
+
let conditions: FxSqlQuerySubQuery.SubQueryConditions = util.omit(opts.conditions, Model.virtualProperties);
|
|
37
|
+
|
|
38
|
+
conditions = Utilities.transformPropertyNames(conditions, opts.properties);
|
|
39
|
+
Utilities.filterWhereConditionsInput(conditions, { properties: Model.allProperties });
|
|
40
|
+
|
|
41
|
+
const order = Utilities.transformOrderPropertyNames(opts.order, opts.properties);
|
|
42
|
+
|
|
43
|
+
let foundItems: FxOrmInstance.InstanceDataPayload[];
|
|
44
|
+
|
|
45
|
+
const vFields = Object.entries(Model.virtualProperties).map(([k, p]) => p.mapsTo || k);
|
|
46
|
+
const { tableConditions, topConditions } = Utilities.extractSelectTopConditions(conditions, vFields);
|
|
47
|
+
|
|
48
|
+
const __pointTypeMapsTo = pickPointTypeFields(opts.driver, Model.allProperties);
|
|
49
|
+
|
|
50
|
+
foundItems = opts.driver.find(opts.only, opts.table, tableConditions, {
|
|
51
|
+
limit : Utilities.coercePositiveInt(opts.limit, undefined),
|
|
52
|
+
order : order,
|
|
53
|
+
merge : merges,
|
|
54
|
+
offset : Utilities.coercePositiveInt(opts.offset, undefined),
|
|
55
|
+
exists : (opts.exists || []).map(existCond => {
|
|
56
|
+
const maybeAssoc = Object.values(Model.associations).find(({ association }) => association.mergeTable === existCond.table)?.association;
|
|
57
|
+
const mergeProps = maybeAssoc?.props || null;
|
|
58
|
+
|
|
59
|
+
if (mergeProps) {
|
|
60
|
+
existCond.conditions = util.omit(existCond.conditions, vFields);
|
|
61
|
+
existCond.conditions = Utilities.transformPropertyNames(existCond.conditions, mergeProps);
|
|
62
|
+
Utilities.filterWhereConditionsInput(existCond.conditions, { properties: mergeProps });
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return existCond;
|
|
66
|
+
}),
|
|
67
|
+
topConditions,
|
|
68
|
+
selectVirtualFields: vFields,
|
|
69
|
+
generateSqlSelect: opts.generateSqlSelect,
|
|
70
|
+
__pointTypeMapsTo
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
if (foundItems.length === 0) {
|
|
74
|
+
return [];
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* only valid for related table based on single foreign key
|
|
79
|
+
* @param err
|
|
80
|
+
* @param items
|
|
81
|
+
*/
|
|
82
|
+
const eagerLoadSync = function (items: FxOrmInstance.InstanceDataPayload[]) {
|
|
83
|
+
const associationKey_Item_Map: {[key: string]: typeof items[any]} = {};
|
|
84
|
+
|
|
85
|
+
const self_key_field = opts.keys[0];
|
|
86
|
+
|
|
87
|
+
const keys = items.map(function (item: FxOrmInstance.InstanceDataPayload) {
|
|
88
|
+
const key = item[self_key_field];
|
|
89
|
+
associationKey_Item_Map[key] = item;
|
|
90
|
+
|
|
91
|
+
return key;
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
Utilities.parallelQueryIfPossible(
|
|
95
|
+
false,
|
|
96
|
+
opts.__eager || [],
|
|
97
|
+
(association: FxOrmAssociation.InstanceAssociationItem) => {
|
|
98
|
+
let instances: FxOrmInstance.Instance[] = [];
|
|
99
|
+
|
|
100
|
+
instances = opts.driver.eagerQuery<FxOrmInstance.Instance[]>(association, opts, keys);
|
|
101
|
+
|
|
102
|
+
const association_name = association.name;
|
|
103
|
+
|
|
104
|
+
for (
|
|
105
|
+
let idx = 0, instance: FxOrmInstance.Instance, item = null;
|
|
106
|
+
instance = instances[idx];
|
|
107
|
+
idx++
|
|
108
|
+
) {
|
|
109
|
+
item = associationKey_Item_Map[instance.$p];
|
|
110
|
+
|
|
111
|
+
// Create the association arrays
|
|
112
|
+
if (!item[association_name])
|
|
113
|
+
item[association_name] = []
|
|
114
|
+
|
|
115
|
+
item[association_name].push(instance);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
)
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
const items = foundItems.map<FxOrmInstance.Instance>((dataItem: FxOrmInstance.InstanceDataPayload) => {
|
|
122
|
+
const newInstanceSync = opts.newInstanceSync;
|
|
123
|
+
|
|
124
|
+
return newInstanceSync(dataItem);
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
if (opts.__eager && opts.__eager.length)
|
|
128
|
+
eagerLoadSync(items);
|
|
129
|
+
|
|
130
|
+
return items;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
const chainRun = function<T> (done?: FxOrmCommon.GenericCallback<T|T[]|FxOrmInstance.InstanceDataPayload[]>) {
|
|
134
|
+
const syncResponse = Utilities.catchBlocking(chainRunSync);
|
|
135
|
+
Utilities.takeAwayResult(syncResponse, { no_throw: true, callback: done, use_tick: true });
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
const chain: FxOrmQuery.IChainFind = {
|
|
139
|
+
model: null as any,
|
|
140
|
+
options: null as any,
|
|
141
|
+
|
|
142
|
+
whereExists: function () {
|
|
143
|
+
if (arguments.length && Array.isArray(arguments[0])) {
|
|
144
|
+
opts.exists = arguments[0];
|
|
145
|
+
} else {
|
|
146
|
+
opts.exists = Array.prototype.slice.apply(arguments);
|
|
147
|
+
}
|
|
148
|
+
return this;
|
|
149
|
+
},
|
|
150
|
+
only: function () {
|
|
151
|
+
if (arguments.length && Array.isArray(arguments[0])) {
|
|
152
|
+
opts.only = arguments[0];
|
|
153
|
+
} else {
|
|
154
|
+
opts.only = Array.prototype.slice.apply(arguments);
|
|
155
|
+
}
|
|
156
|
+
return this;
|
|
157
|
+
},
|
|
158
|
+
omit: function () {
|
|
159
|
+
let omit = null;
|
|
160
|
+
|
|
161
|
+
if (arguments.length && Array.isArray(arguments[0])) {
|
|
162
|
+
omit = arguments[0];
|
|
163
|
+
} else {
|
|
164
|
+
omit = Array.prototype.slice.apply(arguments);
|
|
165
|
+
}
|
|
166
|
+
this.only(util.difference(Object.keys(opts.properties), omit));
|
|
167
|
+
return this;
|
|
168
|
+
},
|
|
169
|
+
limit: function (limit) {
|
|
170
|
+
opts.limit = limit;
|
|
171
|
+
return this;
|
|
172
|
+
},
|
|
173
|
+
skip: function (offset) {
|
|
174
|
+
return this.offset(offset);
|
|
175
|
+
},
|
|
176
|
+
offset: function (offset) {
|
|
177
|
+
opts.offset = offset;
|
|
178
|
+
return this;
|
|
179
|
+
},
|
|
180
|
+
order: (function (this: any, ...orders: FxOrmQuery.OrderSeqRawTuple) {
|
|
181
|
+
if (!Array.isArray(opts.order)) {
|
|
182
|
+
opts.order = [];
|
|
183
|
+
}
|
|
184
|
+
opts.order = opts.order.concat(Utilities.standardizeOrder(orders));
|
|
185
|
+
|
|
186
|
+
return this;
|
|
187
|
+
}) as any,
|
|
188
|
+
orderRaw: function (str, args?) {
|
|
189
|
+
if (!Array.isArray(opts.order)) {
|
|
190
|
+
opts.order = [];
|
|
191
|
+
}
|
|
192
|
+
args = args || [];
|
|
193
|
+
|
|
194
|
+
opts.order.push([ str, args ]);
|
|
195
|
+
return this;
|
|
196
|
+
},
|
|
197
|
+
eager: function () {
|
|
198
|
+
// This will allow params such as ("abc", "def") or (["abc", "def"])
|
|
199
|
+
var associations: string[] = util.flatten(arguments);
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
opts.__eager = opts.associations.filter(function (association) {
|
|
203
|
+
return ~associations.indexOf(association.name);
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
return this;
|
|
207
|
+
},
|
|
208
|
+
|
|
209
|
+
/* methods to ChainInstance :start */
|
|
210
|
+
each: function (cb) {
|
|
211
|
+
return ChainInstance(this, cb as any);
|
|
212
|
+
},
|
|
213
|
+
/* methods to ChainInstance :end */
|
|
214
|
+
|
|
215
|
+
/* sync, callback-as-run style methods :start */
|
|
216
|
+
all: null as any,
|
|
217
|
+
allSync: null as any,
|
|
218
|
+
where: null as any,
|
|
219
|
+
whereSync: null as any,
|
|
220
|
+
|
|
221
|
+
find: function (...args: any[]) {
|
|
222
|
+
var cb: FxOrmCommon.GenericCallback<FxOrmInstance.Instance[]> | null = null;
|
|
223
|
+
|
|
224
|
+
opts.conditions = opts.conditions || {};
|
|
225
|
+
|
|
226
|
+
if (typeof util.last(args) === "function") {
|
|
227
|
+
cb = args.pop() as FxOrmCommon.GenericCallback<FxOrmInstance.Instance[]>;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
if (typeof args[0] === "object") {
|
|
231
|
+
util.extend(opts.conditions, args[0]);
|
|
232
|
+
} else if (typeof args[0] === "string") {
|
|
233
|
+
opts.conditions.__sql = (opts.conditions.__sql || []) as FxSqlQuerySubQuery.UnderscoreSqlInput;
|
|
234
|
+
opts.conditions.__sql.push(args as any);
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
if (cb) {
|
|
238
|
+
chainRun(cb as any);
|
|
239
|
+
}
|
|
240
|
+
return this;
|
|
241
|
+
},
|
|
242
|
+
|
|
243
|
+
findSync: function (...args: any[]) {
|
|
244
|
+
opts.conditions = opts.conditions || {};
|
|
245
|
+
|
|
246
|
+
if (typeof args[0] === "object") {
|
|
247
|
+
util.extend(opts.conditions, args[0]);
|
|
248
|
+
} else if (typeof args[0] === "string") {
|
|
249
|
+
opts.conditions.__sql = (opts.conditions.__sql || []) as FxSqlQuerySubQuery.UnderscoreSqlInput;
|
|
250
|
+
opts.conditions.__sql.push(args as any);
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
return chainRunSync() as any;
|
|
254
|
+
},
|
|
255
|
+
|
|
256
|
+
count: function (cb?) {
|
|
257
|
+
process.nextTick(() => {
|
|
258
|
+
const syncResult = Utilities.catchBlocking<number>(chain.countSync)
|
|
259
|
+
Utilities.takeAwayResult<number>(syncResult, { callback: cb });
|
|
260
|
+
});
|
|
261
|
+
return this;
|
|
262
|
+
},
|
|
263
|
+
|
|
264
|
+
countSync: function () {
|
|
265
|
+
const data: FxOrmQuery.CountResult[] = opts.driver.count(
|
|
266
|
+
opts.table,
|
|
267
|
+
Utilities.transformPropertyNames(opts.conditions, opts.properties),
|
|
268
|
+
{
|
|
269
|
+
merge : merges
|
|
270
|
+
});
|
|
271
|
+
|
|
272
|
+
if (data.length === 0)
|
|
273
|
+
return 0;
|
|
274
|
+
|
|
275
|
+
return data[0].c
|
|
276
|
+
},
|
|
277
|
+
|
|
278
|
+
remove: function (cb?) {
|
|
279
|
+
process.nextTick(() => {
|
|
280
|
+
const syncResult = Utilities.catchBlocking<FxOrmQuery.RemoveResult>(chain.removeSync)
|
|
281
|
+
Utilities.takeAwayResult(syncResult, { callback: cb });
|
|
282
|
+
})
|
|
283
|
+
return this;
|
|
284
|
+
},
|
|
285
|
+
|
|
286
|
+
// TODO: add test case about `.removeSync()`
|
|
287
|
+
removeSync: function () {
|
|
288
|
+
Utilities.disAllowOpForVModel(Model, 'modelChain.remove');
|
|
289
|
+
|
|
290
|
+
const keys = opts.keyProperties.map((x: FxOrmProperty.NormalizedProperty) => x.mapsTo!);
|
|
291
|
+
|
|
292
|
+
const data = opts.driver.find(
|
|
293
|
+
keys,
|
|
294
|
+
opts.table,
|
|
295
|
+
Utilities.transformPropertyNames(opts.conditions, opts.properties),
|
|
296
|
+
{
|
|
297
|
+
limit : opts.limit,
|
|
298
|
+
order : Utilities.transformOrderPropertyNames(
|
|
299
|
+
opts.order, opts.properties
|
|
300
|
+
),
|
|
301
|
+
merge : merges,
|
|
302
|
+
offset : opts.offset,
|
|
303
|
+
exists : opts.exists,
|
|
304
|
+
__pointTypeMapsTo: [],
|
|
305
|
+
});
|
|
306
|
+
|
|
307
|
+
if (data.length === 0) {
|
|
308
|
+
return null;
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
const conditions: FxSqlQuerySubQuery.SubQueryConditions = {};
|
|
312
|
+
let or: FxSqlQueryComparator.SubQueryInput;
|
|
313
|
+
|
|
314
|
+
conditions.or = [];
|
|
315
|
+
|
|
316
|
+
for (let i = 0; i < data.length; i++) {
|
|
317
|
+
or = {};
|
|
318
|
+
for (let j = 0; j < keys.length; j++) {
|
|
319
|
+
or[keys[j]!] = data[i][keys[j]!];
|
|
320
|
+
}
|
|
321
|
+
conditions.or.push(or);
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
return opts.driver.remove(opts.table, conditions);
|
|
325
|
+
},
|
|
326
|
+
|
|
327
|
+
first: function (cb?) {
|
|
328
|
+
return this.run(function (err: Error, items: FxOrmInstance.Instance[]) {
|
|
329
|
+
return cb!(err, items && items.length > 0 ? items[0] : null);
|
|
330
|
+
});
|
|
331
|
+
},
|
|
332
|
+
firstSync: function () {
|
|
333
|
+
const items = this.runSync();
|
|
334
|
+
|
|
335
|
+
return items && items.length > 0 ? items[0] : null
|
|
336
|
+
},
|
|
337
|
+
last: function (cb?) {
|
|
338
|
+
return this.run(function (err: Error, items: FxOrmInstance.Instance[]) {
|
|
339
|
+
return cb!(err, items && items.length > 0 ? items[items.length - 1] : null);
|
|
340
|
+
});
|
|
341
|
+
},
|
|
342
|
+
lastSync: function () {
|
|
343
|
+
const items = this.runSync();
|
|
344
|
+
|
|
345
|
+
return items && items.length > 0 ? items[items.length - 1] : null
|
|
346
|
+
},
|
|
347
|
+
run: function (cb?) {
|
|
348
|
+
chainRun(cb as any);
|
|
349
|
+
return this;
|
|
350
|
+
},
|
|
351
|
+
runSync: function () {
|
|
352
|
+
return chainRunSync() as any;
|
|
353
|
+
},
|
|
354
|
+
/* sync, callback-as-run style methods :end */
|
|
355
|
+
};
|
|
356
|
+
|
|
357
|
+
chain.allSync = chain.whereSync = chain.findSync;
|
|
358
|
+
chain.all = chain.where = chain.find;
|
|
359
|
+
|
|
360
|
+
if (opts.associations) {
|
|
361
|
+
for (let i = 0; i < opts.associations.length; i++) {
|
|
362
|
+
addChainMethod(chain, opts.associations[i], opts);
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
for (let k in Model) {
|
|
366
|
+
if (MODEL_FUNCS.indexOf(k) >= 0) {
|
|
367
|
+
continue;
|
|
368
|
+
}
|
|
369
|
+
if (typeof Model[k] !== "function" || chain[k]) {
|
|
370
|
+
continue;
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
chain[k] = Model[k];
|
|
374
|
+
}
|
|
375
|
+
chain.model = Model;
|
|
376
|
+
chain.options = opts as FxOrmQuery.ChainFindInstanceOptions;
|
|
377
|
+
|
|
378
|
+
return chain
|
|
379
|
+
} as any as FxOrmQuery.ChainFindGenerator;
|
|
380
|
+
|
|
381
|
+
export default ChainFind
|
|
382
|
+
|
|
383
|
+
function addChainMethod(
|
|
384
|
+
chain: FxOrmQuery.IChainFind,
|
|
385
|
+
association: FxOrmAssociation.InstanceAssociationItem,
|
|
386
|
+
opts: FxOrmQuery.ChainFindOptions
|
|
387
|
+
) {
|
|
388
|
+
chain[association.hasAccessor] = function<T = any> (value: T) {
|
|
389
|
+
if (!opts.exists) {
|
|
390
|
+
opts.exists = [];
|
|
391
|
+
}
|
|
392
|
+
var conditions: FxSqlQuerySubQuery.SubQueryConditions = {};
|
|
393
|
+
|
|
394
|
+
var assocIds = Object.keys(association.mergeAssocId);
|
|
395
|
+
var ids = association.model.id;
|
|
396
|
+
function mergeConditions(source: FxOrmInstance.InstanceDataPayload) {
|
|
397
|
+
for (let i = 0, cond_item; i < assocIds.length; i++) {
|
|
398
|
+
cond_item = conditions[assocIds[i]];
|
|
399
|
+
|
|
400
|
+
if (typeof cond_item === "undefined") {
|
|
401
|
+
conditions[assocIds[i]] = source[ids[i]];
|
|
402
|
+
} else if (Array.isArray(cond_item)) {
|
|
403
|
+
cond_item.push(source[ids[i]]);
|
|
404
|
+
conditions[assocIds[i]] = cond_item
|
|
405
|
+
} else {
|
|
406
|
+
conditions[assocIds[i]] = [ cond_item, source[ids[i]] ];
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
if (Array.isArray(value)) {
|
|
412
|
+
for (let i = 0; i < value.length; i++) {
|
|
413
|
+
mergeConditions(value[i]);
|
|
414
|
+
}
|
|
415
|
+
} else {
|
|
416
|
+
mergeConditions(value as any);
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
opts.exists!.push({
|
|
420
|
+
table : association.mergeTable,
|
|
421
|
+
link : [ Object.keys(association.mergeId), association.model.id ] as FxSqlQuerySql.WhereExistsLinkTuple,
|
|
422
|
+
conditions : conditions
|
|
423
|
+
});
|
|
424
|
+
|
|
425
|
+
return chain;
|
|
426
|
+
};
|
|
427
|
+
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import type { FxOrmError } from "./Typo/Error";
|
|
2
|
+
import type { FxOrmInstance } from "./Typo/instance";
|
|
3
|
+
import type { FxOrmQuery } from "./Typo/query";
|
|
4
|
+
import type { FxOrmCommon } from "./Typo/_common";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* NOT SUPPORTED
|
|
8
|
+
*/
|
|
9
|
+
export default function ChainInstance(chain: FxOrmQuery.IChainFind, chain_cb: FxOrmQuery.IChainInstanceCallbackFn): FxOrmQuery.IChainInstance {
|
|
10
|
+
let instances: FxOrmInstance.Instance[] = null as any;
|
|
11
|
+
let loading = false;
|
|
12
|
+
const queue: {hwd: (...args: any[]) => any, args?: any[]}[] = [];
|
|
13
|
+
|
|
14
|
+
const load = function () {
|
|
15
|
+
loading = true;
|
|
16
|
+
|
|
17
|
+
chain.run(function (err: FxOrmError.ExtendedError, items: FxOrmInstance.Instance[]) {
|
|
18
|
+
instances = items;
|
|
19
|
+
|
|
20
|
+
return next();
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
const pushIterateeQueue = function<HDLR_TYPE>(hwd: (cb: HDLR_TYPE) => void): FxOrmQuery.IChainInstanceCallbackFn {
|
|
25
|
+
return function (cb: HDLR_TYPE) {
|
|
26
|
+
if (!loading) {
|
|
27
|
+
load();
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
queue.push({ hwd: hwd, args: [cb] });
|
|
31
|
+
|
|
32
|
+
return calls;
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
const next = function () {
|
|
36
|
+
if (queue.length === 0) return ;
|
|
37
|
+
|
|
38
|
+
const item = queue.shift();
|
|
39
|
+
|
|
40
|
+
return item!.hwd.apply(calls, item!.args || []);
|
|
41
|
+
};
|
|
42
|
+
const calls: FxOrmQuery.IChainInstance = {
|
|
43
|
+
_each: pushIterateeQueue<FxOrmQuery.IChainInstanceCallbackFn>(function (cb) {
|
|
44
|
+
instances.forEach(cb);
|
|
45
|
+
|
|
46
|
+
return next();
|
|
47
|
+
}),
|
|
48
|
+
filter: pushIterateeQueue<FxOrmQuery.IChainInstanceCallbackFn>(function (cb) {
|
|
49
|
+
instances = instances.filter(cb);
|
|
50
|
+
|
|
51
|
+
return next();
|
|
52
|
+
}),
|
|
53
|
+
sort: pushIterateeQueue<(a: FxOrmInstance.Instance, b: FxOrmInstance.Instance) => number>(function (cb) {
|
|
54
|
+
instances.sort(cb);
|
|
55
|
+
|
|
56
|
+
return next();
|
|
57
|
+
}),
|
|
58
|
+
count: pushIterateeQueue<(count: number) => void>(function (cb) {
|
|
59
|
+
cb(instances.length);
|
|
60
|
+
|
|
61
|
+
return next();
|
|
62
|
+
}),
|
|
63
|
+
get: pushIterateeQueue<(instances: FxOrmInstance.Instance[]) => void>(function (cb) {
|
|
64
|
+
cb(instances);
|
|
65
|
+
|
|
66
|
+
return next();
|
|
67
|
+
}),
|
|
68
|
+
save: pushIterateeQueue<FxOrmCommon.ExecutionCallback<FxOrmError.ExtendedError>>(function (cb) {
|
|
69
|
+
const saveNext = function (i: number): any {
|
|
70
|
+
if (i >= instances.length) {
|
|
71
|
+
if (typeof cb === "function") {
|
|
72
|
+
cb();
|
|
73
|
+
}
|
|
74
|
+
return next();
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
return instances[i].save(function (err) {
|
|
78
|
+
if (err) {
|
|
79
|
+
if (typeof cb === "function") {
|
|
80
|
+
cb(err);
|
|
81
|
+
}
|
|
82
|
+
return next();
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
return saveNext(i + 1);
|
|
86
|
+
});
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
return saveNext(0);
|
|
90
|
+
})
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
if (typeof chain_cb === "function") {
|
|
94
|
+
return calls._each(chain_cb);
|
|
95
|
+
}
|
|
96
|
+
return calls;
|
|
97
|
+
}
|
package/src/orm/Debug.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { createRequire } from 'node:module';
|
|
2
|
+
const require = createRequire(import.meta.url);
|
|
3
|
+
const util = require("util");
|
|
4
|
+
const tty = require("tty");
|
|
5
|
+
|
|
6
|
+
import type { FxOrmDMLDriver } from "./Typo/DMLDriver";
|
|
7
|
+
|
|
8
|
+
export function sql (driver: FxOrmDMLDriver.DMLDriver | string, sql: string) {
|
|
9
|
+
var fmt: string;
|
|
10
|
+
|
|
11
|
+
if (tty.isatty(process.stdout.fd)) {
|
|
12
|
+
fmt = "\x1b[32;1m(orm/%s) \x1b[34m%s\x1b[0m\n";
|
|
13
|
+
sql = sql.replace(/`(.+?)`/g, function (m) { return "\x1b[31m" + m + "\x1b[34m"; });
|
|
14
|
+
} else {
|
|
15
|
+
fmt = "[SQL/%s] %s\n";
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
process.stdout.write(
|
|
19
|
+
util.format(fmt, driver, sql) as any
|
|
20
|
+
);
|
|
21
|
+
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { createRequire } from 'node:module';
|
|
2
|
+
const require = createRequire(import.meta.url);
|
|
3
|
+
import { Driver as FxDbDriver } from '../../../db-driver/index';
|
|
4
|
+
|
|
5
|
+
import getEventEmitter from './base';
|
|
6
|
+
|
|
7
|
+
import * as Utilities from '../../Utilities';
|
|
8
|
+
|
|
9
|
+
import type { FxOrmCommon } from '../../Typo/_common';
|
|
10
|
+
import type { FxOrmDb } from '../../Typo/Db';
|
|
11
|
+
|
|
12
|
+
const Driver = FxDbDriver.getDriver('dm');
|
|
13
|
+
|
|
14
|
+
export class Database extends Driver implements FxOrmDb.Database<Class_DbConnection> {
|
|
15
|
+
eventor: Class_EventEmitter = getEventEmitter();
|
|
16
|
+
|
|
17
|
+
connect(cb?: FxOrmCommon.GenericCallback<Class_DbConnection>) {
|
|
18
|
+
const exposedErrResults = Utilities.catchBlocking(
|
|
19
|
+
() => super.open()
|
|
20
|
+
)
|
|
21
|
+
Utilities.takeAwayResult(exposedErrResults, { no_throw: !!cb, callback: cb});
|
|
22
|
+
|
|
23
|
+
return this.connection
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
query<T = any>(sql: string, cb?: FxOrmCommon.GenericCallback<T>) {
|
|
27
|
+
const exposedErrResults = Utilities.catchBlocking(
|
|
28
|
+
() => this.execute(sql)
|
|
29
|
+
)
|
|
30
|
+
|
|
31
|
+
Utilities.takeAwayResult(exposedErrResults, { no_throw: !!cb, callback: cb});
|
|
32
|
+
|
|
33
|
+
return exposedErrResults.result;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { createRequire } from 'node:module';
|
|
2
|
+
const require = createRequire(import.meta.url);
|
|
3
|
+
import { Driver as FxDbDriver } from '../../../db-driver/index';
|
|
4
|
+
|
|
5
|
+
import getEventEmitter from './base';
|
|
6
|
+
|
|
7
|
+
import * as Utilities from '../../Utilities';
|
|
8
|
+
|
|
9
|
+
import type { FxOrmCommon } from '../../Typo/_common';
|
|
10
|
+
import type { FxOrmDb } from '../../Typo/Db';
|
|
11
|
+
|
|
12
|
+
const Driver = FxDbDriver.getDriver('mssql');
|
|
13
|
+
|
|
14
|
+
export default class MssqlDatabase extends Driver implements FxOrmDb.Database<Class_DbConnection> {
|
|
15
|
+
eventor: Class_EventEmitter = getEventEmitter();
|
|
16
|
+
|
|
17
|
+
connect(cb?: FxOrmCommon.GenericCallback<Class_DbConnection>) {
|
|
18
|
+
const exposedErrResults = Utilities.catchBlocking(
|
|
19
|
+
() => super.open()
|
|
20
|
+
)
|
|
21
|
+
Utilities.takeAwayResult(exposedErrResults, { no_throw: !!cb, callback: cb});
|
|
22
|
+
|
|
23
|
+
return this.connection
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
query<T = any>(sql: string, cb?: FxOrmCommon.GenericCallback<T>) {
|
|
27
|
+
const exposedErrResults = Utilities.catchBlocking(
|
|
28
|
+
() => this.execute(sql)
|
|
29
|
+
)
|
|
30
|
+
|
|
31
|
+
Utilities.takeAwayResult(exposedErrResults, { no_throw: !!cb, callback: cb});
|
|
32
|
+
|
|
33
|
+
return exposedErrResults.result;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { createRequire } from 'node:module';
|
|
2
|
+
const require = createRequire(import.meta.url);
|
|
3
|
+
import { Driver as FxDbDriver } from '../../../db-driver/index';
|
|
4
|
+
|
|
5
|
+
import getEventEmitter from './base';
|
|
6
|
+
|
|
7
|
+
import * as Utilities from '../../Utilities';
|
|
8
|
+
|
|
9
|
+
import type { FxOrmCommon } from '../../Typo/_common';
|
|
10
|
+
import type { FxOrmDb } from '../../Typo/Db';
|
|
11
|
+
|
|
12
|
+
const Driver = FxDbDriver.getDriver('mysql');
|
|
13
|
+
|
|
14
|
+
export class Database extends Driver implements FxOrmDb.Database<Class_MySQL> {
|
|
15
|
+
eventor: Class_EventEmitter = getEventEmitter();
|
|
16
|
+
|
|
17
|
+
connect(cb?: FxOrmCommon.GenericCallback<Class_MySQL>) {
|
|
18
|
+
const exposedErrResults = Utilities.catchBlocking(
|
|
19
|
+
() => super.open()
|
|
20
|
+
)
|
|
21
|
+
Utilities.takeAwayResult(exposedErrResults, { no_throw: !!cb, callback: cb});
|
|
22
|
+
|
|
23
|
+
return this.connection
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
query<T = any>(sql: string, cb?: FxOrmCommon.GenericCallback<T>) {
|
|
27
|
+
const exposedErrResults = Utilities.catchBlocking(
|
|
28
|
+
() => this.execute(sql)
|
|
29
|
+
)
|
|
30
|
+
|
|
31
|
+
Utilities.takeAwayResult(exposedErrResults, { no_throw: !!cb, callback: cb});
|
|
32
|
+
|
|
33
|
+
return exposedErrResults.result;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { createRequire } from 'node:module';
|
|
2
|
+
const require = createRequire(import.meta.url);
|
|
3
|
+
import { Driver as FxDbDriver } from '../../../db-driver/index';
|
|
4
|
+
|
|
5
|
+
import getEventEmitter from './base';
|
|
6
|
+
|
|
7
|
+
import * as Utilities from '../../Utilities';
|
|
8
|
+
|
|
9
|
+
import type { FxOrmCommon } from '../../Typo/_common';
|
|
10
|
+
import type { FxOrmDb } from '../../Typo/Db';
|
|
11
|
+
|
|
12
|
+
const Driver = FxDbDriver.getDriver('postgresql');
|
|
13
|
+
|
|
14
|
+
export default class PostgresqlDatabase extends Driver implements FxOrmDb.Database<Class_DbConnection> {
|
|
15
|
+
eventor: Class_EventEmitter = getEventEmitter();
|
|
16
|
+
|
|
17
|
+
connect(cb?: FxOrmCommon.GenericCallback<Class_DbConnection>) {
|
|
18
|
+
const exposedErrResults = Utilities.catchBlocking(
|
|
19
|
+
() => super.open()
|
|
20
|
+
)
|
|
21
|
+
Utilities.takeAwayResult(exposedErrResults, { no_throw: !!cb, callback: cb});
|
|
22
|
+
|
|
23
|
+
return this.connection
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
query<T = any>(sql: string, cb?: FxOrmCommon.GenericCallback<T>) {
|
|
27
|
+
const exposedErrResults = Utilities.catchBlocking(
|
|
28
|
+
() => this.execute(sql)
|
|
29
|
+
)
|
|
30
|
+
|
|
31
|
+
Utilities.takeAwayResult(exposedErrResults, { no_throw: !!cb, callback: cb});
|
|
32
|
+
|
|
33
|
+
return exposedErrResults.result;
|
|
34
|
+
}
|
|
35
|
+
}
|