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,285 @@
|
|
|
1
|
+
import type { IPropTransformer, IProperty, PropertyType, __StringType } from "../Property"
|
|
2
|
+
import { COLUMN_NUMER_TYPE_IDX, filterPropertyDefaultValue } from "../Utils"
|
|
3
|
+
|
|
4
|
+
export type ColumnType_MSSQL = PropertyType
|
|
5
|
+
|
|
6
|
+
export interface ColumnInfoMSSQL {
|
|
7
|
+
COLUMN_NAME?: string
|
|
8
|
+
DATA_TYPE?: string
|
|
9
|
+
CHARACTER_MAXIMUM_LENGTH?: number | string
|
|
10
|
+
NUMERIC_PRECISION?: number | string
|
|
11
|
+
NUMERIC_SCALE?: number | string
|
|
12
|
+
IS_NULLABLE?: __StringType<'YES' | 'NO'>
|
|
13
|
+
COLUMN_DEFAULT?: any
|
|
14
|
+
IS_IDENTITY?: number | string | boolean
|
|
15
|
+
COMMENT?: string
|
|
16
|
+
|
|
17
|
+
column_name?: string
|
|
18
|
+
data_type?: string
|
|
19
|
+
character_maximum_length?: number | string
|
|
20
|
+
numeric_precision?: number | string
|
|
21
|
+
numeric_scale?: number | string
|
|
22
|
+
is_nullable?: __StringType<'YES' | 'NO'>
|
|
23
|
+
column_default?: any
|
|
24
|
+
is_identity?: number | string | boolean
|
|
25
|
+
comment?: string
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const columnSizes = {
|
|
29
|
+
integer: {
|
|
30
|
+
[COLUMN_NUMER_TYPE_IDX.SHORT]: 'SMALLINT',
|
|
31
|
+
[COLUMN_NUMER_TYPE_IDX.INTEGER]: 'INT',
|
|
32
|
+
[COLUMN_NUMER_TYPE_IDX.LONG]: 'BIGINT'
|
|
33
|
+
},
|
|
34
|
+
floating: {
|
|
35
|
+
[COLUMN_NUMER_TYPE_IDX.FLOAT]: 'REAL',
|
|
36
|
+
[COLUMN_NUMER_TYPE_IDX.DOUBLE]: 'FLOAT'
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
function normalizeColInfo(colInfo: ColumnInfoMSSQL): ColumnInfoMSSQL {
|
|
41
|
+
const toStringOrEmpty = (value: unknown) => value ? value.toString() : '';
|
|
42
|
+
|
|
43
|
+
return {
|
|
44
|
+
COLUMN_NAME: toStringOrEmpty(colInfo.COLUMN_NAME ?? colInfo.column_name),
|
|
45
|
+
DATA_TYPE: toStringOrEmpty(colInfo.DATA_TYPE ?? colInfo.data_type),
|
|
46
|
+
CHARACTER_MAXIMUM_LENGTH: toStringOrEmpty(
|
|
47
|
+
colInfo.CHARACTER_MAXIMUM_LENGTH ?? colInfo.character_maximum_length
|
|
48
|
+
),
|
|
49
|
+
NUMERIC_PRECISION: toStringOrEmpty(
|
|
50
|
+
colInfo.NUMERIC_PRECISION ?? colInfo.numeric_precision
|
|
51
|
+
),
|
|
52
|
+
NUMERIC_SCALE: toStringOrEmpty(
|
|
53
|
+
colInfo.NUMERIC_SCALE ?? colInfo.numeric_scale
|
|
54
|
+
),
|
|
55
|
+
IS_NULLABLE: toStringOrEmpty(
|
|
56
|
+
colInfo.IS_NULLABLE ?? colInfo.is_nullable
|
|
57
|
+
) as ColumnInfoMSSQL['IS_NULLABLE'],
|
|
58
|
+
COLUMN_DEFAULT: colInfo.COLUMN_DEFAULT ?? colInfo.column_default,
|
|
59
|
+
IS_IDENTITY: toStringOrEmpty(
|
|
60
|
+
colInfo.IS_IDENTITY ?? colInfo.is_identity
|
|
61
|
+
),
|
|
62
|
+
COMMENT: (colInfo.COMMENT ?? colInfo.comment) as ColumnInfoMSSQL['COMMENT'],
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function isIdentityColumn(colInfo: ColumnInfoMSSQL) {
|
|
67
|
+
const v = colInfo.IS_IDENTITY ? colInfo.IS_IDENTITY.toString().toUpperCase() : '';
|
|
68
|
+
return v === '1' || v === 'TRUE' || v === 'YES' || v === 'Y';
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function cleanDefaultValue(value: any) {
|
|
72
|
+
if (value === undefined || value === null) return value;
|
|
73
|
+
|
|
74
|
+
let str = String(value).trim();
|
|
75
|
+
// SQL Server wraps defaults like ((0)) or ('text').
|
|
76
|
+
while (str.startsWith('(') && str.endsWith(')')) {
|
|
77
|
+
str = str.slice(1, -1).trim();
|
|
78
|
+
}
|
|
79
|
+
if (str.length >= 2 && str.startsWith("'") && str.endsWith("'")) {
|
|
80
|
+
str = str.slice(1, -1).replace(/''/g, "'");
|
|
81
|
+
}
|
|
82
|
+
return str;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function colInfoToProperty(colInfo: ColumnInfoMSSQL) {
|
|
86
|
+
const property = {} as IProperty;
|
|
87
|
+
const col = normalizeColInfo(colInfo);
|
|
88
|
+
const type = col.DATA_TYPE!.toUpperCase();
|
|
89
|
+
|
|
90
|
+
if (isIdentityColumn(col)) {
|
|
91
|
+
property.serial = true;
|
|
92
|
+
property.key = true;
|
|
93
|
+
property.primary = true;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
if (col.IS_NULLABLE && col.IS_NULLABLE.toUpperCase() === 'NO') {
|
|
97
|
+
property.required = true;
|
|
98
|
+
}
|
|
99
|
+
if (col.COLUMN_DEFAULT !== undefined && col.COLUMN_DEFAULT !== null) {
|
|
100
|
+
property.defaultValue = cleanDefaultValue(col.COLUMN_DEFAULT);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
switch (type) {
|
|
104
|
+
case 'TINYINT':
|
|
105
|
+
case 'SMALLINT':
|
|
106
|
+
case 'INT':
|
|
107
|
+
case 'BIGINT':
|
|
108
|
+
property.type = 'integer';
|
|
109
|
+
property.size = COLUMN_NUMER_TYPE_IDX.INTEGER;
|
|
110
|
+
if (type === 'TINYINT' || type === 'SMALLINT') property.size = COLUMN_NUMER_TYPE_IDX.SHORT;
|
|
111
|
+
if (type === 'BIGINT') property.size = COLUMN_NUMER_TYPE_IDX.LONG;
|
|
112
|
+
break;
|
|
113
|
+
case 'REAL':
|
|
114
|
+
property.type = 'number';
|
|
115
|
+
property.rational = true;
|
|
116
|
+
property.size = COLUMN_NUMER_TYPE_IDX.FLOAT;
|
|
117
|
+
break;
|
|
118
|
+
case 'FLOAT':
|
|
119
|
+
case 'DECIMAL':
|
|
120
|
+
case 'NUMERIC':
|
|
121
|
+
case 'MONEY':
|
|
122
|
+
case 'SMALLMONEY':
|
|
123
|
+
property.type = 'number';
|
|
124
|
+
property.rational = true;
|
|
125
|
+
property.size = COLUMN_NUMER_TYPE_IDX.DOUBLE;
|
|
126
|
+
break;
|
|
127
|
+
case 'BIT':
|
|
128
|
+
property.type = 'boolean';
|
|
129
|
+
break;
|
|
130
|
+
case 'DATE':
|
|
131
|
+
property.type = 'date';
|
|
132
|
+
break;
|
|
133
|
+
case 'DATETIME':
|
|
134
|
+
case 'DATETIME2':
|
|
135
|
+
case 'SMALLDATETIME':
|
|
136
|
+
case 'DATETIMEOFFSET':
|
|
137
|
+
case 'TIME':
|
|
138
|
+
property.type = 'date';
|
|
139
|
+
property.time = true;
|
|
140
|
+
break;
|
|
141
|
+
case 'CHAR':
|
|
142
|
+
case 'VARCHAR':
|
|
143
|
+
case 'NCHAR':
|
|
144
|
+
case 'NVARCHAR':
|
|
145
|
+
property.type = 'text';
|
|
146
|
+
if (col.CHARACTER_MAXIMUM_LENGTH !== undefined && col.CHARACTER_MAXIMUM_LENGTH !== '') {
|
|
147
|
+
const size = parseInt(String(col.CHARACTER_MAXIMUM_LENGTH), 10);
|
|
148
|
+
if (size < 0) {
|
|
149
|
+
property.big = true;
|
|
150
|
+
} else {
|
|
151
|
+
property.size = size;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
break;
|
|
155
|
+
case 'TEXT':
|
|
156
|
+
case 'NTEXT':
|
|
157
|
+
case 'XML':
|
|
158
|
+
property.type = 'text';
|
|
159
|
+
property.big = true;
|
|
160
|
+
break;
|
|
161
|
+
case 'BINARY':
|
|
162
|
+
case 'VARBINARY':
|
|
163
|
+
case 'IMAGE':
|
|
164
|
+
case 'TIMESTAMP':
|
|
165
|
+
case 'ROWVERSION':
|
|
166
|
+
property.type = 'binary';
|
|
167
|
+
break;
|
|
168
|
+
case 'UNIQUEIDENTIFIER':
|
|
169
|
+
property.type = 'text';
|
|
170
|
+
break;
|
|
171
|
+
case 'SQL_VARIANT':
|
|
172
|
+
property.type = 'text';
|
|
173
|
+
break;
|
|
174
|
+
default:
|
|
175
|
+
throw new Error(`Unknown property type '${type}'`);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
if (property.serial) {
|
|
179
|
+
property.type = 'serial';
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
property.mapsTo = col.COLUMN_NAME;
|
|
183
|
+
|
|
184
|
+
if (col.COMMENT) {
|
|
185
|
+
property.comment = String(col.COMMENT);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
return property;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
export const rawToProperty: IPropTransformer<ColumnInfoMSSQL>['rawToProperty'] = function (
|
|
192
|
+
colInfo, ctx
|
|
193
|
+
) {
|
|
194
|
+
return {
|
|
195
|
+
raw: colInfo,
|
|
196
|
+
property: colInfoToProperty(colInfo)
|
|
197
|
+
}
|
|
198
|
+
};
|
|
199
|
+
|
|
200
|
+
export const toStorageType: IPropTransformer<ColumnInfoMSSQL>['toStorageType'] = function (
|
|
201
|
+
inputProperty, ctx
|
|
202
|
+
) {
|
|
203
|
+
const property = { ...inputProperty }
|
|
204
|
+
|
|
205
|
+
const result: ReturnType<IPropTransformer<ColumnInfoMSSQL>['toStorageType']> = {
|
|
206
|
+
isCustom: false,
|
|
207
|
+
property,
|
|
208
|
+
typeValue: '',
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
if (property.type == 'number' && property.rational === false) {
|
|
212
|
+
property.type = 'integer';
|
|
213
|
+
delete property.rational;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
switch (property.type) {
|
|
217
|
+
case 'text':
|
|
218
|
+
if (property.big) {
|
|
219
|
+
result.typeValue = 'NVARCHAR(MAX)';
|
|
220
|
+
} else {
|
|
221
|
+
const size = Math.min(Math.max(parseInt(String(property.size), 10) || 255, 1), 4000);
|
|
222
|
+
result.typeValue = `NVARCHAR(${size})`;
|
|
223
|
+
}
|
|
224
|
+
break;
|
|
225
|
+
case 'integer':
|
|
226
|
+
result.typeValue = (columnSizes.integer as Record<string, string>)[property.size!] || columnSizes.integer[COLUMN_NUMER_TYPE_IDX.INTEGER];
|
|
227
|
+
break;
|
|
228
|
+
case 'number':
|
|
229
|
+
result.typeValue = (columnSizes.floating as Record<string, string>)[property.size!] || columnSizes.floating[COLUMN_NUMER_TYPE_IDX.DOUBLE];
|
|
230
|
+
break;
|
|
231
|
+
case 'serial':
|
|
232
|
+
property.type = 'number';
|
|
233
|
+
property.serial = true;
|
|
234
|
+
property.key = true;
|
|
235
|
+
result.typeValue = property.size === COLUMN_NUMER_TYPE_IDX.LONG
|
|
236
|
+
? 'BIGINT IDENTITY(1,1)'
|
|
237
|
+
: 'INT IDENTITY(1,1)';
|
|
238
|
+
break;
|
|
239
|
+
case 'boolean':
|
|
240
|
+
result.typeValue = 'BIT';
|
|
241
|
+
break;
|
|
242
|
+
case 'datetime':
|
|
243
|
+
property.type = 'date';
|
|
244
|
+
property.time = true;
|
|
245
|
+
case 'date':
|
|
246
|
+
result.typeValue = property.time ? 'DATETIME2' : 'DATE';
|
|
247
|
+
break;
|
|
248
|
+
case 'binary':
|
|
249
|
+
result.typeValue = 'VARBINARY(MAX)';
|
|
250
|
+
break;
|
|
251
|
+
case 'object':
|
|
252
|
+
result.typeValue = 'NVARCHAR(MAX)';
|
|
253
|
+
break;
|
|
254
|
+
case 'enum':
|
|
255
|
+
result.typeValue = 'NVARCHAR(255)';
|
|
256
|
+
break;
|
|
257
|
+
case 'point':
|
|
258
|
+
result.typeValue = 'NVARCHAR(MAX)';
|
|
259
|
+
break;
|
|
260
|
+
default:
|
|
261
|
+
result.isCustom = true;
|
|
262
|
+
break;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
if (!result.typeValue && !result.isCustom) return result;
|
|
266
|
+
|
|
267
|
+
if (property.required) {
|
|
268
|
+
result.typeValue += ' NOT NULL';
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
if (result.isCustom) {
|
|
272
|
+
if (ctx.customTypes?.[property.type]) {
|
|
273
|
+
result.typeValue = ctx.customTypes?.[property.type].datastoreType(property, ctx)
|
|
274
|
+
}
|
|
275
|
+
} else if (property.hasOwnProperty('defaultValue') && property.defaultValue !== undefined) {
|
|
276
|
+
if (property.type === 'date' && property.defaultValue === Date.now) {
|
|
277
|
+
result.typeValue += ' DEFAULT GETDATE()';
|
|
278
|
+
} else {
|
|
279
|
+
const defaultValue = filterPropertyDefaultValue(property, ctx)
|
|
280
|
+
result.typeValue += ' DEFAULT ' + ctx.escapeVal(defaultValue);
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
return result;
|
|
285
|
+
}
|
|
@@ -0,0 +1,395 @@
|
|
|
1
|
+
import type { IPropTransformer, IProperty, PropertyType, __StringType } from "../Property"
|
|
2
|
+
import { COLUMN_NUMER_TYPE_IDX, filterPropertyDefaultValue } from "../Utils"
|
|
3
|
+
|
|
4
|
+
export type ColumnType_MySQL = PropertyType
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* result from:
|
|
8
|
+
* 1. SHOW COLUMN FROM ??;
|
|
9
|
+
* 1. SHOW FULL COLUMN FROM ??;
|
|
10
|
+
*
|
|
11
|
+
* there're extra fields in the result of sql 2: Collation, Comment, Privileges
|
|
12
|
+
*
|
|
13
|
+
*/
|
|
14
|
+
export interface ColumnInfoMySQL {
|
|
15
|
+
Field: string
|
|
16
|
+
Type: Class_Buffer | __StringType<
|
|
17
|
+
'smallint'
|
|
18
|
+
| 'integer'
|
|
19
|
+
| 'bigint'
|
|
20
|
+
| 'int'
|
|
21
|
+
| 'float'
|
|
22
|
+
| 'double'
|
|
23
|
+
| 'tinyint'
|
|
24
|
+
| 'datetime'
|
|
25
|
+
| 'date'
|
|
26
|
+
| 'longblob'
|
|
27
|
+
| 'blob'
|
|
28
|
+
| 'varchar'
|
|
29
|
+
>
|
|
30
|
+
Size: number | string
|
|
31
|
+
/**
|
|
32
|
+
* extra description such as `AUTO_INCREMENT`
|
|
33
|
+
*/
|
|
34
|
+
Extra: string
|
|
35
|
+
/**
|
|
36
|
+
* @example `PRI`
|
|
37
|
+
*/
|
|
38
|
+
Key: __StringType<'PRI' | 'MUL'>
|
|
39
|
+
/**
|
|
40
|
+
* @example `NO`
|
|
41
|
+
*/
|
|
42
|
+
Null: __StringType<'NO' | 'YES'>
|
|
43
|
+
/**
|
|
44
|
+
* @deprecated
|
|
45
|
+
*/
|
|
46
|
+
SubType?: string[]
|
|
47
|
+
/**
|
|
48
|
+
* @example null
|
|
49
|
+
*/
|
|
50
|
+
Default?: any
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* @example `utf8mb4_unicode_ci`
|
|
54
|
+
*/
|
|
55
|
+
Collation?: string
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* @example `select,insert,update,references`
|
|
59
|
+
* type IPrivileges = "select" | "insert" | "update" | "references";
|
|
60
|
+
*/
|
|
61
|
+
Privileges?: string
|
|
62
|
+
|
|
63
|
+
Comment?: string
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
export interface ColumnInfoMySQL {
|
|
68
|
+
Field: string;
|
|
69
|
+
Type: Class_Buffer | __StringType<'smallint' | 'integer' | 'bigint' | 'int' | 'float' | 'double' | 'tinyint' | 'datetime' | 'date' | 'longblob' | 'blob' | 'varchar'>;
|
|
70
|
+
Size: number | string;
|
|
71
|
+
/**
|
|
72
|
+
* extra description such as `AUTO_INCREMENT`
|
|
73
|
+
*/
|
|
74
|
+
Extra: string;
|
|
75
|
+
/**
|
|
76
|
+
* @example `PRI`
|
|
77
|
+
*/
|
|
78
|
+
Key: __StringType<'PRI' | 'MUL'>;
|
|
79
|
+
/**
|
|
80
|
+
* @example `NO`
|
|
81
|
+
*/
|
|
82
|
+
Null: __StringType<'NO' | 'YES'>;
|
|
83
|
+
SubType?: string[];
|
|
84
|
+
/**
|
|
85
|
+
* @example null
|
|
86
|
+
*/
|
|
87
|
+
Default?: any;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
type DB_INTEGER = number;
|
|
91
|
+
type DB_UNSIGNED_INT = DB_INTEGER;
|
|
92
|
+
type DB_BIGINT = number | bigint;
|
|
93
|
+
type DB_UNSIGNED_BIGINT = DB_BIGINT;
|
|
94
|
+
type DB_TEXT = string;
|
|
95
|
+
type DB_VARCHAR<T extends number = 255> = string;
|
|
96
|
+
|
|
97
|
+
// result from: SELECT * FROM information_schema.columns WHERE table_name = ? AND table_schema = ?;
|
|
98
|
+
// this type from: show columns from information_schema.columns;
|
|
99
|
+
export interface SchemaColumnInfoMySQL {
|
|
100
|
+
TABLE_CATALOG: DB_VARCHAR<64>
|
|
101
|
+
TABLE_SCHEMA: DB_VARCHAR<64>
|
|
102
|
+
TABLE_NAME: DB_VARCHAR<64>
|
|
103
|
+
COLUMN_NAME: DB_VARCHAR<64>
|
|
104
|
+
ORDINAL_POSITION: DB_UNSIGNED_INT
|
|
105
|
+
COLUMN_DEFAULT: DB_TEXT
|
|
106
|
+
IS_NULLABLE: DB_VARCHAR<3> | 'NO' | 'YES'
|
|
107
|
+
DATA_TYPE: DB_TEXT
|
|
108
|
+
CHARACTER_MAXIMUM_LENGTH: DB_BIGINT
|
|
109
|
+
CHARACTER_OCTET_LENGTH: DB_BIGINT
|
|
110
|
+
NUMERIC_PRECISION: DB_UNSIGNED_BIGINT
|
|
111
|
+
NUMERIC_SCALE: DB_UNSIGNED_BIGINT
|
|
112
|
+
DATETIME_PRECISION: DB_UNSIGNED_INT
|
|
113
|
+
CHARACTER_SET_NAME: DB_VARCHAR
|
|
114
|
+
COLLATION_NAME: DB_TEXT
|
|
115
|
+
COLUMN_TYPE: DB_TEXT
|
|
116
|
+
COLUMN_KEY: '' | 'PRI' | 'UNI' | 'MUL'
|
|
117
|
+
EXTRA: DB_VARCHAR<256>
|
|
118
|
+
PRIVILEGES: DB_VARCHAR<154>
|
|
119
|
+
COLUMN_COMMENT: DB_TEXT
|
|
120
|
+
GENERATION_EXPRESSION: DB_TEXT
|
|
121
|
+
SRS_ID: DB_UNSIGNED_INT
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
const columnSizes = {
|
|
125
|
+
integer: {
|
|
126
|
+
[COLUMN_NUMER_TYPE_IDX.SHORT]: 'SMALLINT',
|
|
127
|
+
[COLUMN_NUMER_TYPE_IDX.INTEGER]: 'INTEGER',
|
|
128
|
+
[COLUMN_NUMER_TYPE_IDX.LONG]: 'BIGINT'
|
|
129
|
+
},
|
|
130
|
+
floating: {
|
|
131
|
+
[COLUMN_NUMER_TYPE_IDX.FLOAT]: 'FLOAT',
|
|
132
|
+
[COLUMN_NUMER_TYPE_IDX.DOUBLE]: 'DOUBLE'
|
|
133
|
+
}
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
function colInfoToProperty(colInfo: ColumnInfoMySQL) {
|
|
137
|
+
const property = {} as IProperty;
|
|
138
|
+
colInfo = { ...colInfo };
|
|
139
|
+
filterRawColumns!(colInfo);
|
|
140
|
+
|
|
141
|
+
let Type = colInfo.Type + ''
|
|
142
|
+
const spaceIdx = Type.indexOf(" ");
|
|
143
|
+
if (spaceIdx > 0) {
|
|
144
|
+
colInfo.SubType = Type.slice(spaceIdx + 1).split(/\s+/);
|
|
145
|
+
Type = Type.slice(0, spaceIdx);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
// match_result
|
|
149
|
+
let [_, _type, _size] = Type.match(/^(.+)\((\d+)\)$/) || [] as any[];
|
|
150
|
+
if (_) colInfo.Size = parseInt(_size, 10);
|
|
151
|
+
const narrowType = !_ ? Type.toUpperCase() : _type.toUpperCase();
|
|
152
|
+
|
|
153
|
+
if (colInfo.Extra.toUpperCase() == "AUTO_INCREMENT") {
|
|
154
|
+
property.serial = true;
|
|
155
|
+
property.key = true;
|
|
156
|
+
property.unsigned = true;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
if (colInfo.Key === "PRI") {
|
|
160
|
+
property.primary = true;
|
|
161
|
+
property.key = true;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
if (colInfo.Null.toUpperCase() == "NO") {
|
|
165
|
+
property.required = true;
|
|
166
|
+
}
|
|
167
|
+
if (colInfo.Default !== "null") {
|
|
168
|
+
property.defaultValue = colInfo.Default;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
switch (narrowType) {
|
|
172
|
+
case "SMALLINT":
|
|
173
|
+
case "INTEGER":
|
|
174
|
+
case "BIGINT":
|
|
175
|
+
case "INT":
|
|
176
|
+
property.type = "integer";
|
|
177
|
+
property.size = 4; // INT
|
|
178
|
+
if (colInfo.SubType?.includes('unsigned')) property.unsigned = true;
|
|
179
|
+
for (let k in columnSizes.integer) {
|
|
180
|
+
if ((columnSizes.integer as Record<string, string>)[k] == narrowType) {
|
|
181
|
+
property.size = k;
|
|
182
|
+
break;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
break;
|
|
186
|
+
case "FLOAT":
|
|
187
|
+
case "DOUBLE":
|
|
188
|
+
property.type = "number";
|
|
189
|
+
property.rational = true;
|
|
190
|
+
if (colInfo.SubType?.includes('unsigned')) property.unsigned = true;
|
|
191
|
+
for (let k in columnSizes.floating) {
|
|
192
|
+
if ((columnSizes.floating as Record<string, string>)[k] == narrowType) {
|
|
193
|
+
property.size = k;
|
|
194
|
+
break;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
break;
|
|
198
|
+
case "TINYINT":
|
|
199
|
+
if (colInfo.Size == 1) {
|
|
200
|
+
property.type = "boolean";
|
|
201
|
+
} else {
|
|
202
|
+
property.type = "integer";
|
|
203
|
+
}
|
|
204
|
+
break;
|
|
205
|
+
case "DATETIME":
|
|
206
|
+
property.time = true;
|
|
207
|
+
case "DATE":
|
|
208
|
+
property.type = "date";
|
|
209
|
+
break;
|
|
210
|
+
case "LONGBLOB":
|
|
211
|
+
property.big = true;
|
|
212
|
+
case "BLOB":
|
|
213
|
+
property.type = "binary";
|
|
214
|
+
break;
|
|
215
|
+
case "VARCHAR":
|
|
216
|
+
property.type = "text";
|
|
217
|
+
if (colInfo.Size) {
|
|
218
|
+
property.size = colInfo.Size;
|
|
219
|
+
}
|
|
220
|
+
break;
|
|
221
|
+
case "TEXT":
|
|
222
|
+
property.type = "text";
|
|
223
|
+
break;
|
|
224
|
+
case "LONGTEXT":
|
|
225
|
+
property.type = "longtext";
|
|
226
|
+
break;
|
|
227
|
+
case "POINT":
|
|
228
|
+
property.type = "point";
|
|
229
|
+
break;
|
|
230
|
+
default:
|
|
231
|
+
let [_2, _enum_value_str] = narrowType.toLowerCase().match(/^enum\('(.+)'\)$/) || [] as any;
|
|
232
|
+
if (_2) {
|
|
233
|
+
property.type = "enum";
|
|
234
|
+
property.values = _enum_value_str.split(/'\s*,\s*'/);
|
|
235
|
+
break;
|
|
236
|
+
}
|
|
237
|
+
throw new Error(`Unknown property type '${narrowType}'`);
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
if (property.serial) {
|
|
241
|
+
property.type = "serial";
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
property.mapsTo = colInfo.Field;
|
|
245
|
+
|
|
246
|
+
if (colInfo.Comment)
|
|
247
|
+
property.comment = colInfo.Comment;
|
|
248
|
+
|
|
249
|
+
return property
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
function schemaColInfoToProperty(colInfo: SchemaColumnInfoMySQL) {
|
|
253
|
+
throw new Error('Not implemented');
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
export const rawToProperty: IPropTransformer<ColumnInfoMySQL>['rawToProperty'] = function (
|
|
257
|
+
colInfo, ctx
|
|
258
|
+
) {
|
|
259
|
+
return {
|
|
260
|
+
raw: colInfo,
|
|
261
|
+
property: colInfoToProperty(colInfo)
|
|
262
|
+
}
|
|
263
|
+
};
|
|
264
|
+
|
|
265
|
+
export const toStorageType: IPropTransformer<ColumnInfoMySQL>['toStorageType'] = function (
|
|
266
|
+
inputProperty, ctx
|
|
267
|
+
) {
|
|
268
|
+
const property = { ...inputProperty }
|
|
269
|
+
|
|
270
|
+
const result: ReturnType<IPropTransformer<ColumnInfoMySQL>['toStorageType']> = {
|
|
271
|
+
isCustom: false,
|
|
272
|
+
property,
|
|
273
|
+
typeValue: '',
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
if (property.type == 'number' && property.rational === false) {
|
|
277
|
+
property.type = 'integer';
|
|
278
|
+
delete property.rational;
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
switch (property.type) {
|
|
282
|
+
case "text":
|
|
283
|
+
if (property.big) {
|
|
284
|
+
result.typeValue = "LONGTEXT";
|
|
285
|
+
} else {
|
|
286
|
+
result.typeValue = "VARCHAR(" + Math.min(Math.max(parseInt(String(property.size), 10) || 255, 1), 65535) + ")";
|
|
287
|
+
}
|
|
288
|
+
break;
|
|
289
|
+
case "integer":
|
|
290
|
+
result.typeValue = (columnSizes.integer as Record<string, string>)[property.size!] || columnSizes.integer[COLUMN_NUMER_TYPE_IDX.INTEGER];
|
|
291
|
+
if (property.unsigned) { result.typeValue += " UNSIGNED"; }
|
|
292
|
+
break;
|
|
293
|
+
/**
|
|
294
|
+
* @notice As of MySQL 8.0.17, the UNSIGNED attribute is deprecated for columns of type FLOAT, DOUBLE, and DECIMAL (and any synonyms); you should expect support for it to be removed in a future version of MySQL. Consider using a simple CHECK constraint instead for such columns.
|
|
295
|
+
*
|
|
296
|
+
* @see https://dev.mysql.com/doc/refman/8.0/en/numeric-type-syntax.html
|
|
297
|
+
*/
|
|
298
|
+
case "number":
|
|
299
|
+
result.typeValue = (columnSizes.floating as Record<string, string>)[property.size!] || columnSizes.floating[COLUMN_NUMER_TYPE_IDX.INTEGER];
|
|
300
|
+
if (property.unsigned) { result.typeValue += " UNSIGNED"; }
|
|
301
|
+
break;
|
|
302
|
+
case "serial":
|
|
303
|
+
property.type = "number";
|
|
304
|
+
property.serial = true;
|
|
305
|
+
property.key = true;
|
|
306
|
+
result.typeValue = `INT(${property.size || 11})`;
|
|
307
|
+
break;
|
|
308
|
+
case "boolean":
|
|
309
|
+
result.typeValue = "TINYINT(1)";
|
|
310
|
+
break;
|
|
311
|
+
case "datetime":
|
|
312
|
+
property.type = "date";
|
|
313
|
+
property.time = true;
|
|
314
|
+
case "date":
|
|
315
|
+
if (!property.time) {
|
|
316
|
+
result.typeValue = "DATE";
|
|
317
|
+
} else {
|
|
318
|
+
result.typeValue = "DATETIME";
|
|
319
|
+
}
|
|
320
|
+
break;
|
|
321
|
+
case "binary":
|
|
322
|
+
case "object":
|
|
323
|
+
if (property.big === true) {
|
|
324
|
+
result.typeValue = "LONGBLOB";
|
|
325
|
+
} else {
|
|
326
|
+
result.typeValue = "BLOB";
|
|
327
|
+
}
|
|
328
|
+
break;
|
|
329
|
+
case "enum":
|
|
330
|
+
result.typeValue = "ENUM (" + property.values!.map((val: any) => ctx.escapeVal(val)) + ")";
|
|
331
|
+
break;
|
|
332
|
+
case "point":
|
|
333
|
+
result.typeValue = "POINT";
|
|
334
|
+
break;
|
|
335
|
+
default:
|
|
336
|
+
result.isCustom = true;
|
|
337
|
+
break;
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
if (!result.typeValue && !result.isCustom) return result;
|
|
341
|
+
|
|
342
|
+
if (property.required) {
|
|
343
|
+
result.typeValue += " NOT NULL";
|
|
344
|
+
}
|
|
345
|
+
if (property.serial) {
|
|
346
|
+
if (!property.required) {
|
|
347
|
+
// append if not set
|
|
348
|
+
result.typeValue += " NOT NULL";
|
|
349
|
+
}
|
|
350
|
+
result.typeValue += " AUTO_INCREMENT";
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
if (result.isCustom) {
|
|
354
|
+
if (ctx.customTypes?.[property.type]) {
|
|
355
|
+
result.typeValue = ctx.customTypes[property.type].datastoreType(property, ctx)
|
|
356
|
+
}
|
|
357
|
+
} else if (property.hasOwnProperty("defaultValue") && property.defaultValue !== undefined) {
|
|
358
|
+
const defaultValue = property.type === 'date' && property.defaultValue === Date.now
|
|
359
|
+
? 'CURRENT_TIMESTAMP'
|
|
360
|
+
: filterPropertyDefaultValue(property, ctx);
|
|
361
|
+
|
|
362
|
+
result.typeValue += ` DEFAULT ${
|
|
363
|
+
property.type === 'date' && (['CURRENT_TIMESTAMP'].includes(defaultValue))
|
|
364
|
+
? defaultValue
|
|
365
|
+
: ctx.escapeVal(defaultValue)}`;
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
if (property.comment) {
|
|
369
|
+
result.typeValue += ` COMMENT ${ctx.escapeVal(property.comment)}`;
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
return result;
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
function isSimpleColumnInfo(input: ColumnInfoMySQL | SchemaColumnInfoMySQL): input is ColumnInfoMySQL {
|
|
376
|
+
return input.hasOwnProperty('Type');
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
export const filterRawColumns: IPropTransformer<ColumnInfoMySQL>['filterRawColumns'] = function (col) {
|
|
380
|
+
if (isSimpleColumnInfo(col)) {
|
|
381
|
+
col.Type = col.Type ? col.Type.toString() : '';
|
|
382
|
+
col.Size = col.Size ? col.Size.toString() : '';
|
|
383
|
+
col.Extra = col.Extra ? col.Extra.toString() : '';
|
|
384
|
+
col.Key = col.Key ? col.Key.toString() : '';
|
|
385
|
+
col.Null = col.Null ? col.Null.toString() : '';
|
|
386
|
+
col.Default = col.Default ? col.Default.toString() : '';
|
|
387
|
+
col.Collation = col.Collation ? col.Collation.toString() : '';
|
|
388
|
+
col.Privileges = col.Privileges ? col.Privileges.toString() : '';
|
|
389
|
+
col.Comment = col.Comment ? col.Comment.toString() : '';
|
|
390
|
+
|
|
391
|
+
return col as ColumnInfoMySQL;
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
return col;
|
|
395
|
+
}
|