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,127 @@
|
|
|
1
|
+
import { createRequire } from 'node:module';
|
|
2
|
+
const require = createRequire(import.meta.url);
|
|
3
|
+
|
|
4
|
+
const Enforce = require("@fibjs/enforce");
|
|
5
|
+
const util = require("util");
|
|
6
|
+
import type { FxOrmInstance } from "./Typo/instance";
|
|
7
|
+
|
|
8
|
+
export const required : FibjsEnforce.enforcementValidation = Enforce.required
|
|
9
|
+
export const notEmptyString : FibjsEnforce.enforcementValidation = Enforce.notEmptyString
|
|
10
|
+
|
|
11
|
+
export const rangeNumber : FibjsEnforce.enforcementValidation = Enforce.ranges.number
|
|
12
|
+
export const rangeLength : FibjsEnforce.enforcementValidation = Enforce.ranges.length
|
|
13
|
+
|
|
14
|
+
export const insideList : FibjsEnforce.enforcementValidation = Enforce.lists.inside
|
|
15
|
+
export const outsideList : FibjsEnforce.enforcementValidation = Enforce.lists.outside
|
|
16
|
+
|
|
17
|
+
export const password : FibjsEnforce.enforcementValidation = Enforce.security.password
|
|
18
|
+
|
|
19
|
+
export const patterns : FibjsEnforce.enforcementsContainer = Enforce.patterns
|
|
20
|
+
|
|
21
|
+
import type { FxOrmModel } from './Typo/model';
|
|
22
|
+
import type { FxOrmQuery } from "./Typo/query";
|
|
23
|
+
import type { FxOrmValidators } from "./Typo/Validators";
|
|
24
|
+
import type { FxOrmCommon } from "./Typo/_common";
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Check if a value is the same as a value
|
|
28
|
+
* of another property (useful for password
|
|
29
|
+
* checking).
|
|
30
|
+
**/
|
|
31
|
+
export function equalToProperty (name: string, msg?: string): FibjsEnforce.ValidationCallback {
|
|
32
|
+
return function (this: any, v, next) {
|
|
33
|
+
if (v === this[name]) {
|
|
34
|
+
return next();
|
|
35
|
+
}
|
|
36
|
+
return next(msg || 'not-equal-to-property');
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Check if a property is unique in the collection.
|
|
42
|
+
* This can take a while because a query has to be made against the Model.
|
|
43
|
+
*
|
|
44
|
+
* Due to the async nature of node, and concurrent web server environments,
|
|
45
|
+
* an index on the database column is the only way to gurantee uniqueness.
|
|
46
|
+
*
|
|
47
|
+
* For sensibility's sake, undefined and null values are ignored for uniqueness
|
|
48
|
+
* checks.
|
|
49
|
+
*
|
|
50
|
+
* Options:
|
|
51
|
+
* ignoreCase: for postgres; mysql ignores case by default.
|
|
52
|
+
* scope: (Array) scope uniqueness to listed properties
|
|
53
|
+
**/
|
|
54
|
+
export function unique (
|
|
55
|
+
opts: {
|
|
56
|
+
ignoreCase?: boolean,
|
|
57
|
+
scope?: string[]
|
|
58
|
+
} = {},
|
|
59
|
+
msg: string | null = null
|
|
60
|
+
): FxOrmValidators.ValidationCallback {
|
|
61
|
+
for (let k in arguments) {
|
|
62
|
+
const arg = arguments[k];
|
|
63
|
+
if (typeof arg === "string") {
|
|
64
|
+
msg = arg;
|
|
65
|
+
} else if (typeof arg === "object") {
|
|
66
|
+
opts = arg;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
return function (this: any, v: any, next: FxOrmCommon.NextCallback, ctx: FxOrmValidators.ValidatorContext) {
|
|
71
|
+
if (typeof v === "undefined" || v === null) {
|
|
72
|
+
return next();
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// Cannot process on database engines which don't support SQL syntax
|
|
76
|
+
if (!ctx.driver.isSql) {
|
|
77
|
+
return next('not-supported');
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
var chain: FxOrmQuery.IChainFind = ctx.model.find();
|
|
81
|
+
|
|
82
|
+
var chainQuery = function (prop: string, value: any) {
|
|
83
|
+
var query: string | FxOrmQuery.QueryConditions__Find | null = null;
|
|
84
|
+
|
|
85
|
+
if (opts.ignoreCase === true && ctx.model.properties[prop] && ctx.model.properties[prop].type === 'text') {
|
|
86
|
+
query = util.format('LOWER(%s.%s) LIKE LOWER(?)',
|
|
87
|
+
ctx.driver.query.escapeId(ctx.model.table), ctx.driver.query.escapeId(prop)
|
|
88
|
+
);
|
|
89
|
+
chain.where(query as any, [value]);
|
|
90
|
+
} else {
|
|
91
|
+
query = {};
|
|
92
|
+
query[prop] = value;
|
|
93
|
+
chain.where(query!);
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
var handler = function (this: any, err: Error, records: FxOrmInstance.Instance) {
|
|
98
|
+
if (err) {
|
|
99
|
+
return next();
|
|
100
|
+
}
|
|
101
|
+
if (!records || records.length === 0) {
|
|
102
|
+
return next();
|
|
103
|
+
}
|
|
104
|
+
if (records.length === 1 && records[0][ctx.model.id + ''] === this[ctx.model.id + '']) {
|
|
105
|
+
return next();
|
|
106
|
+
}
|
|
107
|
+
return next(msg || 'not-unique');
|
|
108
|
+
}.bind(this);
|
|
109
|
+
|
|
110
|
+
chainQuery(ctx.property!, v);
|
|
111
|
+
|
|
112
|
+
if (opts.scope) {
|
|
113
|
+
for (let s in opts.scope) {
|
|
114
|
+
let scopeProp = opts.scope[s];
|
|
115
|
+
|
|
116
|
+
// In SQL unique index land, NULL values are not considered equal.
|
|
117
|
+
if (ctx.instance[scopeProp] === undefined || ctx.instance[scopeProp] === null) {
|
|
118
|
+
return next();
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
chainQuery(scopeProp, ctx.instance[scopeProp]);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
chain.all(handler);
|
|
126
|
+
};
|
|
127
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
FxSqlQuerySubQuery,
|
|
3
|
+
} from '../../sql-query/Query';
|
|
4
|
+
|
|
5
|
+
const model_conjunctions_keys: (keyof FxSqlQuerySubQuery.ConjunctionInput__Sample)[] = [ 'or', 'and', 'not_or', 'not_and', 'not' ];
|
|
6
|
+
export function isModelConjunctionsKey (k: string) {
|
|
7
|
+
return model_conjunctions_keys.includes(k as any)
|
|
8
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { createRequire } from 'node:module';
|
|
2
|
+
const require = createRequire(import.meta.url);
|
|
3
|
+
const util = require('util');
|
|
4
|
+
import type {
|
|
5
|
+
FxSqlQuerySql,
|
|
6
|
+
FxSqlQueryComparator,
|
|
7
|
+
} from '../../sql-query/Query';
|
|
8
|
+
import type { FxOrmInstance } from '../Typo/instance';
|
|
9
|
+
import type { FxOrmModel } from '../Typo/model';
|
|
10
|
+
import { isModelConjunctionsKey } from './common';
|
|
11
|
+
|
|
12
|
+
function isNumbericDate(v: any) {
|
|
13
|
+
if (isNaN(v)) return false;
|
|
14
|
+
if (typeof v === 'number') return true;
|
|
15
|
+
if (typeof v === 'string') {
|
|
16
|
+
return !isNaN(parseInt(v))
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const whereCondKeys = ['val', 'from', 'to'] as (keyof FxSqlQuerySql.DetailedQueryWhereCondition)[];
|
|
23
|
+
const queryComparators = ['eq', 'ne', 'gt', 'gte', 'lt', 'lte'] as (FxSqlQueryComparator.ComparatorNameType)[];
|
|
24
|
+
const ALL_FILTER_KEYS: (
|
|
25
|
+
keyof FxSqlQuerySql.DetailedQueryWhereCondition
|
|
26
|
+
| FxSqlQueryComparator.ComparatorNameType
|
|
27
|
+
)[] = ([] as any[]).concat(whereCondKeys).concat(queryComparators);
|
|
28
|
+
/**
|
|
29
|
+
* filter the Date-Type SelectQuery Property corresponding item when call find-like executor ('find', 'get', 'where')
|
|
30
|
+
* @TODO add test about i
|
|
31
|
+
*
|
|
32
|
+
* @param conds
|
|
33
|
+
*/
|
|
34
|
+
// value | FxSqlQueryComparator.ComparatorNameType
|
|
35
|
+
export function filterDate(
|
|
36
|
+
conds: FxOrmInstance.InstanceDataPayload,
|
|
37
|
+
m: {
|
|
38
|
+
properties: FxOrmModel.Model['allProperties']
|
|
39
|
+
}
|
|
40
|
+
) {
|
|
41
|
+
if (typeof conds !== 'object') {
|
|
42
|
+
return ;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
for (let k in conds) {
|
|
46
|
+
if (isModelConjunctionsKey(k))
|
|
47
|
+
Array.isArray(conds[k]) && conds[k].forEach((item: any) => filterDate(item, m));
|
|
48
|
+
else {
|
|
49
|
+
let p = m.properties[k];
|
|
50
|
+
if (p && p.type === 'date') {
|
|
51
|
+
let v: any = conds[k];
|
|
52
|
+
|
|
53
|
+
if (!util.isDate(v)) {
|
|
54
|
+
if (util.isNumber(v) || util.isString(v))
|
|
55
|
+
conds[k] = new Date(isNumbericDate(v) ? parseInt(v) : v);
|
|
56
|
+
else if (util.isObject(v)) {
|
|
57
|
+
ALL_FILTER_KEYS.forEach(c => {
|
|
58
|
+
let v1 = v[c];
|
|
59
|
+
|
|
60
|
+
if (Array.isArray(v1)) {
|
|
61
|
+
v1.forEach((v2: any, i) => {
|
|
62
|
+
if (!util.isDate(v2))
|
|
63
|
+
v1[i] = new Date(v2);
|
|
64
|
+
});
|
|
65
|
+
} else if (v1 !== undefined && !util.isDate(v1)) {
|
|
66
|
+
v[c] = new Date(isNumbericDate(v1) ? parseInt(v1) : v1);
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Deep clone values used by properties and settings.
|
|
3
|
+
*
|
|
4
|
+
* fibjs' `util.clone` only clones one level, while lodash.clonedeep (which was
|
|
5
|
+
* previously used here) preserved nested objects, arrays, dates, buffers and
|
|
6
|
+
* circular references. This helper keeps those semantics without an external
|
|
7
|
+
* dependency.
|
|
8
|
+
*/
|
|
9
|
+
export default function cloneDeep<T> (value: T, seen: WeakMap<object, any> = new WeakMap()): T {
|
|
10
|
+
if (value === null || typeof value !== 'object')
|
|
11
|
+
return value;
|
|
12
|
+
|
|
13
|
+
if (value instanceof Date)
|
|
14
|
+
return new Date(value.getTime()) as any;
|
|
15
|
+
|
|
16
|
+
if (typeof Buffer !== 'undefined' && Buffer.isBuffer(value))
|
|
17
|
+
return Buffer.from(value as any) as any;
|
|
18
|
+
|
|
19
|
+
if (value instanceof RegExp) {
|
|
20
|
+
const clone = new RegExp(value.source, value.flags);
|
|
21
|
+
clone.lastIndex = value.lastIndex;
|
|
22
|
+
return clone as any;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
if (seen.has(value as object))
|
|
26
|
+
return seen.get(value as object);
|
|
27
|
+
|
|
28
|
+
if (Array.isArray(value)) {
|
|
29
|
+
const clone: any[] = [];
|
|
30
|
+
seen.set(value, clone);
|
|
31
|
+
|
|
32
|
+
for (let i = 0; i < value.length; i++)
|
|
33
|
+
clone[i] = cloneDeep(value[i], seen);
|
|
34
|
+
|
|
35
|
+
return clone as any;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const clone = Object.create(Object.getPrototypeOf(value));
|
|
39
|
+
seen.set(value as object, clone);
|
|
40
|
+
|
|
41
|
+
for (const key of Object.keys(value as object))
|
|
42
|
+
clone[key] = cloneDeep((value as any)[key], seen);
|
|
43
|
+
|
|
44
|
+
return clone;
|
|
45
|
+
}
|
package/src/orm/index.ts
ADDED
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
import { createRequire } from 'node:module';
|
|
2
|
+
const require = createRequire(import.meta.url);
|
|
3
|
+
const events = require("events");
|
|
4
|
+
|
|
5
|
+
import type { FxDbDriverNS, IDbDriver } from "../db-driver/index";
|
|
6
|
+
import * as SqlQuery from '../sql-query/Query';
|
|
7
|
+
const Enforces = require("@fibjs/enforce");
|
|
8
|
+
|
|
9
|
+
import type { FxOrmCoreCallbackNS } from "../orm-core/index";
|
|
10
|
+
import type { FxOrmDb } from "./Typo/Db";
|
|
11
|
+
import type { FxOrmNS } from "./Typo/ORM";
|
|
12
|
+
import type { FxOrmError } from "./Typo/Error";
|
|
13
|
+
|
|
14
|
+
import * as Utilities from "./Utilities";
|
|
15
|
+
import * as Settings from "./Settings";
|
|
16
|
+
import { addAdapter, getAdapter } from "./Adapters";
|
|
17
|
+
import ORMError from "./Error";
|
|
18
|
+
import * as validators from "./Validators";
|
|
19
|
+
import * as Helpers from "./Helpers";
|
|
20
|
+
import * as singleton from "./Singleton";
|
|
21
|
+
import { ORM } from './ORM';
|
|
22
|
+
|
|
23
|
+
import * as Property from "./Property";
|
|
24
|
+
export { Property };
|
|
25
|
+
|
|
26
|
+
import './Patch/fib-cache';
|
|
27
|
+
|
|
28
|
+
function isOrmLikeErrorEmitter(parsedDBDriver: IDbDriver | FxOrmNS.ORMLike): parsedDBDriver is FxOrmNS.ORMLike {
|
|
29
|
+
return !parsedDBDriver.hasOwnProperty('host') && parsedDBDriver instanceof events.EventEmitter
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function connectSync(opts?: string | FxDbDriverNS.DBConnectionConfig): ORM {
|
|
33
|
+
Helpers.selectArgs(arguments, function (type, arg) {
|
|
34
|
+
switch (type) {
|
|
35
|
+
default:
|
|
36
|
+
opts = arg;
|
|
37
|
+
break
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
const dbdriver = Helpers.buildDbDriver(opts!);
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* @pointless
|
|
45
|
+
*/
|
|
46
|
+
if (isOrmLikeErrorEmitter(dbdriver)) {
|
|
47
|
+
const errWaitor = Utilities.getErrWaitor(true);
|
|
48
|
+
dbdriver.on('connect', (err: FxOrmError.ExtendedError) => {
|
|
49
|
+
errWaitor.err = err;
|
|
50
|
+
errWaitor.evt!.set();
|
|
51
|
+
});
|
|
52
|
+
errWaitor.evt!.wait();
|
|
53
|
+
|
|
54
|
+
if (errWaitor.err)
|
|
55
|
+
throw errWaitor.err;
|
|
56
|
+
|
|
57
|
+
return dbdriver as unknown as ORM;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
let adapterName = dbdriver.config.protocol!.replace(/:$/, '');
|
|
61
|
+
let orm: ORM | undefined;
|
|
62
|
+
|
|
63
|
+
const syncResult = Utilities.catchBlocking(() => {
|
|
64
|
+
const DMLDriver = getAdapter(adapterName);
|
|
65
|
+
const settings = Settings.Container(Settings.defaultSettingsInstance.get('*'));
|
|
66
|
+
const driver = new DMLDriver(dbdriver.uri as any, null as any, {
|
|
67
|
+
debug: dbdriver.extend_config.debug ? dbdriver.extend_config.debug : settings.get("connection.debug"),
|
|
68
|
+
settings: settings
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
driver.connect();
|
|
72
|
+
|
|
73
|
+
orm = new ORM(adapterName, driver, settings);
|
|
74
|
+
|
|
75
|
+
return orm;
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
if (syncResult.error && Utilities.isDriverNotSupportedError(syncResult.error)) {
|
|
79
|
+
syncResult.error = new ORMError("Connection protocol not supported - have you installed the database driver for " + adapterName + "?", 'NO_SUPPORT');
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
Utilities.takeAwayResult(syncResult, { no_throw: false });
|
|
83
|
+
|
|
84
|
+
return orm!;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export function connect<T extends IDbDriver.ISQLConn = any>(
|
|
88
|
+
uri?: string | FxDbDriverNS.DBConnectionConfig,
|
|
89
|
+
cb?: FxOrmCoreCallbackNS.ExecutionCallback<ORM>
|
|
90
|
+
): ORM {
|
|
91
|
+
let args = Array.prototype.slice.apply(arguments);
|
|
92
|
+
Helpers.selectArgs(args, function (type, arg) {
|
|
93
|
+
switch (type) {
|
|
94
|
+
case 'function':
|
|
95
|
+
cb = arg;
|
|
96
|
+
break
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
args = args.filter((x: any) => x !== cb);
|
|
100
|
+
|
|
101
|
+
const syncResponse = Utilities.catchBlocking<ORM>(connectSync, args);
|
|
102
|
+
|
|
103
|
+
let orm: ORM | undefined;
|
|
104
|
+
if (syncResponse.error)
|
|
105
|
+
orm = Utilities.ORM_Error(syncResponse.error, cb) as ORM;
|
|
106
|
+
else
|
|
107
|
+
orm = syncResponse.result as ORM;
|
|
108
|
+
|
|
109
|
+
Utilities.takeAwayResult(syncResponse, {
|
|
110
|
+
// no throw it, it could be processed with event handler
|
|
111
|
+
no_throw: true,
|
|
112
|
+
callback: cb
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
process.nextTick(() => {
|
|
116
|
+
orm.emit("connect", syncResponse.error, !syncResponse.error ? orm : null);
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
return orm;
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
export { ORM } from './ORM';
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* @description just re-export from @fibjs/enforce for convenience, you can also use `orm.enforce` for orm instances
|
|
126
|
+
*/
|
|
127
|
+
export const enforce = Enforces;
|
|
128
|
+
|
|
129
|
+
export const settings = Settings.defaultSettingsInstance;
|
|
130
|
+
|
|
131
|
+
export function use(
|
|
132
|
+
connection: FxOrmDb.Database,
|
|
133
|
+
proto: string,
|
|
134
|
+
opts: FxOrmNS.IUseOptions,
|
|
135
|
+
cb: (err: Error | null, db?: FxOrmNS.ORM) => void
|
|
136
|
+
): any {
|
|
137
|
+
if (typeof opts === "function") {
|
|
138
|
+
cb = opts;
|
|
139
|
+
opts = {} as FxOrmNS.IUseOptions;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
try {
|
|
143
|
+
const DMLDriver = getAdapter(proto);
|
|
144
|
+
const settings = Settings.Container(Settings.defaultSettingsInstance.get('*'));
|
|
145
|
+
const driver = new DMLDriver(null as any, connection, {
|
|
146
|
+
debug: (opts.query && opts.query.debug === 'true'),
|
|
147
|
+
settings: settings
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
return cb(null, new ORM(proto, driver, settings) as any);
|
|
151
|
+
} catch (err) {
|
|
152
|
+
return cb(err as Error);
|
|
153
|
+
}
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
export {
|
|
157
|
+
addAdapter,
|
|
158
|
+
Helpers,
|
|
159
|
+
validators,
|
|
160
|
+
Settings,
|
|
161
|
+
singleton,
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
/* @internal */
|
|
165
|
+
export const ErrorCodes = ORMError.codes;
|
|
166
|
+
|
|
167
|
+
export function definePlugin<TOpts extends object>(definition: FxOrmNS.PluginConstructFn<TOpts>) {
|
|
168
|
+
return definition;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
export function defineModel<T = any>(definition: (db: FxOrmNS.ORM) => T): typeof definition {
|
|
172
|
+
return definition;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
export type { FxOrmNS } from './Typo/ORM';
|
|
176
|
+
export type { FxOrmModel } from './Typo/model';
|
|
177
|
+
export type { FxOrmInstance } from './Typo/instance';
|
|
178
|
+
export type { FxOrmAssociation } from './Typo/assoc';
|
|
179
|
+
export type { FxOrmProperty } from './Typo/property';
|
|
180
|
+
export type { FxOrmSettings } from './Typo/settings';
|
|
181
|
+
export type { FxOrmValidators } from './Typo/Validators';
|
|
182
|
+
export type { FxOrmError } from './Typo/Error';
|
|
183
|
+
|
|
184
|
+
/* @internal */
|
|
185
|
+
export type { FxOrmQuery } from './Typo/query';
|
|
186
|
+
/* @internal */
|
|
187
|
+
export type { FxOrmDb } from './Typo/Db';
|
|
188
|
+
/* @internal */
|
|
189
|
+
export type { FxOrmDMLDriver } from './Typo/DMLDriver';
|
|
190
|
+
/* @internal */
|
|
191
|
+
export type { FxOrmHook } from './Typo/hook';
|
|
192
|
+
|
|
193
|
+
// /* @internal */
|
|
194
|
+
// export { FxOrmAdapter } from './Typo/Adapter';
|
|
195
|
+
// /* @internal */
|
|
196
|
+
// export { FxOrmPatch } from './Typo/patch';
|
|
197
|
+
// /* @internal */
|
|
198
|
+
// export { FxOrmSynchronous } from './Typo/synchronous';
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* @deprecated use FxOrmNS.ORM directly
|
|
202
|
+
*/
|
|
203
|
+
export type ORMInstance = FxOrmNS.ORM
|
|
204
|
+
|
|
205
|
+
/** @deprecated use _Query.Text instead */
|
|
206
|
+
export const Text = SqlQuery.Text;
|
|
207
|
+
/** @deprecated use SqlQuery.comparators.between instead */
|
|
208
|
+
export const between = SqlQuery.comparators.between;
|
|
209
|
+
/** @deprecated use SqlQuery.comparators.not_between instead */
|
|
210
|
+
export const not_between = SqlQuery.comparators.not_between;
|
|
211
|
+
/** @deprecated use SqlQuery.comparators.like instead */
|
|
212
|
+
export const like = SqlQuery.comparators.like;
|
|
213
|
+
/** @deprecated use SqlQuery.comparators.not_like instead */
|
|
214
|
+
export const not_like = SqlQuery.comparators.not_like;
|
|
215
|
+
/** @deprecated use SqlQuery.comparators.eq instead */
|
|
216
|
+
export const eq = SqlQuery.comparators.eq;
|
|
217
|
+
/** @deprecated use SqlQuery.comparators.ne instead */
|
|
218
|
+
export const ne = SqlQuery.comparators.ne;
|
|
219
|
+
/** @deprecated use SqlQuery.comparators.gt instead */
|
|
220
|
+
export const gt = SqlQuery.comparators.gt;
|
|
221
|
+
/** @deprecated use SqlQuery.comparators.gte instead */
|
|
222
|
+
export const gte = SqlQuery.comparators.gte;
|
|
223
|
+
/** @deprecated use SqlQuery.comparators.lt instead */
|
|
224
|
+
export const lt = SqlQuery.comparators.lt;
|
|
225
|
+
/** @deprecated use SqlQuery.comparators.lte instead */
|
|
226
|
+
export const lte = SqlQuery.comparators.lte;
|
|
227
|
+
/** @deprecated use SqlQuery.comparators.in instead */
|
|
228
|
+
const _in = SqlQuery.comparators.in;
|
|
229
|
+
export { _in as in };
|
|
230
|
+
/** @deprecated use SqlQuery.comparators.not_in instead */
|
|
231
|
+
export const not_in = SqlQuery.comparators.not_in;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { FxOrmCoreError } from "./error";
|
|
2
|
+
|
|
3
|
+
export namespace FxOrmCoreCallbackNS {
|
|
4
|
+
export interface VoidCallback<T_RESULT = any, T_THIS = any> {
|
|
5
|
+
(this: T_THIS, err?: any): T_RESULT
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export interface ExecutionCallback<T, T_RESULT = any, T_THIS = any> {
|
|
9
|
+
(this: T_THIS, err?: any, result?: T): T_RESULT
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface GenericCallback<T, T_RESULT = any, T_THIS = any> {
|
|
13
|
+
(this: T_THIS, err?: any, result?: T): T_RESULT
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -1,80 +1,103 @@
|
|
|
1
|
-
import { FxOrmCoreCallbackNS } from "./callback"
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import type { FxOrmCoreCallbackNS } from "./callback"
|
|
2
|
+
|
|
3
|
+
export namespace FxOrmDialect {
|
|
4
|
+
export type EscapeArgType = string | number | boolean | Date | String | Number | RegExp | Symbol
|
|
5
|
+
|
|
6
|
+
// /**
|
|
7
|
+
// * @description QueryDiact is dialct helpers
|
|
8
|
+
// * before/after sending query to database backend
|
|
9
|
+
// */
|
|
10
|
+
// export interface QueryDialect {
|
|
11
|
+
// type: string
|
|
12
|
+
|
|
13
|
+
// escape (query: string, args: any[]): string
|
|
14
|
+
// /**
|
|
15
|
+
// * @description escape string as identifiers in els or `str` in els
|
|
16
|
+
// * @param els
|
|
17
|
+
// */
|
|
18
|
+
// escapeId (...els: (string | number | { str: string, escapes: string[] })[]): string
|
|
19
|
+
// /**
|
|
20
|
+
// * @description escape string-like as value in vals, value format is different for
|
|
21
|
+
// * database backends
|
|
22
|
+
// * @param val
|
|
23
|
+
// */
|
|
24
|
+
// escapeVal (val: EscapeArgType): string
|
|
25
|
+
// }
|
|
26
|
+
|
|
4
27
|
type __AlertTableOptions = {
|
|
5
|
-
comment?: string
|
|
6
|
-
}
|
|
28
|
+
comment?: string
|
|
29
|
+
}
|
|
30
|
+
|
|
7
31
|
/**
|
|
8
32
|
* @description DDLDialect is dialct helpers to interact with database backend,
|
|
9
33
|
* to check if database has some features, get/remove data from it, or update date in it
|
|
10
34
|
*/
|
|
11
|
-
export interface DDLDialect<TDriver extends any> {
|
|
35
|
+
export interface DDLDialect <TDriver extends any> {
|
|
12
36
|
hasCollection: {
|
|
13
|
-
(driver: TDriver, name: string, cb: FxOrmCoreCallbackNS.ExecutionCallback<boolean>): void
|
|
14
|
-
}
|
|
37
|
+
(driver: TDriver, name: string, cb: FxOrmCoreCallbackNS.ExecutionCallback<boolean>): void
|
|
38
|
+
}
|
|
15
39
|
hasCollectionSync: {
|
|
16
|
-
(driver: TDriver, name: string): boolean
|
|
17
|
-
}
|
|
40
|
+
(driver: TDriver, name: string): boolean
|
|
41
|
+
}
|
|
18
42
|
addPrimaryKey: {
|
|
19
|
-
<T extends any = any>(driver: TDriver, tableName: string, columnName: string, cb: FxOrmCoreCallbackNS.ExecutionCallback<T>): void
|
|
20
|
-
}
|
|
43
|
+
<T extends any = any>(driver: TDriver, tableName: string, columnName: string, cb: FxOrmCoreCallbackNS.ExecutionCallback<T>): void
|
|
44
|
+
}
|
|
21
45
|
addPrimaryKeySync: {
|
|
22
|
-
<T extends any = any>(driver: TDriver, tableName: string, columnName: string): T
|
|
23
|
-
}
|
|
46
|
+
<T extends any = any>(driver: TDriver, tableName: string, columnName: string): T
|
|
47
|
+
}
|
|
24
48
|
dropPrimaryKey: {
|
|
25
|
-
<T extends any = any>(driver: TDriver, tableName: string, columnName: string, cb: FxOrmCoreCallbackNS.ExecutionCallback<T>): void
|
|
26
|
-
}
|
|
49
|
+
<T extends any = any>(driver: TDriver, tableName: string, columnName: string, cb: FxOrmCoreCallbackNS.ExecutionCallback<T>): void
|
|
50
|
+
}
|
|
27
51
|
dropPrimaryKeySync: {
|
|
28
|
-
<T extends any = any>(driver: TDriver, tableName: string, columnName: string): T
|
|
29
|
-
}
|
|
52
|
+
<T extends any = any>(driver: TDriver, tableName: string, columnName: string): T
|
|
53
|
+
}
|
|
30
54
|
getCollectionColumns: {
|
|
31
|
-
<T extends any = any>(driver: TDriver, name: string, cb: FxOrmCoreCallbackNS.ExecutionCallback<T[]>): void
|
|
32
|
-
}
|
|
55
|
+
<T extends any = any>(driver: TDriver, name: string, cb: FxOrmCoreCallbackNS.ExecutionCallback<T[]>): void
|
|
56
|
+
}
|
|
33
57
|
getCollectionColumnsSync: {
|
|
34
|
-
<T extends any = any>(driver: TDriver, name: string): T[]
|
|
35
|
-
}
|
|
58
|
+
<T extends any = any>(driver: TDriver, name: string): T[]
|
|
59
|
+
}
|
|
36
60
|
createCollection: {
|
|
37
|
-
<T extends any = any>(driver: TDriver, name: string, columns: string[], keys: string[], opts?: __AlertTableOptions, cb?: FxOrmCoreCallbackNS.ExecutionCallback<T>): void
|
|
38
|
-
}
|
|
61
|
+
<T extends any = any>(driver: TDriver, name: string, columns: string[], keys: string[], opts?: __AlertTableOptions, cb?: FxOrmCoreCallbackNS.ExecutionCallback<T>): void
|
|
62
|
+
}
|
|
39
63
|
createCollectionSync: {
|
|
40
|
-
<T extends any = any>(driver: TDriver, name: string, columns: string[], keys: string[], opts?: __AlertTableOptions): T
|
|
41
|
-
}
|
|
64
|
+
<T extends any = any>(driver: TDriver, name: string, columns: string[], keys: string[], opts?: __AlertTableOptions): T
|
|
65
|
+
}
|
|
42
66
|
dropCollection: {
|
|
43
|
-
<T extends any = any>(driver: TDriver, name: string, cb: FxOrmCoreCallbackNS.ExecutionCallback<T>): void
|
|
44
|
-
}
|
|
67
|
+
<T extends any = any>(driver: TDriver, name: string, cb: FxOrmCoreCallbackNS.ExecutionCallback<T>): void
|
|
68
|
+
}
|
|
45
69
|
dropCollectionSync: {
|
|
46
|
-
<T extends any = any>(driver: TDriver, name: string): T
|
|
47
|
-
}
|
|
70
|
+
<T extends any = any>(driver: TDriver, name: string): T
|
|
71
|
+
}
|
|
48
72
|
hasCollectionColumnsSync: {
|
|
49
|
-
(driver: TDriver, name: string, column: string | string[]): boolean
|
|
50
|
-
}
|
|
73
|
+
(driver: TDriver, name: string, column: string | string[]): boolean
|
|
74
|
+
}
|
|
51
75
|
hasCollectionColumns: {
|
|
52
|
-
(driver: TDriver, name: string, column: string | string[], cb: FxOrmCoreCallbackNS.ExecutionCallback<boolean>): void
|
|
53
|
-
}
|
|
76
|
+
(driver: TDriver, name: string, column: string | string[], cb: FxOrmCoreCallbackNS.ExecutionCallback<boolean>): void
|
|
77
|
+
}
|
|
54
78
|
addCollectionColumn: {
|
|
55
|
-
<T extends any = any>(driver: TDriver, name: string, column: string, after_column: string
|
|
56
|
-
}
|
|
79
|
+
<T extends any = any>(driver: TDriver, name: string, column: string, after_column: string|false, cb: FxOrmCoreCallbackNS.ExecutionCallback<T>): void
|
|
80
|
+
}
|
|
57
81
|
addCollectionColumnSync: {
|
|
58
|
-
<T extends any = any>(driver: TDriver, name: string, column: string, after_column: string
|
|
59
|
-
}
|
|
82
|
+
<T extends any = any>(driver: TDriver, name: string, column: string, after_column: string|false): T
|
|
83
|
+
}
|
|
60
84
|
renameCollectionColumn: {
|
|
61
|
-
<T extends any = any>(driver: TDriver, name: string, oldColName: string, newColName: string, cb: FxOrmCoreCallbackNS.ExecutionCallback<T>): void
|
|
62
|
-
}
|
|
85
|
+
<T extends any = any>(driver: TDriver, name: string, oldColName: string, newColName: string, cb: FxOrmCoreCallbackNS.ExecutionCallback<T>): void
|
|
86
|
+
}
|
|
63
87
|
renameCollectionColumnSync: {
|
|
64
|
-
<T extends any = any>(driver: TDriver, name: string, oldColName: string, newColName: string): T
|
|
65
|
-
}
|
|
88
|
+
<T extends any = any>(driver: TDriver, name: string, oldColName: string, newColName: string): T
|
|
89
|
+
}
|
|
66
90
|
modifyCollectionColumn: {
|
|
67
|
-
<T extends any = any>(driver: TDriver, name: string, column: string, cb: FxOrmCoreCallbackNS.ExecutionCallback<T>): void
|
|
68
|
-
}
|
|
91
|
+
<T extends any = any>(driver: TDriver, name: string, column: string, cb: FxOrmCoreCallbackNS.ExecutionCallback<T>): void
|
|
92
|
+
}
|
|
69
93
|
modifyCollectionColumnSync: {
|
|
70
|
-
<T extends any = any>(driver: TDriver, name: string, column: string): T
|
|
71
|
-
}
|
|
94
|
+
<T extends any = any>(driver: TDriver, name: string, column: string): T
|
|
95
|
+
}
|
|
72
96
|
dropCollectionColumn: {
|
|
73
|
-
<T extends any = any>(driver: TDriver, name: string, column: string, cb: FxOrmCoreCallbackNS.ExecutionCallback<T>): void
|
|
74
|
-
}
|
|
97
|
+
<T extends any = any>(driver: TDriver, name: string, column: string, cb: FxOrmCoreCallbackNS.ExecutionCallback<T>): void
|
|
98
|
+
}
|
|
75
99
|
dropCollectionColumnSync: {
|
|
76
|
-
<T extends any = any>(driver: TDriver, name: string, column: string): T
|
|
77
|
-
}
|
|
100
|
+
<T extends any = any>(driver: TDriver, name: string, column: string): T
|
|
101
|
+
}
|
|
78
102
|
}
|
|
79
|
-
|
|
80
|
-
}
|
|
103
|
+
}
|