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,71 @@
|
|
|
1
|
+
export declare namespace FxOrmCoreError {
|
|
2
|
+
export interface ExtendedError extends Error {
|
|
3
|
+
code?: number | string
|
|
4
|
+
|
|
5
|
+
[ext: string]: any
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
// type ValidateErrorResult = ValidateError | ValidateError[]
|
|
9
|
+
|
|
10
|
+
// interface ErrorWaitor {
|
|
11
|
+
// evt?: Class_Event,
|
|
12
|
+
// err: FxOrmError.ExtendedError
|
|
13
|
+
// }
|
|
14
|
+
|
|
15
|
+
// interface BatchOperationInstanceErrorItem extends ExtendedError {
|
|
16
|
+
// index: number
|
|
17
|
+
// instance: FxOrmInstance.Instance
|
|
18
|
+
// }
|
|
19
|
+
}
|
|
20
|
+
import type { FxOrmCoreCallbackNS } from "./callback";
|
|
21
|
+
import type { FxOrmCoreSyncNS } from "./sync";
|
|
22
|
+
|
|
23
|
+
export function catchBlocking<T = any> (
|
|
24
|
+
executor: (...args: any[]) => any,
|
|
25
|
+
args?: any[],
|
|
26
|
+
opts?: {
|
|
27
|
+
thisArg?: any,
|
|
28
|
+
}
|
|
29
|
+
): FxOrmCoreSyncNS.ExposedResult<T> {
|
|
30
|
+
let error: FxOrmCoreError.ExtendedError | undefined,
|
|
31
|
+
result: T | undefined
|
|
32
|
+
|
|
33
|
+
const { thisArg = null } = opts || {};
|
|
34
|
+
|
|
35
|
+
try {
|
|
36
|
+
result = executor.apply(thisArg, args || []) as T | undefined;
|
|
37
|
+
} catch (ex) {
|
|
38
|
+
error = ex as FxOrmCoreError.ExtendedError
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return { error, result }
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export function takeAwayResult <RESULT_T = any> (
|
|
45
|
+
input: FxOrmCoreSyncNS.ExposedResult<RESULT_T>,
|
|
46
|
+
opts?: {
|
|
47
|
+
callback?: FxOrmCoreCallbackNS.GenericCallback<RESULT_T>,
|
|
48
|
+
use_tick?: boolean
|
|
49
|
+
no_throw?: boolean
|
|
50
|
+
}
|
|
51
|
+
): void {
|
|
52
|
+
const {
|
|
53
|
+
use_tick = false,
|
|
54
|
+
callback = null,
|
|
55
|
+
} = opts || {}
|
|
56
|
+
|
|
57
|
+
const isFunc = typeof callback === 'function';
|
|
58
|
+
|
|
59
|
+
const { no_throw = isFunc } = opts || {};
|
|
60
|
+
|
|
61
|
+
if (!no_throw && input.error)
|
|
62
|
+
throw input.error;
|
|
63
|
+
|
|
64
|
+
if (isFunc)
|
|
65
|
+
if (use_tick)
|
|
66
|
+
process.nextTick(() => {
|
|
67
|
+
callback(input.error || null, input.result);
|
|
68
|
+
});
|
|
69
|
+
else
|
|
70
|
+
callback(input.error || null, input.result);
|
|
71
|
+
}
|
|
@@ -1,6 +1,12 @@
|
|
|
1
|
-
|
|
1
|
+
import * as Utils from './utils';
|
|
2
|
+
export { Utils };
|
|
3
|
+
|
|
2
4
|
export type { FxOrmCoreCallbackNS } from './callback';
|
|
3
5
|
export type { FxOrmCoreSyncNS } from './sync';
|
|
4
6
|
export type { FxOrmCoreError } from './error';
|
|
5
7
|
export type { FxOrmDialect } from './dialect';
|
|
6
|
-
|
|
8
|
+
|
|
9
|
+
export {
|
|
10
|
+
catchBlocking,
|
|
11
|
+
takeAwayResult,
|
|
12
|
+
} from './error';
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { FxOrmCoreCallbackNS } from "./callback";
|
|
2
|
+
import type { FxOrmCoreError } from "./error";
|
|
3
|
+
|
|
4
|
+
export namespace FxOrmCoreSyncNS {
|
|
5
|
+
export interface ExposedResult<T = any> {
|
|
6
|
+
error?: FxOrmCoreError.ExtendedError,
|
|
7
|
+
result?: T
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export interface SyncCallbackInputArags<T = any> {
|
|
11
|
+
callback?: FxOrmCoreCallbackNS.ExecutionCallback<T>,
|
|
12
|
+
is_sync?: boolean
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
export type __StringType<ENUM_T = string> = string | ENUM_T
|
|
2
|
+
export type ColumnType = __StringType
|
|
3
|
+
|
|
4
|
+
export interface IProperty {
|
|
5
|
+
type: __StringType<PropertyType>
|
|
6
|
+
|
|
7
|
+
key?: boolean
|
|
8
|
+
mapsTo?: string
|
|
9
|
+
|
|
10
|
+
unique?: boolean | string | string[]
|
|
11
|
+
index?: boolean | string | string[]
|
|
12
|
+
|
|
13
|
+
/* extra option :start */
|
|
14
|
+
serial?: boolean
|
|
15
|
+
unsigned?: boolean
|
|
16
|
+
primary?: boolean
|
|
17
|
+
required?: boolean
|
|
18
|
+
defaultValue?: ((ctx?: ITransformCtx) => any) | any
|
|
19
|
+
size?: number | string
|
|
20
|
+
rational?: boolean // whether float type
|
|
21
|
+
time?: boolean
|
|
22
|
+
big?: boolean
|
|
23
|
+
values?: any[] // values for enum type
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* @description for some db backends, comment is the description of the column
|
|
27
|
+
*/
|
|
28
|
+
comment?: string
|
|
29
|
+
|
|
30
|
+
[ext_k: string]: any
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* @description
|
|
35
|
+
* all standard property types should be supported by transformer
|
|
36
|
+
*/
|
|
37
|
+
export type PropertyType =
|
|
38
|
+
'text'
|
|
39
|
+
| 'integer'
|
|
40
|
+
| 'number'
|
|
41
|
+
| 'serial'
|
|
42
|
+
| 'boolean'
|
|
43
|
+
| 'date'
|
|
44
|
+
| 'binary'
|
|
45
|
+
| 'object'
|
|
46
|
+
| 'enum'
|
|
47
|
+
| 'point'
|
|
48
|
+
|
|
49
|
+
export type ICustomPropertyType = {
|
|
50
|
+
datastoreType(
|
|
51
|
+
prop: IProperty,
|
|
52
|
+
ctx: ITransformCtx
|
|
53
|
+
): string
|
|
54
|
+
// valueToProperty(value?: any, prop?: IProperty): any
|
|
55
|
+
// propertyToValue(prop?: IProperty): any
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export type ITransformCtx = {
|
|
59
|
+
/**
|
|
60
|
+
* @description database's type
|
|
61
|
+
*/
|
|
62
|
+
type?: string
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* @description database's version
|
|
66
|
+
*/
|
|
67
|
+
version?: string
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* @description collection name
|
|
71
|
+
*/
|
|
72
|
+
collection?: string
|
|
73
|
+
|
|
74
|
+
userOptions?: Record<string, any>
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export interface IPropTransformer<TCol extends object> {
|
|
78
|
+
/**
|
|
79
|
+
* @description filter column information, some input data would be dirty.
|
|
80
|
+
*
|
|
81
|
+
* e.g. the type of field in TCol is Class_Buffer, we need to convert it to string.
|
|
82
|
+
*
|
|
83
|
+
*/
|
|
84
|
+
filterRawColumns?(column: TCol): TCol
|
|
85
|
+
/**
|
|
86
|
+
* @description transform database's type raw information to property
|
|
87
|
+
*/
|
|
88
|
+
rawToProperty(column: TCol, ctx?: ITransformCtx): {
|
|
89
|
+
raw: TCol,
|
|
90
|
+
property: IProperty,
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* @description transform property to database's type
|
|
95
|
+
*/
|
|
96
|
+
toStorageType(property: IProperty, ctx: ITransformCtx & {
|
|
97
|
+
/**
|
|
98
|
+
* @description custom types
|
|
99
|
+
*/
|
|
100
|
+
customTypes?: Record<string, ICustomPropertyType>
|
|
101
|
+
|
|
102
|
+
escapeVal(val: any): string
|
|
103
|
+
}): {
|
|
104
|
+
isCustom: boolean
|
|
105
|
+
property: IProperty
|
|
106
|
+
typeValue: string
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export type ExtractColumnInfo<T extends any> = T extends IPropTransformer<infer U> ? U : never
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { IProperty, ITransformCtx } from "./Property"
|
|
2
|
+
|
|
3
|
+
export function filterPropertyDefaultValue (
|
|
4
|
+
property: IProperty,
|
|
5
|
+
ctx: ITransformCtx
|
|
6
|
+
) {
|
|
7
|
+
let _dftValue
|
|
8
|
+
if (property.hasOwnProperty('defaultValue'))
|
|
9
|
+
if (typeof property.defaultValue === 'function') {
|
|
10
|
+
_dftValue = property.defaultValue(ctx)
|
|
11
|
+
} else
|
|
12
|
+
_dftValue = property.defaultValue
|
|
13
|
+
|
|
14
|
+
return _dftValue
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export const COLUMN_NUMER_TYPE_IDX = {
|
|
18
|
+
SHORT: 2,
|
|
19
|
+
INTEGER: 4,
|
|
20
|
+
LONG: 8,
|
|
21
|
+
|
|
22
|
+
FLOAT: 4,
|
|
23
|
+
DOUBLE: 8,
|
|
24
|
+
} as const;
|
|
25
|
+
|
|
26
|
+
export type COLUMN_NUMER_TYPE_IDX = typeof COLUMN_NUMER_TYPE_IDX[keyof typeof COLUMN_NUMER_TYPE_IDX];
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { ICustomPropertyType } from "./Property";
|
|
2
|
+
|
|
3
|
+
const DEFAULT_DATASTORE_TYPE: ICustomPropertyType['datastoreType'] = function (prop, ctx) {
|
|
4
|
+
return prop.type.toUpperCase();
|
|
5
|
+
};
|
|
6
|
+
export function defineCustomType (opts: Partial<ICustomPropertyType>): ICustomPropertyType {
|
|
7
|
+
opts = {...opts}
|
|
8
|
+
if (typeof opts.datastoreType !== 'function') {
|
|
9
|
+
opts.datastoreType = DEFAULT_DATASTORE_TYPE.bind(null)
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
return opts as ICustomPropertyType
|
|
13
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import * as Transformers from './transformers';
|
|
2
|
+
|
|
3
|
+
export { Transformers };
|
|
4
|
+
|
|
5
|
+
export type { IProperty } from './Property';
|
|
6
|
+
|
|
7
|
+
export function transformer(type: 'mysql'): typeof Transformers['mysql']
|
|
8
|
+
export function transformer(type: 'psql'): typeof Transformers['postgresql']
|
|
9
|
+
export function transformer(type: 'postgresql'): typeof Transformers['postgresql']
|
|
10
|
+
export function transformer(type: 'sqlite'): typeof Transformers['sqlite']
|
|
11
|
+
export function transformer(type: 'dm'): typeof Transformers['dm']
|
|
12
|
+
export function transformer(type: 'mssql'): typeof Transformers['mssql']
|
|
13
|
+
export function transformer(type: string) {
|
|
14
|
+
switch (type) {
|
|
15
|
+
case 'psql':
|
|
16
|
+
case 'postgres':
|
|
17
|
+
return Transformers['postgresql'];
|
|
18
|
+
case 'dm':
|
|
19
|
+
return Transformers['dm'];
|
|
20
|
+
case 'mssql':
|
|
21
|
+
return Transformers['mssql'];
|
|
22
|
+
case 'postgresql':
|
|
23
|
+
case 'mysql':
|
|
24
|
+
case 'sqlite':
|
|
25
|
+
return Transformers[type];
|
|
26
|
+
default:
|
|
27
|
+
throw new Error('Unknown database type');
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export { defineCustomType } from './customTypes';
|
|
32
|
+
|
|
33
|
+
// TODO: add type test for it
|
|
34
|
+
export type { ExtractColumnInfo } from './Property';
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { IPropTransformer } from "./Property";
|
|
2
|
+
|
|
3
|
+
export function defineTransformer<T extends object>(opts: {
|
|
4
|
+
rawToProperty: IPropTransformer<T>['rawToProperty']
|
|
5
|
+
toStorageType: IPropTransformer<T>['toStorageType']
|
|
6
|
+
}): IPropTransformer<T> {
|
|
7
|
+
const {
|
|
8
|
+
rawToProperty,
|
|
9
|
+
toStorageType,
|
|
10
|
+
} = opts;
|
|
11
|
+
|
|
12
|
+
return {
|
|
13
|
+
rawToProperty,
|
|
14
|
+
toStorageType,
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -1,61 +1,108 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import type { IPropTransformer, IProperty, PropertyType, __StringType } from "../Property"
|
|
2
|
+
import { COLUMN_NUMER_TYPE_IDX, filterPropertyDefaultValue } from "../Utils"
|
|
3
|
+
|
|
4
|
+
export type ColumnType_DM = PropertyType
|
|
5
|
+
|
|
6
|
+
export interface ColumnInfoDM {
|
|
7
|
+
COLUMN_NAME?: string
|
|
8
|
+
DATA_TYPE?: string
|
|
9
|
+
DATA_LENGTH?: number | string
|
|
10
|
+
DATA_PRECISION?: number | string
|
|
11
|
+
DATA_SCALE?: number | string
|
|
12
|
+
NULLABLE?: __StringType<'Y' | 'N' | 'YES' | 'NO'>
|
|
13
|
+
DATA_DEFAULT?: any
|
|
14
|
+
CHAR_LENGTH?: number | string
|
|
15
|
+
IDENTITY_COLUMN?: __StringType<'YES' | 'NO' | 'Y' | 'N'>
|
|
16
|
+
IS_IDENTITY?: __StringType<'YES' | 'NO' | 'Y' | 'N'>
|
|
17
|
+
COMMENT?: string
|
|
18
|
+
|
|
19
|
+
column_name?: string
|
|
20
|
+
data_type?: string
|
|
21
|
+
data_length?: number | string
|
|
22
|
+
data_precision?: number | string
|
|
23
|
+
data_scale?: number | string
|
|
24
|
+
nullable?: __StringType<'Y' | 'N' | 'YES' | 'NO'>
|
|
25
|
+
data_default?: any
|
|
26
|
+
char_length?: number | string
|
|
27
|
+
identity_column?: __StringType<'YES' | 'NO' | 'Y' | 'N'>
|
|
28
|
+
is_identity?: __StringType<'YES' | 'NO' | 'Y' | 'N'>
|
|
29
|
+
comment?: string
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
type DB_INTEGER = number;
|
|
33
|
+
|
|
34
|
+
type DB_TEXT = string;
|
|
35
|
+
|
|
36
|
+
type DB_VARCHAR<T extends number = 255> = string;
|
|
37
|
+
|
|
4
38
|
const columnSizes = {
|
|
5
39
|
integer: {
|
|
6
|
-
[
|
|
7
|
-
[
|
|
8
|
-
[
|
|
40
|
+
[COLUMN_NUMER_TYPE_IDX.SHORT]: 'SMALLINT',
|
|
41
|
+
[COLUMN_NUMER_TYPE_IDX.INTEGER]: 'INTEGER',
|
|
42
|
+
[COLUMN_NUMER_TYPE_IDX.LONG]: 'BIGINT'
|
|
9
43
|
},
|
|
10
44
|
floating: {
|
|
11
|
-
[
|
|
12
|
-
[
|
|
45
|
+
[COLUMN_NUMER_TYPE_IDX.FLOAT]: 'FLOAT',
|
|
46
|
+
[COLUMN_NUMER_TYPE_IDX.DOUBLE]: 'DOUBLE'
|
|
13
47
|
}
|
|
14
48
|
};
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
49
|
+
|
|
50
|
+
function normalizeColInfo(colInfo: ColumnInfoDM): ColumnInfoDM {
|
|
51
|
+
const toStringOrEmpty = (value: unknown) => value ? value.toString() : '';
|
|
52
|
+
const raw = colInfo as ColumnInfoDM & Record<string, unknown>;
|
|
53
|
+
const defaultValue = colInfo.DATA_DEFAULT ?? colInfo.data_default;
|
|
54
|
+
|
|
55
|
+
return {
|
|
56
|
+
COLUMN_NAME: toStringOrEmpty(colInfo.COLUMN_NAME ?? colInfo.column_name),
|
|
57
|
+
DATA_TYPE: toStringOrEmpty(colInfo.DATA_TYPE ?? colInfo.data_type),
|
|
58
|
+
DATA_LENGTH: toStringOrEmpty(colInfo.DATA_LENGTH ?? colInfo.data_length),
|
|
59
|
+
DATA_PRECISION: toStringOrEmpty(
|
|
60
|
+
colInfo.DATA_PRECISION ?? colInfo.data_precision
|
|
61
|
+
),
|
|
62
|
+
DATA_SCALE: toStringOrEmpty(colInfo.DATA_SCALE ?? colInfo.data_scale),
|
|
63
|
+
NULLABLE: toStringOrEmpty(
|
|
64
|
+
colInfo.NULLABLE ?? colInfo.nullable
|
|
65
|
+
) as ColumnInfoDM['NULLABLE'],
|
|
66
|
+
DATA_DEFAULT: defaultValue !== undefined && defaultValue !== null
|
|
67
|
+
? defaultValue.toString()
|
|
68
|
+
: defaultValue,
|
|
69
|
+
CHAR_LENGTH: toStringOrEmpty(colInfo.CHAR_LENGTH ?? colInfo.char_length),
|
|
70
|
+
IDENTITY_COLUMN: toStringOrEmpty(
|
|
71
|
+
colInfo.IDENTITY_COLUMN ??
|
|
72
|
+
colInfo.identity_column ??
|
|
73
|
+
colInfo.IS_IDENTITY ??
|
|
74
|
+
colInfo.is_identity
|
|
75
|
+
) as ColumnInfoDM['IDENTITY_COLUMN'],
|
|
76
|
+
COMMENT: toStringOrEmpty(
|
|
77
|
+
colInfo.COMMENT ?? colInfo.comment ?? raw.COMMENTS ?? raw.comments
|
|
78
|
+
),
|
|
79
|
+
};
|
|
39
80
|
}
|
|
40
|
-
|
|
81
|
+
|
|
82
|
+
function isIdentityColumn(colInfo: ColumnInfoDM) {
|
|
41
83
|
const v = colInfo.IDENTITY_COLUMN ? colInfo.IDENTITY_COLUMN.toString().toUpperCase() : '';
|
|
42
84
|
return v === 'YES' || v === 'Y' || v === 'TRUE' || v === '1';
|
|
43
85
|
}
|
|
44
|
-
|
|
45
|
-
|
|
86
|
+
|
|
87
|
+
function colInfoToProperty(colInfo: ColumnInfoDM) {
|
|
88
|
+
const property = {} as IProperty;
|
|
46
89
|
const col = normalizeColInfo(colInfo);
|
|
47
|
-
|
|
90
|
+
|
|
91
|
+
const type = col.DATA_TYPE!.toUpperCase();
|
|
92
|
+
|
|
48
93
|
if (isIdentityColumn(col)) {
|
|
49
94
|
property.serial = true;
|
|
50
95
|
property.key = true;
|
|
51
96
|
property.primary = true;
|
|
52
97
|
}
|
|
98
|
+
|
|
53
99
|
if (col.NULLABLE && (col.NULLABLE.toUpperCase() === 'N' || col.NULLABLE.toUpperCase() === 'NO')) {
|
|
54
100
|
property.required = true;
|
|
55
101
|
}
|
|
56
102
|
if (col.DATA_DEFAULT !== 'null' && col.DATA_DEFAULT !== undefined && col.DATA_DEFAULT !== null) {
|
|
57
103
|
property.defaultValue = col.DATA_DEFAULT;
|
|
58
104
|
}
|
|
105
|
+
|
|
59
106
|
switch (type) {
|
|
60
107
|
case 'SMALLINT':
|
|
61
108
|
case 'INTEGER':
|
|
@@ -63,9 +110,9 @@ function colInfoToProperty(colInfo) {
|
|
|
63
110
|
case 'BIGINT':
|
|
64
111
|
case 'TINYINT':
|
|
65
112
|
property.type = 'integer';
|
|
66
|
-
property.size =
|
|
113
|
+
property.size = COLUMN_NUMER_TYPE_IDX.INTEGER;
|
|
67
114
|
for (let k in columnSizes.integer) {
|
|
68
|
-
if (columnSizes.integer[k] === type) {
|
|
115
|
+
if ((columnSizes.integer as Record<string, string>)[k] === type) {
|
|
69
116
|
property.size = parseInt(k, 10);
|
|
70
117
|
break;
|
|
71
118
|
}
|
|
@@ -78,9 +125,9 @@ function colInfoToProperty(colInfo) {
|
|
|
78
125
|
case 'DECIMAL':
|
|
79
126
|
property.type = 'number';
|
|
80
127
|
property.rational = true;
|
|
81
|
-
property.size =
|
|
128
|
+
property.size = COLUMN_NUMER_TYPE_IDX.DOUBLE;
|
|
82
129
|
if (type === 'FLOAT' || type === 'REAL') {
|
|
83
|
-
property.size =
|
|
130
|
+
property.size = COLUMN_NUMER_TYPE_IDX.FLOAT;
|
|
84
131
|
}
|
|
85
132
|
break;
|
|
86
133
|
case 'BIT':
|
|
@@ -102,8 +149,7 @@ function colInfoToProperty(colInfo) {
|
|
|
102
149
|
property.type = 'text';
|
|
103
150
|
if (col.CHAR_LENGTH) {
|
|
104
151
|
property.size = parseInt(String(col.CHAR_LENGTH), 10);
|
|
105
|
-
}
|
|
106
|
-
else if (col.DATA_LENGTH) {
|
|
152
|
+
} else if (col.DATA_LENGTH) {
|
|
107
153
|
property.size = parseInt(String(col.DATA_LENGTH), 10);
|
|
108
154
|
}
|
|
109
155
|
break;
|
|
@@ -125,49 +171,59 @@ function colInfoToProperty(colInfo) {
|
|
|
125
171
|
default:
|
|
126
172
|
throw new Error(`Unknown property type '${type}'`);
|
|
127
173
|
}
|
|
174
|
+
|
|
128
175
|
if (property.serial) {
|
|
129
176
|
property.type = 'serial';
|
|
130
177
|
}
|
|
178
|
+
|
|
131
179
|
property.mapsTo = col.COLUMN_NAME;
|
|
180
|
+
|
|
132
181
|
if (col.COMMENT) {
|
|
133
182
|
property.comment = col.COMMENT;
|
|
134
183
|
}
|
|
184
|
+
|
|
135
185
|
return property;
|
|
136
186
|
}
|
|
137
|
-
|
|
187
|
+
|
|
188
|
+
export const rawToProperty: IPropTransformer<ColumnInfoDM>['rawToProperty'] = function (
|
|
189
|
+
colInfo, ctx
|
|
190
|
+
) {
|
|
138
191
|
return {
|
|
139
192
|
raw: colInfo,
|
|
140
193
|
property: colInfoToProperty(colInfo)
|
|
141
|
-
}
|
|
194
|
+
}
|
|
142
195
|
};
|
|
143
|
-
|
|
144
|
-
const toStorageType = function (
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
const
|
|
196
|
+
|
|
197
|
+
export const toStorageType: IPropTransformer<ColumnInfoDM>['toStorageType'] = function (
|
|
198
|
+
inputProperty, ctx
|
|
199
|
+
) {
|
|
200
|
+
const property = { ...inputProperty }
|
|
201
|
+
|
|
202
|
+
const result: ReturnType<IPropTransformer<ColumnInfoDM>['toStorageType']> = {
|
|
148
203
|
isCustom: false,
|
|
149
204
|
property,
|
|
150
205
|
typeValue: '',
|
|
151
|
-
}
|
|
206
|
+
}
|
|
207
|
+
|
|
152
208
|
if (property.type == 'number' && property.rational === false) {
|
|
153
209
|
property.type = 'integer';
|
|
154
210
|
delete property.rational;
|
|
155
211
|
}
|
|
212
|
+
|
|
156
213
|
switch (property.type) {
|
|
157
214
|
case 'text':
|
|
158
215
|
if (property.big) {
|
|
159
216
|
result.typeValue = 'TEXT';
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
const size = Math.min(Math.max(parseInt(property.size, 10) || 255, 1), 32767);
|
|
217
|
+
} else {
|
|
218
|
+
const size = Math.min(Math.max(parseInt(String(property.size), 10) || 255, 1), 32767);
|
|
163
219
|
result.typeValue = `VARCHAR(${size})`;
|
|
164
220
|
}
|
|
165
221
|
break;
|
|
166
222
|
case 'integer':
|
|
167
|
-
result.typeValue = columnSizes.integer[property.size] || columnSizes.integer[
|
|
223
|
+
result.typeValue = (columnSizes.integer as Record<string, string>)[property.size!] || columnSizes.integer[COLUMN_NUMER_TYPE_IDX.INTEGER];
|
|
168
224
|
break;
|
|
169
225
|
case 'number':
|
|
170
|
-
result.typeValue = columnSizes.floating[property.size] || columnSizes.floating[
|
|
226
|
+
result.typeValue = (columnSizes.floating as Record<string, string>)[property.size!] || columnSizes.floating[COLUMN_NUMER_TYPE_IDX.DOUBLE];
|
|
171
227
|
break;
|
|
172
228
|
case 'serial':
|
|
173
229
|
property.type = 'number';
|
|
@@ -201,8 +257,9 @@ const toStorageType = function (inputProperty, ctx) {
|
|
|
201
257
|
result.isCustom = true;
|
|
202
258
|
break;
|
|
203
259
|
}
|
|
204
|
-
|
|
205
|
-
|
|
260
|
+
|
|
261
|
+
if (!result.typeValue && !result.isCustom) return result;
|
|
262
|
+
|
|
206
263
|
if (property.required) {
|
|
207
264
|
result.typeValue += ' NOT NULL';
|
|
208
265
|
}
|
|
@@ -212,26 +269,29 @@ const toStorageType = function (inputProperty, ctx) {
|
|
|
212
269
|
}
|
|
213
270
|
result.typeValue += ' IDENTITY(1,1)';
|
|
214
271
|
}
|
|
272
|
+
|
|
215
273
|
if (result.isCustom) {
|
|
216
|
-
if (
|
|
217
|
-
result.typeValue = ctx.customTypes[property.type].datastoreType(property, ctx)
|
|
274
|
+
if (ctx.customTypes?.[property.type]) {
|
|
275
|
+
result.typeValue = ctx.customTypes[property.type].datastoreType(property, ctx)
|
|
218
276
|
}
|
|
219
|
-
}
|
|
220
|
-
else if (property.hasOwnProperty('defaultValue') && property.defaultValue !== undefined) {
|
|
277
|
+
} else if (property.hasOwnProperty('defaultValue') && property.defaultValue !== undefined) {
|
|
221
278
|
const defaultValue = property.type === 'date' && property.defaultValue === Date.now
|
|
222
279
|
? 'CURRENT_TIMESTAMP'
|
|
223
|
-
:
|
|
224
|
-
|
|
280
|
+
: filterPropertyDefaultValue(property, ctx);
|
|
281
|
+
|
|
282
|
+
result.typeValue += ` DEFAULT ${
|
|
283
|
+
property.type === 'date' && (['CURRENT_TIMESTAMP'].includes(defaultValue))
|
|
225
284
|
? defaultValue
|
|
226
285
|
: ctx.escapeVal(defaultValue)}`;
|
|
227
286
|
}
|
|
287
|
+
|
|
228
288
|
if (property.comment) {
|
|
229
289
|
result.typeValue += ` COMMENT ${ctx.escapeVal(property.comment)}`;
|
|
230
290
|
}
|
|
291
|
+
|
|
231
292
|
return result;
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
const filterRawColumns = function (col) {
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
export const filterRawColumns: IPropTransformer<ColumnInfoDM>['filterRawColumns'] = function (col) {
|
|
235
296
|
return normalizeColInfo(col);
|
|
236
|
-
}
|
|
237
|
-
exports.filterRawColumns = filterRawColumns;
|
|
297
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import * as mysql from './mysql';
|
|
2
|
+
export { mysql };
|
|
3
|
+
import * as sqlite from './sqlite';
|
|
4
|
+
export { sqlite };
|
|
5
|
+
import * as postgresql from './postgresql';
|
|
6
|
+
export { postgresql };
|
|
7
|
+
import * as dm from './dm';
|
|
8
|
+
export { dm };
|
|
9
|
+
import * as mssql from './mssql';
|
|
10
|
+
export { mssql };
|