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
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
## fib-orm
|
|
2
2
|
|
|
3
|
-
ORM for [fibjs](https://fibjs.org) — a unified ORM package supporting SQLite, MySQL, and
|
|
3
|
+
ORM for [fibjs](https://fibjs.org) — a unified ORM package supporting SQLite, MySQL, PostgreSQL, KingbaseES, Microsoft SQL Server and DM (达梦).
|
|
4
4
|
|
|
5
5
|
### Install
|
|
6
6
|
|
|
@@ -29,23 +29,59 @@ console.log(users);
|
|
|
29
29
|
db.closeSync();
|
|
30
30
|
```
|
|
31
31
|
|
|
32
|
-
###
|
|
32
|
+
### Run and check
|
|
33
|
+
|
|
34
|
+
fibjs executes the TypeScript sources directly, so there is no compiler or
|
|
35
|
+
`lib/` build step. The runtime entry `index.js` is a CommonJS bridge over
|
|
36
|
+
`src/orm/index.ts`, which keeps `require('fib-orm')` working; `index.d.ts` adds
|
|
37
|
+
the default-export typing for `import orm from 'fib-orm'`.
|
|
33
38
|
|
|
34
39
|
```bash
|
|
35
|
-
|
|
40
|
+
# Type/syntax check (uses tsconfig.json, no emit)
|
|
41
|
+
npm run check
|
|
42
|
+
|
|
43
|
+
# CommonJS bridge: package entry, CJS/ESM interop, dynamic import()
|
|
44
|
+
npm run test:bridge
|
|
45
|
+
|
|
46
|
+
# ...and its declaration file
|
|
47
|
+
npm run check:bridge
|
|
48
|
+
|
|
49
|
+
# Use the library
|
|
50
|
+
fibjs -e "const ORM = require('fib-orm'); const db = ORM.connectSync('sqlite:test.db')"
|
|
36
51
|
```
|
|
37
52
|
|
|
38
53
|
### Test
|
|
39
54
|
|
|
55
|
+
`npm test` runs the full integration suite and reads `test/config.js` (or
|
|
56
|
+
`test/config.ci.js` when `CI` is set). `npm run test:smoke` runs the compact
|
|
57
|
+
cross-driver smoke suite against one URI:
|
|
58
|
+
|
|
40
59
|
```bash
|
|
41
60
|
# SQLite
|
|
42
|
-
ORM_PROTOCOL=sqlite
|
|
61
|
+
ORM_PROTOCOL=sqlite ORM_URI=sqlite:test.db npm run test:smoke
|
|
43
62
|
|
|
44
63
|
# MySQL
|
|
45
|
-
ORM_PROTOCOL=mysql
|
|
64
|
+
ORM_PROTOCOL=mysql ORM_URI=mysql://root:root_test@127.0.0.1:3306/test npm run test:smoke
|
|
46
65
|
|
|
47
66
|
# PostgreSQL
|
|
48
|
-
ORM_PROTOCOL=
|
|
67
|
+
ORM_PROTOCOL=psql ORM_URI=psql://user:password@127.0.0.1:5432/test npm run test:smoke
|
|
68
|
+
|
|
69
|
+
# KingbaseES (KODBC)
|
|
70
|
+
ORM_PROTOCOL=kingbase ORM_URI='kingbase://user:password@127.0.0.1:54321/test?Driver=/path/to/kdbodbcw.so' npm run test:smoke
|
|
71
|
+
|
|
72
|
+
# Microsoft SQL Server
|
|
73
|
+
ORM_PROTOCOL=mssql ORM_URI='mssql://sa:password@127.0.0.1:1433/test' npm run test:smoke
|
|
74
|
+
|
|
75
|
+
# DM (达梦)
|
|
76
|
+
ORM_PROTOCOL=dm ORM_URI='dm://SYSDBA:password@127.0.0.1:5236/test' npm run test:smoke
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
For CI, every database can run the self-contained smoke suite:
|
|
80
|
+
|
|
81
|
+
```bash
|
|
82
|
+
ORM_PROTOCOL=mssql \
|
|
83
|
+
ORM_URI='mssql://sa:password@localhost:1433/test' \
|
|
84
|
+
fibjs test/integration/db-smoke.js
|
|
49
85
|
```
|
|
50
86
|
|
|
51
87
|
### License
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type declarations for fib-orm's package entry.
|
|
3
|
+
*
|
|
4
|
+
* Runtime entry is `index.js` (the CJS bridge over `src/orm/index.ts`); this
|
|
5
|
+
* file restores the default export for `import orm from 'fib-orm'` while
|
|
6
|
+
* keeping every named export/types from the TS source.
|
|
7
|
+
*/
|
|
8
|
+
import * as orm from './src/orm/index';
|
|
9
|
+
|
|
10
|
+
export * from './src/orm/index';
|
|
11
|
+
export default orm;
|
package/index.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CommonJS bridge for fib-orm.
|
|
3
|
+
*
|
|
4
|
+
* `src/orm/index.ts` is an ESM TypeScript module with named exports only, so
|
|
5
|
+
* `import orm from 'fib-orm'` (the shape used by existing consumers) fails
|
|
6
|
+
* with "does not provide an export named 'default'". fibjs can load the TS
|
|
7
|
+
* entry from CJS, so this bridge keeps the historical `module.exports`
|
|
8
|
+
* namespace shape — same packaging idea as fib-flow's `lib/index.js`.
|
|
9
|
+
*
|
|
10
|
+
* Keep this a pass-through: the TS entry is a non-extensible module namespace,
|
|
11
|
+
* so a `default` shim cannot be added here. fibjs synthesizes the default for
|
|
12
|
+
* static imports of CJS modules; dynamic `import()` also returns a cached
|
|
13
|
+
* wrapper whose `default` is module.exports.
|
|
14
|
+
*/
|
|
15
|
+
module.exports = require('./src/orm/index.ts');
|
package/package.json
CHANGED
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fib-orm",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"description": "ORM for fibjs - unified package",
|
|
5
|
-
"main": "
|
|
6
|
-
"types": "
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"types": "index.d.ts",
|
|
7
7
|
"exports": {
|
|
8
|
-
".": "./
|
|
9
|
-
"./cli": "./
|
|
8
|
+
".": "./index.js",
|
|
9
|
+
"./cli": "./src/cli/index.ts"
|
|
10
|
+
},
|
|
11
|
+
"bin": {
|
|
12
|
+
"orm-cli": "src/cli/index.ts",
|
|
13
|
+
"orm": "src/cli/index.ts"
|
|
10
14
|
},
|
|
11
15
|
"repository": {
|
|
12
16
|
"type": "git",
|
|
@@ -14,7 +18,7 @@
|
|
|
14
18
|
},
|
|
15
19
|
"author": "fibjs",
|
|
16
20
|
"homepage": "https://github.com/fibjs/fib-orm",
|
|
17
|
-
"license": "
|
|
21
|
+
"license": "MIT",
|
|
18
22
|
"keywords": [
|
|
19
23
|
"orm",
|
|
20
24
|
"database",
|
|
@@ -22,51 +26,49 @@
|
|
|
22
26
|
"mysql",
|
|
23
27
|
"sqlite",
|
|
24
28
|
"postgres",
|
|
29
|
+
"kingbase",
|
|
30
|
+
"mssql",
|
|
31
|
+
"dm",
|
|
25
32
|
"redis"
|
|
26
33
|
],
|
|
27
34
|
"scripts": {
|
|
28
|
-
"build": "rm -rf ./lib && ftsc $(find src -name '*.ts' ! -name '*.d.ts' ! -path '*/plugins/*' | sort) --outDir ./lib && cp src/codepoints-map.json lib/codepoints-map.json && cp -r src/knex/deps lib/knex/deps",
|
|
29
35
|
"test": "fibjs test",
|
|
30
|
-
"ci": "npm run ci-sqlite",
|
|
31
|
-
"ci-mysql": "
|
|
32
|
-
"ci-sqlite": "
|
|
33
|
-
"ci-postgres": "
|
|
36
|
+
"ci": "npm run check:bridge && npm run ci-sqlite",
|
|
37
|
+
"ci-mysql": "cross-env ORM_PROTOCOL=mysql npm test",
|
|
38
|
+
"ci-sqlite": "cross-env ORM_PROTOCOL=sqlite npm test",
|
|
39
|
+
"ci-postgres": "cross-env ORM_PROTOCOL=psql npm test",
|
|
40
|
+
"ci-kingbase": "cross-env ORM_PROTOCOL=kingbase npm test",
|
|
41
|
+
"ci-mssql": "cross-env ORM_PROTOCOL=mssql npm test",
|
|
42
|
+
"ci-dm": "cross-env ORM_PROTOCOL=dm npm test",
|
|
43
|
+
"check": "fibjs --check",
|
|
44
|
+
"check:bridge": "fibjs --check --project test/bridge/tsconfig.json",
|
|
45
|
+
"test:smoke": "fibjs test/integration/db-smoke.js",
|
|
46
|
+
"test:bridge": "fibjs test/integration/commonjs-bridge.js",
|
|
47
|
+
"check:strict": "fibjs --check --project tsconfig.strict.json"
|
|
34
48
|
},
|
|
35
49
|
"dependencies": {
|
|
36
50
|
"@fibjs/enforce": "^0.1.1",
|
|
37
|
-
"
|
|
38
|
-
"
|
|
39
|
-
"
|
|
40
|
-
"
|
|
51
|
+
"cac": "^6.7.14",
|
|
52
|
+
"chalk": "^4.1.2",
|
|
53
|
+
"cli-spinners": "^2.9.2",
|
|
54
|
+
"diff": "^5.1.0",
|
|
41
55
|
"fib-cache": "^1.1.0",
|
|
42
|
-
"fib-kv": "^1.3.1",
|
|
43
56
|
"knex": "^2.5.1",
|
|
44
|
-
"
|
|
45
|
-
"
|
|
46
|
-
"lodash.merge": "^4.6.1",
|
|
47
|
-
"parse-querystring-dotkey": "^1.0.3",
|
|
48
|
-
"rxjs": "^6.5.2",
|
|
49
|
-
"@types/diff": "^5.0.2",
|
|
50
|
-
"@types/semver": "^7.3.10",
|
|
51
|
-
"diff": "^5.1.0",
|
|
52
|
-
"semver": "^7.3.7"
|
|
57
|
+
"log-update": "^4.0.0",
|
|
58
|
+
"ora": "^5.4.1"
|
|
53
59
|
},
|
|
54
60
|
"devDependencies": {
|
|
55
|
-
"@fibjs/types": "^0.35.0",
|
|
56
|
-
"@types/lodash.clonedeep": "^4.5.6",
|
|
57
|
-
"@types/lodash.flatten": "^4.4.6",
|
|
58
|
-
"@types/lodash.merge": "^4.6.6",
|
|
59
61
|
"cross-env": "^5.2.0",
|
|
60
|
-
"
|
|
61
|
-
"rimraf": "^3.0.2",
|
|
62
|
-
"ts-expect": "^1.3.0"
|
|
62
|
+
"should": "^13.2.3"
|
|
63
63
|
},
|
|
64
64
|
"engines": {
|
|
65
|
-
"fibjs": ">= 0.
|
|
65
|
+
"fibjs": ">= 0.38.0"
|
|
66
66
|
},
|
|
67
67
|
"private": false,
|
|
68
68
|
"files": [
|
|
69
|
-
"
|
|
69
|
+
"index.js",
|
|
70
|
+
"index.d.ts",
|
|
71
|
+
"src"
|
|
70
72
|
],
|
|
71
73
|
"publishConfig": {
|
|
72
74
|
"access": "public"
|
|
@@ -1,74 +1,88 @@
|
|
|
1
|
-
|
|
2
|
-
const
|
|
3
|
-
const
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
import { createRequire } from 'node:module';
|
|
2
|
+
const require = createRequire(import.meta.url);
|
|
3
|
+
const fs = require('fs');
|
|
4
|
+
const path = require('path');
|
|
5
|
+
const coroutine = require('coroutine');
|
|
6
|
+
import { wrapSubcommand } from '../wrapSubcommand';
|
|
7
|
+
|
|
8
|
+
import { Driver } from '../../db-driver/index';
|
|
9
|
+
import { Sync } from '../../sql-ddl-sync/index';
|
|
10
|
+
import { getAllTableNames, getTableDDLs } from '../helpers/ddl';
|
|
11
|
+
|
|
12
|
+
export default wrapSubcommand({
|
|
9
13
|
name: 'ddlFrom',
|
|
14
|
+
|
|
10
15
|
aliases: [
|
|
11
16
|
'ddlfrom'
|
|
12
17
|
],
|
|
18
|
+
|
|
13
19
|
inputs: {
|
|
14
20
|
required: '<connection>',
|
|
15
21
|
optional: [
|
|
16
22
|
'[tableName]'
|
|
17
23
|
]
|
|
18
24
|
},
|
|
25
|
+
|
|
19
26
|
examples: [
|
|
20
27
|
'orm ddlFrom mysql://root:@localhost:3306/test',
|
|
21
28
|
],
|
|
29
|
+
|
|
22
30
|
options: {
|
|
23
|
-
'-P, --pool [pool]': 'whether use connection pool or not',
|
|
24
31
|
'-O, --out [outPath]': 'path to output json file',
|
|
25
32
|
},
|
|
33
|
+
|
|
26
34
|
description: `read columns information from database, and generate ddl file`,
|
|
35
|
+
|
|
27
36
|
onAction: ([connection, [tableName]], options) => {
|
|
28
|
-
const driver =
|
|
29
|
-
const sync = new
|
|
30
|
-
|
|
37
|
+
const driver = Driver.create(connection);
|
|
38
|
+
const sync = new Sync({ dbdriver: driver });
|
|
39
|
+
|
|
40
|
+
let outJson: string = '';
|
|
31
41
|
if (options.out) {
|
|
32
|
-
if (options.out === true) {
|
|
33
|
-
outJson = `./${driver.type}-${
|
|
34
|
-
|
|
35
|
-
|
|
42
|
+
if ((options.out as any) === true) {
|
|
43
|
+
outJson = `./${driver.type}-${
|
|
44
|
+
driver.config.database!.replace(/[\.|\/]/g, '_')
|
|
45
|
+
}.json`;
|
|
46
|
+
} else if (typeof options.out === 'string') {
|
|
36
47
|
outJson = options.out;
|
|
37
48
|
}
|
|
49
|
+
|
|
38
50
|
if (outJson) {
|
|
39
51
|
outJson = path.resolve(process.cwd(), outJson);
|
|
40
52
|
}
|
|
41
53
|
}
|
|
42
|
-
|
|
54
|
+
|
|
55
|
+
let tableNames = [] as string[];
|
|
43
56
|
if (tableName) {
|
|
44
57
|
if (!sync.Dialect.hasCollectionSync(driver, tableName))
|
|
45
58
|
throw new Error(`[ddlFrom] table ${tableName} doen't exist!`);
|
|
59
|
+
|
|
46
60
|
tableNames = [tableName];
|
|
47
|
-
}
|
|
48
|
-
else {
|
|
61
|
+
} else {
|
|
49
62
|
switch (driver.type) {
|
|
50
63
|
case 'psql':
|
|
51
64
|
case 'mysql':
|
|
52
65
|
case 'sqlite':
|
|
53
|
-
tableNames =
|
|
66
|
+
tableNames = getAllTableNames(driver);
|
|
54
67
|
break;
|
|
55
68
|
default:
|
|
56
69
|
if (!tableName) {
|
|
57
|
-
throw new Error('[ddlFrom] tableName is required!')
|
|
70
|
+
throw new Error('[ddlFrom] tableName is required!')
|
|
58
71
|
}
|
|
59
72
|
tableNames = [tableName];
|
|
60
73
|
}
|
|
61
74
|
}
|
|
62
|
-
|
|
75
|
+
|
|
76
|
+
const tableDDLs = getTableDDLs(sync as any, { tableNames });
|
|
77
|
+
|
|
63
78
|
if (outJson) {
|
|
64
79
|
console.notice(`[ddlFrom] try to write to ${outJson}...`);
|
|
65
80
|
fs.mkdir(path.dirname(outJson), { recursive: true });
|
|
66
|
-
fs.writeFile(outJson, JSON.stringify(tableDDLs, null, 2));
|
|
81
|
+
fs.writeFile(outJson, JSON.stringify(tableDDLs, null, 2) as any);
|
|
67
82
|
console.notice(`[ddlFrom] write json to ${outJson} success!`);
|
|
68
|
-
}
|
|
69
|
-
else {
|
|
83
|
+
} else {
|
|
70
84
|
console.log('[ddlFrom] tableDDLs:');
|
|
71
85
|
console.log(JSON.stringify(tableDDLs, null, 2));
|
|
72
86
|
}
|
|
73
87
|
}
|
|
74
|
-
});
|
|
88
|
+
});
|
|
@@ -1,43 +1,57 @@
|
|
|
1
|
-
|
|
2
|
-
const
|
|
3
|
-
const
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
1
|
+
import { createRequire } from 'node:module';
|
|
2
|
+
const require = createRequire(import.meta.url);
|
|
3
|
+
const fs = require('fs');
|
|
4
|
+
const path = require('path');
|
|
5
|
+
import { wrapSubcommand } from '../wrapSubcommand';
|
|
6
|
+
|
|
7
|
+
import * as ORM from '../../orm/index';
|
|
8
|
+
import { Sync } from '../../sql-ddl-sync/index';
|
|
9
|
+
const Diff = require('diff');
|
|
10
|
+
|
|
11
|
+
import {getTableDDLs, type IModelProperties, type IRawColumns} from '../helpers/ddl';
|
|
12
|
+
|
|
13
|
+
type IModelFunc = (ORM: typeof import('../../orm/index')) => {
|
|
14
|
+
orm: import('../../orm/index').FxOrmNS.ORM
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
function alphaBetKeySort<T extends object>(obj: T) {
|
|
18
|
+
if (!obj) return obj;
|
|
12
19
|
return Object.keys(obj).sort().reduce((acc, key) => {
|
|
13
|
-
|
|
14
|
-
acc[key] = obj[key];
|
|
20
|
+
Object.assign(acc, { [key]: (obj as Record<string, unknown>)[key] });
|
|
15
21
|
return acc;
|
|
16
|
-
}, {});
|
|
22
|
+
}, {} as T);
|
|
17
23
|
}
|
|
18
|
-
|
|
24
|
+
|
|
25
|
+
export default wrapSubcommand({
|
|
19
26
|
name: 'dumpModel',
|
|
27
|
+
|
|
20
28
|
inputs: {
|
|
21
29
|
required: '<modelFile>',
|
|
22
30
|
optional: [
|
|
23
31
|
'[modelFile]'
|
|
24
32
|
]
|
|
25
33
|
},
|
|
34
|
+
|
|
26
35
|
examples: [],
|
|
36
|
+
|
|
27
37
|
options: {
|
|
28
38
|
'-O, --out [outPath]': 'path to output json file',
|
|
29
39
|
'--sync': 'sync user definition to database',
|
|
30
40
|
'--no-alphabet': 'sort properties alphabetically on patch',
|
|
31
41
|
},
|
|
42
|
+
|
|
32
43
|
description: `read columns information from database, and generate ddl file`,
|
|
44
|
+
|
|
33
45
|
onAction: ([modelFile], options) => {
|
|
34
46
|
modelFile = path.resolve(process.cwd(), modelFile);
|
|
35
47
|
const jsonDiffName = path.basename(modelFile, '.js') + '-dump.json';
|
|
36
48
|
const diffOutDir = path.dirname(modelFile);
|
|
37
49
|
const diffOutput = path.resolve(diffOutDir, jsonDiffName);
|
|
50
|
+
|
|
38
51
|
if (!fs.exists(modelFile)) {
|
|
39
52
|
throw new Error(`[dumpModel] model file not found: ${modelFile}`);
|
|
40
53
|
}
|
|
54
|
+
|
|
41
55
|
let modelFunc = require(modelFile);
|
|
42
56
|
if (typeof modelFunc !== 'function') {
|
|
43
57
|
if (typeof modelFunc.default === 'function')
|
|
@@ -46,61 +60,94 @@ exports.default = (0, make_cli_1.wrapSubcommand)({
|
|
|
46
60
|
if (typeof modelFunc !== 'function') {
|
|
47
61
|
throw new Error(`[dumpModel] model function not found, it's typeof ${typeof modelFunc}`);
|
|
48
62
|
}
|
|
49
|
-
|
|
63
|
+
|
|
64
|
+
const { orm } = (modelFunc as IModelFunc)(ORM);
|
|
65
|
+
|
|
50
66
|
if (options.sync) {
|
|
51
67
|
orm.syncSync();
|
|
52
68
|
}
|
|
53
|
-
|
|
54
|
-
const
|
|
55
|
-
const
|
|
69
|
+
|
|
70
|
+
const sync = new Sync({ dbdriver: orm.driver.sqlDriver });
|
|
71
|
+
const modelReports: Record<string, {
|
|
72
|
+
userDefinedProperties: IModelProperties,
|
|
73
|
+
dataStoreProperties: IModelProperties
|
|
74
|
+
dataStoreRaw: IRawColumns
|
|
75
|
+
propritiesDiff: {
|
|
76
|
+
name: string,
|
|
77
|
+
mapsTo: string,
|
|
78
|
+
changes: any[] | null,
|
|
79
|
+
patch: string
|
|
80
|
+
}[]
|
|
81
|
+
}> = {}
|
|
82
|
+
const modelByTable: typeof orm.models = {}
|
|
56
83
|
for (let k in orm.models) {
|
|
57
84
|
const model = orm.models[k];
|
|
58
85
|
modelByTable[model.table] = model;
|
|
59
86
|
}
|
|
60
|
-
|
|
87
|
+
|
|
88
|
+
getTableDDLs(sync, {
|
|
61
89
|
afterGetTableDDL: (ddl) => {
|
|
62
|
-
|
|
63
|
-
const userDefinedProperties = ((_a = modelByTable[ddl.collection]) === null || _a === void 0 ? void 0 : _a.allProperties) || {};
|
|
90
|
+
const userDefinedProperties = modelByTable[ddl.collection]?.allProperties || {};
|
|
64
91
|
const dataStoreProperties = ddl.properties;
|
|
92
|
+
|
|
65
93
|
const tPatchBaseName = `properties-for-t-[${ddl.collection}]`;
|
|
66
94
|
const tablePatchFile = path.resolve(diffOutDir, `./${tPatchBaseName}.patch`);
|
|
95
|
+
|
|
67
96
|
const propritiesDiff = Object.entries(dataStoreProperties).reduce((accu, [mapsTo, prop]) => {
|
|
68
97
|
let udP = userDefinedProperties[mapsTo] || null;
|
|
69
98
|
if (options.alphabet) {
|
|
70
99
|
udP = alphaBetKeySort(udP);
|
|
71
100
|
userDefinedProperties[mapsTo] = udP;
|
|
101
|
+
|
|
72
102
|
prop = alphaBetKeySort(prop);
|
|
73
103
|
dataStoreProperties[mapsTo] = prop;
|
|
74
104
|
}
|
|
105
|
+
|
|
75
106
|
const changes = Diff.diffJson(udP, prop);
|
|
76
107
|
const patchBaseName = `${tPatchBaseName}-p-${mapsTo}`;
|
|
77
|
-
const patch = Diff.createTwoFilesPatch(
|
|
108
|
+
const patch = Diff.createTwoFilesPatch(
|
|
109
|
+
`${patchBaseName}-from-database.json`,
|
|
110
|
+
`${patchBaseName}-user-defined.json`,
|
|
111
|
+
JSON.stringify(prop, null, 2),
|
|
112
|
+
JSON.stringify(udP, null, 2),
|
|
113
|
+
);
|
|
114
|
+
|
|
78
115
|
accu.push({
|
|
79
116
|
name: mapsTo,
|
|
80
117
|
mapsTo,
|
|
81
118
|
changes,
|
|
82
119
|
patch
|
|
83
120
|
});
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
121
|
+
|
|
122
|
+
return accu
|
|
123
|
+
}, [] as any[])
|
|
124
|
+
|
|
125
|
+
const patch = Diff.createTwoFilesPatch(
|
|
126
|
+
`${tPatchBaseName}-from-database.json`,
|
|
127
|
+
`${tPatchBaseName}-user-defined.json`,
|
|
128
|
+
JSON.stringify(dataStoreProperties, null, 2),
|
|
129
|
+
JSON.stringify(userDefinedProperties, null, 2),
|
|
130
|
+
);
|
|
131
|
+
fs.writeFile(tablePatchFile, patch as any);
|
|
132
|
+
|
|
88
133
|
modelReports[ddl.collection] = {
|
|
89
134
|
propritiesDiff,
|
|
90
135
|
userDefinedProperties,
|
|
91
136
|
dataStoreProperties,
|
|
92
137
|
dataStoreRaw: ddl.rawColumns,
|
|
93
|
-
}
|
|
138
|
+
}
|
|
94
139
|
}
|
|
95
140
|
});
|
|
141
|
+
|
|
96
142
|
const dumpObj = {
|
|
97
143
|
connection: sync.dbdriver.uri,
|
|
98
144
|
driverType: sync.dbdriver.type,
|
|
99
145
|
modelReports,
|
|
100
|
-
}
|
|
146
|
+
}
|
|
147
|
+
|
|
101
148
|
console.notice(`[dumpModel] try to write to ${diffOutput}...`);
|
|
102
149
|
fs.mkdir(path.dirname(diffOutput), { recursive: true });
|
|
103
|
-
fs.writeFile(diffOutput, JSON.stringify(dumpObj, null, 2));
|
|
150
|
+
fs.writeFile(diffOutput, JSON.stringify(dumpObj, null, 2) as any);
|
|
104
151
|
console.notice(`[dumpModel] write json to ${diffOutput} success!`);
|
|
105
152
|
}
|
|
106
|
-
});
|
|
153
|
+
});
|
|
@@ -1,68 +1,91 @@
|
|
|
1
|
-
|
|
1
|
+
import { createRequire } from 'node:module';
|
|
2
|
+
const require = createRequire(import.meta.url);
|
|
2
3
|
// import fs = require('fs');
|
|
3
4
|
// import path = require('path');
|
|
4
5
|
// import coroutine = require('coroutine');
|
|
5
|
-
const chalk = require(
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
const
|
|
6
|
+
const chalk = require('chalk');
|
|
7
|
+
import { wrapSubcommand } from '../wrapSubcommand';
|
|
8
|
+
|
|
9
|
+
import {Query, type FxSqlQueryDialect} from '../../sql-query/Query';
|
|
10
|
+
|
|
11
|
+
const VALID_DIALECTS = ['mysql', 'sqlite', 'postgresql', 'mssql', 'dm'] as const;
|
|
12
|
+
const VALID_TYPES = ['sql', 'val', 'id'] as const;
|
|
13
|
+
|
|
14
|
+
const cmd = wrapSubcommand({
|
|
11
15
|
name: 'escapeSQL',
|
|
16
|
+
|
|
12
17
|
aliases: [
|
|
13
18
|
'escape'
|
|
14
19
|
],
|
|
20
|
+
|
|
15
21
|
inputs: {
|
|
16
22
|
required: '<sqlstring>',
|
|
17
23
|
rest: '[...args]'
|
|
18
24
|
},
|
|
25
|
+
|
|
19
26
|
examples: [],
|
|
27
|
+
|
|
20
28
|
options: {
|
|
21
29
|
'-d, --dialect-type [dialectType]': `dialect type, support ${VALID_DIALECTS.map(d => `'${d}'`).join(', ')}`,
|
|
22
30
|
'-t, --type [escapeType]': `escape type, support ${VALID_TYPES.map(t => `'${t}'`).join(', ')}`,
|
|
23
31
|
},
|
|
32
|
+
|
|
24
33
|
description: `escape SQL string with given arguments`,
|
|
34
|
+
|
|
25
35
|
onAction: ([sqlstring, , rest], options) => {
|
|
26
|
-
const dialectType = options.dialectType || 'mysql';
|
|
36
|
+
const dialectType = options.dialectType as FxSqlQueryDialect.DialectType || 'mysql';
|
|
27
37
|
if (!VALID_DIALECTS.includes(dialectType)) {
|
|
28
38
|
throw new Error(`[escape] invalid dialect type: ${dialectType}`);
|
|
29
39
|
}
|
|
30
|
-
|
|
40
|
+
|
|
41
|
+
const escapeType = options.type as typeof VALID_TYPES[number] || 'sql';
|
|
31
42
|
if (!VALID_TYPES.includes(escapeType)) {
|
|
32
43
|
throw new Error(`[escape] invalid escape type: ${escapeType}`);
|
|
33
44
|
}
|
|
34
|
-
|
|
35
|
-
|
|
45
|
+
|
|
46
|
+
VALID_TYPES
|
|
47
|
+
const query = new Query({ dialect: dialectType });
|
|
48
|
+
|
|
36
49
|
switch (escapeType) {
|
|
37
50
|
default:
|
|
38
51
|
case 'sql': {
|
|
39
52
|
const result = query.escape(sqlstring, rest);
|
|
40
|
-
|
|
41
|
-
console.log(`
|
|
42
|
-
console.log()
|
|
43
|
-
console.log(
|
|
44
|
-
|
|
45
|
-
|
|
53
|
+
|
|
54
|
+
console.log(`dialect-type: ${chalk.blue(dialectType)}`)
|
|
55
|
+
console.log(`args(${rest.length}): ${chalk.blue(rest.join(' '))}`)
|
|
56
|
+
console.log()
|
|
57
|
+
|
|
58
|
+
console.log(`input-sql: \t ${chalk.yellow(sqlstring)}`)
|
|
59
|
+
|
|
60
|
+
console.log(`escaped-sql:\t ${chalk.green(result)}`)
|
|
61
|
+
break
|
|
46
62
|
}
|
|
47
63
|
case 'val': {
|
|
48
64
|
const result = query.escapeVal(sqlstring);
|
|
49
|
-
|
|
65
|
+
|
|
66
|
+
console.log(`dialect-type: ${chalk.blue(dialectType)}`)
|
|
50
67
|
// console.log(`args(${rest.length}): ${chalk.blue(rest.join(' '))}`)
|
|
51
|
-
console.log()
|
|
52
|
-
|
|
53
|
-
console.log(`
|
|
54
|
-
|
|
68
|
+
console.log()
|
|
69
|
+
|
|
70
|
+
console.log(`input-value: \t ${chalk.yellow(sqlstring)}`)
|
|
71
|
+
|
|
72
|
+
console.log(`escaped-value:\t ${chalk.green(result)}`)
|
|
73
|
+
break
|
|
55
74
|
}
|
|
56
75
|
case 'id': {
|
|
57
76
|
const result = query.escapeId(sqlstring);
|
|
58
|
-
|
|
77
|
+
|
|
78
|
+
console.log(`dialect-type: ${chalk.blue(dialectType)}`)
|
|
59
79
|
// console.log(`args(${rest.length}): ${chalk.blue(rest.join(' '))}`)
|
|
60
|
-
console.log()
|
|
61
|
-
|
|
62
|
-
console.log(`
|
|
63
|
-
|
|
80
|
+
console.log()
|
|
81
|
+
|
|
82
|
+
console.log(`input-id: \t ${chalk.yellow(sqlstring)}`)
|
|
83
|
+
|
|
84
|
+
console.log(`escaped-id:\t ${chalk.green(result)}`)
|
|
85
|
+
break
|
|
64
86
|
}
|
|
65
87
|
}
|
|
66
88
|
}
|
|
67
89
|
});
|
|
68
|
-
|
|
90
|
+
|
|
91
|
+
export default cmd;
|