fib-orm 2.1.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 +37 -34
- package/{lib/cli/commands/ddlFrom.js → src/cli/commands/ddlFrom.ts} +40 -27
- package/{lib/cli/commands/dumpModel.js → src/cli/commands/dumpModel.ts} +78 -32
- package/{lib/cli/commands/escape.js → src/cli/commands/escape.ts} +51 -29
- package/{lib/cli/commands/spinner.js → src/cli/commands/spinner.ts} +20 -11
- package/{lib/cli/commands/upgrade.js → src/cli/commands/upgrade.ts} +53 -34
- 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 -86
- 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 -174
- 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 -69
- 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 -22
- 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 -2
- 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 -25
- package/lib/cli/helpers/package.js +0 -56
- package/lib/cli/index.d.ts +0 -2
- package/lib/cli/index.js +0 -19
- package/lib/db-driver/Typo.d.ts +0 -111
- package/lib/db-driver/Typo.js +0 -2
- package/lib/db-driver/built-ins/base.class.d.ts +0 -91
- package/lib/db-driver/built-ins/base.class.js +0 -187
- package/lib/db-driver/built-ins/driver-dm.d.ts +0 -17
- package/lib/db-driver/built-ins/driver-dm.js +0 -54
- package/lib/db-driver/built-ins/driver-mongodb.d.ts +0 -23
- package/lib/db-driver/built-ins/driver-mongodb.js +0 -47
- package/lib/db-driver/built-ins/driver-mysql.d.ts +0 -17
- package/lib/db-driver/built-ins/driver-mysql.js +0 -38
- package/lib/db-driver/built-ins/driver-postgresql.d.ts +0 -21
- package/lib/db-driver/built-ins/driver-postgresql.js +0 -77
- package/lib/db-driver/built-ins/driver-redis.d.ts +0 -11
- package/lib/db-driver/built-ins/driver-redis.js +0 -36
- package/lib/db-driver/built-ins/driver-sqlite.d.ts +0 -16
- package/lib/db-driver/built-ins/driver-sqlite.js +0 -35
- package/lib/db-driver/index.d.ts +0 -3
- package/lib/db-driver/index.js +0 -5
- 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 -4
- package/lib/knex/sandbox.d.ts +0 -4
- package/lib/knex/sandbox.js +0 -23
- 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 -177
- 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 -16
- 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 -14
- package/lib/orm/Associations/_utils.js +0 -53
- package/lib/orm/ChainFind.d.ts +0 -3
- package/lib/orm/ChainFind.js +0 -328
- package/lib/orm/ChainInstance.d.ts +0 -6
- package/lib/orm/ChainInstance.js +0 -74
- package/lib/orm/Debug.d.ts +0 -2
- package/lib/orm/Debug.js +0 -17
- package/lib/orm/Drivers/DB/base.d.ts +0 -2
- package/lib/orm/Drivers/DB/base.js +0 -4
- package/lib/orm/Drivers/DB/dm.d.ts +0 -9
- package/lib/orm/Drivers/DB/dm.js +0 -24
- package/lib/orm/Drivers/DB/mysql.d.ts +0 -9
- package/lib/orm/Drivers/DB/mysql.js +0 -24
- package/lib/orm/Drivers/DB/postgres.d.ts +0 -9
- package/lib/orm/Drivers/DB/postgres.js +0 -23
- package/lib/orm/Drivers/DB/sqlite3.d.ts +0 -14
- package/lib/orm/Drivers/DB/sqlite3.js +0 -40
- package/lib/orm/Drivers/DML/_ddl-sql.d.ts +0 -3
- package/lib/orm/Drivers/DML/_ddl-sql.js +0 -52
- 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 -39
- 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 -3
- 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 -7
- package/lib/orm/Drivers/DML/mysql.d.ts +0 -2
- package/lib/orm/Drivers/DML/mysql.js +0 -252
- package/lib/orm/Drivers/DML/postgres.d.ts +0 -2
- package/lib/orm/Drivers/DML/postgres.js +0 -277
- package/lib/orm/Drivers/DML/sqlite.d.ts +0 -2
- package/lib/orm/Drivers/DML/sqlite.js +0 -267
- package/lib/orm/Error.d.ts +0 -11
- package/lib/orm/Error.js +0 -41
- package/lib/orm/Helpers.d.ts +0 -35
- package/lib/orm/Helpers.js +0 -234
- package/lib/orm/Hook.d.ts +0 -13
- package/lib/orm/Hook.js +0 -100
- package/lib/orm/Instance.d.ts +0 -2
- package/lib/orm/Instance.js +0 -698
- package/lib/orm/LazyLoad.d.ts +0 -4
- package/lib/orm/LazyLoad.js +0 -76
- package/lib/orm/Model.d.ts +0 -6
- package/lib/orm/Model.js +0 -974
- package/lib/orm/ORM.d.ts +0 -37
- package/lib/orm/ORM.js +0 -242
- 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 -14
- 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 -120
- package/lib/orm/Singleton.d.ts +0 -5
- package/lib/orm/Singleton.js +0 -73
- package/lib/orm/Typo/Adapter.d.ts +0 -5
- package/lib/orm/Typo/Adapter.js +0 -2
- package/lib/orm/Typo/DMLDriver.d.ts +0 -209
- package/lib/orm/Typo/DMLDriver.js +0 -2
- package/lib/orm/Typo/Db.d.ts +0 -35
- package/lib/orm/Typo/Db.js +0 -2
- package/lib/orm/Typo/Error.d.ts +0 -29
- package/lib/orm/Typo/Error.js +0 -2
- package/lib/orm/Typo/ORM.d.ts +0 -231
- package/lib/orm/Typo/ORM.js +0 -4
- package/lib/orm/Typo/Validators.d.ts +0 -31
- package/lib/orm/Typo/Validators.js +0 -3
- package/lib/orm/Typo/_common.d.ts +0 -37
- package/lib/orm/Typo/_common.js +0 -2
- package/lib/orm/Typo/assoc.d.ts +0 -221
- package/lib/orm/Typo/assoc.js +0 -2
- package/lib/orm/Typo/hook.d.ts +0 -42
- package/lib/orm/Typo/hook.js +0 -2
- package/lib/orm/Typo/instance.d.ts +0 -156
- package/lib/orm/Typo/instance.js +0 -2
- package/lib/orm/Typo/model.js +0 -7
- package/lib/orm/Typo/patch.d.ts +0 -31
- package/lib/orm/Typo/patch.js +0 -2
- package/lib/orm/Typo/property.d.ts +0 -57
- package/lib/orm/Typo/property.js +0 -2
- package/lib/orm/Typo/query.d.ts +0 -216
- package/lib/orm/Typo/query.js +0 -2
- package/lib/orm/Typo/settings.js +0 -6
- package/lib/orm/Typo/synchronous.js +0 -2
- package/lib/orm/Utilities.d.ts +0 -178
- package/lib/orm/Utilities.js +0 -975
- package/lib/orm/Validators.d.ts +0 -33
- package/lib/orm/Validators.js +0 -101
- 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 -67
- package/lib/orm/index.js +0 -158
- package/lib/orm-core/callback.d.ts +0 -12
- package/lib/orm-core/callback.js +0 -2
- package/lib/orm-core/dialect.js +0 -2
- package/lib/orm-core/error.d.ts +0 -16
- package/lib/orm-core/error.js +0 -29
- package/lib/orm-core/index.js +0 -7
- package/lib/orm-core/sync.d.ts +0 -12
- package/lib/orm-core/sync.js +0 -2
- package/lib/orm-core/utils.d.ts +0 -1
- package/lib/orm-core/utils.js +0 -6
- package/lib/orm-property/Property.d.ts +0 -78
- package/lib/orm-property/Property.js +0 -2
- 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 -23
- 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 -6
- package/lib/orm-property/transformers/mysql.d.ts +0 -101
- package/lib/orm-property/transformers/mysql.js +0 -262
- package/lib/orm-property/transformers/postgresql.d.ts +0 -54
- package/lib/orm-property/transformers/postgresql.js +0 -190
- package/lib/orm-property/transformers/sqlite.d.ts +0 -19
- package/lib/orm-property/transformers/sqlite.js +0 -172
- package/lib/sql-ddl-sync/Dialects/dm.d.ts +0 -39
- package/lib/sql-ddl-sync/Dialects/dm.js +0 -297
- package/lib/sql-ddl-sync/Dialects/index.d.ts +0 -6
- package/lib/sql-ddl-sync/Dialects/index.js +0 -8
- package/lib/sql-ddl-sync/Dialects/mysql.d.ts +0 -38
- package/lib/sql-ddl-sync/Dialects/mysql.js +0 -241
- package/lib/sql-ddl-sync/Dialects/postgresql.d.ts +0 -39
- package/lib/sql-ddl-sync/Dialects/postgresql.js +0 -287
- package/lib/sql-ddl-sync/Dialects/sqlite.d.ts +0 -43
- package/lib/sql-ddl-sync/Dialects/sqlite.js +0 -257
- 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 -2
- package/lib/sql-ddl-sync/Typo/DbIndex.d.ts +0 -13
- package/lib/sql-ddl-sync/Typo/DbIndex.js +0 -2
- package/lib/sql-ddl-sync/Typo/Dialect.js +0 -2
- package/lib/sql-ddl-sync/Typo/Driver.d.ts +0 -53
- package/lib/sql-ddl-sync/Typo/Driver.js +0 -2
- package/lib/sql-ddl-sync/Typo/Query.d.ts +0 -7
- package/lib/sql-ddl-sync/Typo/Query.js +0 -2
- package/lib/sql-ddl-sync/Typo/SQL.d.ts +0 -31
- package/lib/sql-ddl-sync/Typo/SQL.js +0 -2
- package/lib/sql-ddl-sync/Typo/_common.d.ts +0 -29
- package/lib/sql-ddl-sync/Typo/_common.js +0 -2
- package/lib/sql-ddl-sync/Utils.d.ts +0 -39
- 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 -372
- package/lib/sql-query/Comparators.d.ts +0 -3
- package/lib/sql-query/Comparators.js +0 -95
- package/lib/sql-query/Create.d.ts +0 -35
- package/lib/sql-query/Create.js +0 -78
- package/lib/sql-query/Dialects/dm.d.ts +0 -3
- package/lib/sql-query/Dialects/index.js +0 -13
- package/lib/sql-query/Dialects/mssql.d.ts +0 -3
- package/lib/sql-query/Dialects/mssql.js +0 -74
- package/lib/sql-query/Dialects/mysql.d.ts +0 -3
- package/lib/sql-query/Dialects/mysql.js +0 -101
- package/lib/sql-query/Dialects/postgresql.d.ts +0 -3
- package/lib/sql-query/Dialects/postgresql.js +0 -77
- package/lib/sql-query/Dialects/sqlite.d.ts +0 -3
- package/lib/sql-query/Dialects/sqlite.js +0 -62
- package/lib/sql-query/Helpers.d.ts +0 -37
- package/lib/sql-query/Helpers.js +0 -260
- package/lib/sql-query/Insert.d.ts +0 -12
- package/lib/sql-query/Insert.js +0 -34
- package/lib/sql-query/Query.d.ts +0 -28
- package/lib/sql-query/Query.js +0 -120
- package/lib/sql-query/Remove.d.ts +0 -16
- package/lib/sql-query/Remove.js +0 -94
- package/lib/sql-query/Select.d.ts +0 -62
- package/lib/sql-query/Select.js +0 -534
- 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 -2
- package/lib/sql-query/Typo/Comparators.d.ts +0 -140
- package/lib/sql-query/Typo/Comparators.js +0 -2
- package/lib/sql-query/Typo/Dialect.d.ts +0 -39
- package/lib/sql-query/Typo/Dialect.js +0 -2
- package/lib/sql-query/Typo/Field.d.ts +0 -8
- package/lib/sql-query/Typo/Field.js +0 -2
- package/lib/sql-query/Typo/Helper.d.ts +0 -4
- package/lib/sql-query/Typo/Helper.js +0 -2
- package/lib/sql-query/Typo/Query-ChainBuilder.d.ts +0 -80
- package/lib/sql-query/Typo/Query-ChainBuilder.js +0 -2
- package/lib/sql-query/Typo/Query.d.ts +0 -34
- package/lib/sql-query/Typo/Query.js +0 -17
- package/lib/sql-query/Typo/Sql.d.ts +0 -143
- package/lib/sql-query/Typo/Sql.js +0 -2
- package/lib/sql-query/Typo/SubQuery.d.ts +0 -39
- package/lib/sql-query/Typo/SubQuery.js +0 -2
- package/lib/sql-query/Typo/index.js +0 -2
- package/lib/sql-query/Update.d.ts +0 -15
- package/lib/sql-query/Update.js +0 -39
- 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,260 @@
|
|
|
1
|
+
import { createRequire } from 'node:module';
|
|
2
|
+
const require = createRequire(import.meta.url);
|
|
3
|
+
const url = require('url');
|
|
4
|
+
const assert = require('assert');
|
|
5
|
+
const coroutine = require('coroutine');
|
|
6
|
+
import * as Utils from '../utils';
|
|
7
|
+
import type { FxDbDriverNS } from '../Typo';
|
|
8
|
+
import type { FxOrmCoreCallbackNS } from '../../orm-core/index';
|
|
9
|
+
|
|
10
|
+
function getDriver (name: 'mysql'): typeof import('./driver-mysql').default
|
|
11
|
+
function getDriver (name: 'psql' | 'postgresql' | 'pg' | 'kingbase'): typeof import('./driver-postgresql').default
|
|
12
|
+
function getDriver (name: 'sqlite'): typeof import('./driver-sqlite').default
|
|
13
|
+
function getDriver (name: 'redis'): typeof import('./driver-redis').default
|
|
14
|
+
function getDriver (name: 'dm'): typeof import('./driver-dm').default
|
|
15
|
+
function getDriver (name: 'mssql'): typeof import('./driver-mssql').default
|
|
16
|
+
function getDriver (name: FxDbDriverNS.DriverType | string) {
|
|
17
|
+
switch (name) {
|
|
18
|
+
case 'dm':
|
|
19
|
+
return require('./driver-dm').default
|
|
20
|
+
case 'mssql':
|
|
21
|
+
return require('./driver-mssql').default
|
|
22
|
+
case 'mysql':
|
|
23
|
+
return require('./driver-mysql').default
|
|
24
|
+
case 'postgresql':
|
|
25
|
+
case 'postgres':
|
|
26
|
+
case 'pg':
|
|
27
|
+
case 'psql':
|
|
28
|
+
case 'kingbase':
|
|
29
|
+
return require('./driver-postgresql').default
|
|
30
|
+
case 'sqlite':
|
|
31
|
+
return require('./driver-sqlite').default
|
|
32
|
+
case 'redis':
|
|
33
|
+
return require('./driver-redis').default
|
|
34
|
+
default:
|
|
35
|
+
if (name) {
|
|
36
|
+
const type = Utils.filterDriverType(url.parse(name).protocol)
|
|
37
|
+
if (type !== 'unknown')
|
|
38
|
+
return getDriver(type as any)
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// throw new Error(`[feature] driver type ${name} is not supported`)
|
|
42
|
+
return Driver;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export declare namespace Driver {
|
|
47
|
+
export type IConnTypeEnum = Class_DbConnection | Class_Redis;
|
|
48
|
+
type IClass_PostgreSQL = Class_DbConnection;
|
|
49
|
+
type IClass_MSSQL = Class_DbConnection;
|
|
50
|
+
export type ISQLConn = IClass_PostgreSQL | IClass_MSSQL | Class_SQLite | Class_MySQL;
|
|
51
|
+
|
|
52
|
+
export type ITypedDriver<T extends IConnTypeEnum = IConnTypeEnum> =
|
|
53
|
+
T extends ISQLConn ? SQLDriver<T>
|
|
54
|
+
: T extends Class_Redis ? import('./driver-redis').default
|
|
55
|
+
: Driver<T>
|
|
56
|
+
|
|
57
|
+
export type ISQLDriver = ITypedDriver<ISQLConn>
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export class Driver<CONN_TYPE extends Driver.IConnTypeEnum = Driver.IConnTypeEnum> {
|
|
61
|
+
static getDriver = getDriver;
|
|
62
|
+
|
|
63
|
+
static create (input: FxDbDriverNS.ConnectionInputArgs | string) {
|
|
64
|
+
const driver = Driver.getDriver(
|
|
65
|
+
typeof input === 'object' ? input.protocol : input as any
|
|
66
|
+
)
|
|
67
|
+
|
|
68
|
+
return new driver(input);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* @descritpin there's a bug in fibjs <= 0.35.x, only string type `field` would be
|
|
73
|
+
* used by `url.format`
|
|
74
|
+
*/
|
|
75
|
+
static formatUrl (input: FxDbDriverNS.ConnectionInputArgs) {
|
|
76
|
+
let protocol = input.protocol;
|
|
77
|
+
// some user would like add // after valid protocol like `http:`, `mysql:`
|
|
78
|
+
if (protocol?.endsWith('//')) protocol = protocol.slice(0, -2)
|
|
79
|
+
|
|
80
|
+
return url.format({
|
|
81
|
+
...input,
|
|
82
|
+
protocol,
|
|
83
|
+
// there's a bug in fibjs <= 0.35.x, only string type `field` would be
|
|
84
|
+
// used by `url.format`
|
|
85
|
+
...!!input.port && { port: input.port + '' }
|
|
86
|
+
})
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
readonly uid!: string;
|
|
90
|
+
get uri () {
|
|
91
|
+
const isSQLite = this.config.protocol === 'sqlite:';
|
|
92
|
+
return Driver.formatUrl({
|
|
93
|
+
...this.config,
|
|
94
|
+
...this.type === 'psql' && {
|
|
95
|
+
protocol: this.config.protocol === 'kingbase:' ? 'kingbase:' : 'psql:'
|
|
96
|
+
},
|
|
97
|
+
slashes: isSQLite ? false : this.config.slashes,
|
|
98
|
+
query: isSQLite ? {} : this.config.query
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
readonly config!: FxDbDriverNS.DBConnectionConfig;
|
|
102
|
+
readonly extend_config: Record<string, any> & FxDbDriverNS.DriverBuiltInExtConfig = {
|
|
103
|
+
debug: false
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
type: FxDbDriverNS.DriverType;
|
|
107
|
+
|
|
108
|
+
connection!: CONN_TYPE;
|
|
109
|
+
|
|
110
|
+
get isSql () {
|
|
111
|
+
const p = this.config.protocol || ''
|
|
112
|
+
|
|
113
|
+
return (
|
|
114
|
+
(p === 'mysql:')
|
|
115
|
+
|| (p === 'mssql:')
|
|
116
|
+
|| (p === 'psql:')
|
|
117
|
+
|| (p === 'kingbase:')
|
|
118
|
+
|| (p === 'dm:')
|
|
119
|
+
|| (p.startsWith('sqlite:'))
|
|
120
|
+
)
|
|
121
|
+
}
|
|
122
|
+
get isCommand () {
|
|
123
|
+
const p = this.config.protocol || ''
|
|
124
|
+
|
|
125
|
+
return p === 'redis:'
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
constructor (
|
|
129
|
+
options: FxDbDriverNS.ConnectionInputArgs | string
|
|
130
|
+
) {
|
|
131
|
+
// options would be replaced, `Utils.parseConnectionString` return a fresh object
|
|
132
|
+
options = Utils.parseConnectionString( options )
|
|
133
|
+
Object.defineProperty(this, 'config', { get () { return options } })
|
|
134
|
+
assert.ok(!!this.config.protocol, '[driver.config] invalid protocol')
|
|
135
|
+
|
|
136
|
+
// some db has no host
|
|
137
|
+
switch (options.protocol) {
|
|
138
|
+
default: break;
|
|
139
|
+
case 'mysql:':
|
|
140
|
+
case 'mssql:':
|
|
141
|
+
case 'postgresql:':
|
|
142
|
+
case 'kingbase:':
|
|
143
|
+
case 'dm:':
|
|
144
|
+
assert.ok(!!this.config.host || !!this.config.hostname, '[driver.config] host or hostname required')
|
|
145
|
+
break;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
this.type = Utils.filterDriverType(this.config.protocol);
|
|
149
|
+
|
|
150
|
+
const extend_config = {} as Driver['extend_config']
|
|
151
|
+
Object.defineProperty(this, 'extend_config', { get () { return extend_config } })
|
|
152
|
+
|
|
153
|
+
extend_config.debug = Utils.castQueryStringToBoolean(options.query?.debug)
|
|
154
|
+
|
|
155
|
+
Object.defineProperty(this, 'uid', { value: Utils.driverUUid(), writable: false, configurable: false })
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* @description switch to another database, pointless for some databases such as sqlite
|
|
160
|
+
* @param targetDb
|
|
161
|
+
*/
|
|
162
|
+
switchDb (targetDb: string): void {
|
|
163
|
+
this.currentDb = targetDb;
|
|
164
|
+
};
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* @description re open db connection
|
|
169
|
+
*/
|
|
170
|
+
reopen () {
|
|
171
|
+
try { this.close() } catch (error) {}
|
|
172
|
+
return this.open()
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* @description open db connection
|
|
178
|
+
*/
|
|
179
|
+
open (): CONN_TYPE {
|
|
180
|
+
return this.connection = this.getConnection()
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* @description close db connection
|
|
186
|
+
*/
|
|
187
|
+
close (): void {}
|
|
188
|
+
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* @description some db connection has `ping` method
|
|
192
|
+
*/
|
|
193
|
+
ping (): void {}
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* @description get connection instance but don't change internal status
|
|
197
|
+
*/
|
|
198
|
+
getConnection (): CONN_TYPE { throw new Error('[driver] getConnection is not implemented') }
|
|
199
|
+
|
|
200
|
+
useTrans (callback: (conn_for_trans: CONN_TYPE) => any) {
|
|
201
|
+
const conn = this.getConnection() as any;
|
|
202
|
+
if (typeof conn.trans === 'function') {
|
|
203
|
+
const waitor = {
|
|
204
|
+
ev: new (coroutine.Event)(),
|
|
205
|
+
result: <any>undefined
|
|
206
|
+
}
|
|
207
|
+
conn.trans(() => {
|
|
208
|
+
waitor.result = callback(conn)
|
|
209
|
+
waitor.ev.set()
|
|
210
|
+
})
|
|
211
|
+
waitor.ev.wait()
|
|
212
|
+
|
|
213
|
+
return waitor.result
|
|
214
|
+
} else {
|
|
215
|
+
return callback(conn)
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
[sync_method: string]: any
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
export class SQLDriver<CONN_TYPE extends Driver.IConnTypeEnum> extends Driver<CONN_TYPE> implements FxDbDriverNS.SQLDriver {
|
|
223
|
+
constructor (opts: FxDbDriverNS.ConnectionInputArgs | string) {
|
|
224
|
+
super(opts)
|
|
225
|
+
const options = Utils.parseConnectionString(opts)
|
|
226
|
+
|
|
227
|
+
this.extend_config.debug_sql = Utils.castQueryStringToBoolean(options.query?.debug_sql)
|
|
228
|
+
}
|
|
229
|
+
currentDb: FxDbDriverNS.SQLDriver['currentDb'] = null as any;
|
|
230
|
+
|
|
231
|
+
/**
|
|
232
|
+
* @override
|
|
233
|
+
*/
|
|
234
|
+
dbExists(dbname: string): boolean { return false };
|
|
235
|
+
|
|
236
|
+
/**
|
|
237
|
+
* @override
|
|
238
|
+
*/
|
|
239
|
+
begin (): void {}
|
|
240
|
+
|
|
241
|
+
/**
|
|
242
|
+
* @override
|
|
243
|
+
*/
|
|
244
|
+
commit (): void {}
|
|
245
|
+
|
|
246
|
+
/**
|
|
247
|
+
* @override
|
|
248
|
+
*/
|
|
249
|
+
trans <T> (cb: FxOrmCoreCallbackNS.ExecutionCallback<T>): boolean { return true; }
|
|
250
|
+
|
|
251
|
+
/**
|
|
252
|
+
* @override
|
|
253
|
+
*/
|
|
254
|
+
rollback (): void {}
|
|
255
|
+
|
|
256
|
+
/**
|
|
257
|
+
* @override
|
|
258
|
+
*/
|
|
259
|
+
execute<T> (sql: string): T { return undefined as unknown as T }
|
|
260
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { createRequire } from 'node:module';
|
|
2
|
+
const require = createRequire(import.meta.url);
|
|
3
|
+
const db = require('db');
|
|
4
|
+
import type { FxDbDriverNS } from '../Typo';
|
|
5
|
+
import type { FxOrmCoreCallbackNS } from '../../orm-core/index';
|
|
6
|
+
import { SQLDriver } from "./base.class";
|
|
7
|
+
import { logDebugSQL } from '../utils';
|
|
8
|
+
|
|
9
|
+
function escapeSchemaName(schema: string) {
|
|
10
|
+
return `"${schema.replace(/"/g, '""')}"`;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export default class DMDriver extends SQLDriver<Class_DbConnection> implements FxDbDriverNS.SQLDriver {
|
|
14
|
+
constructor (conn: FxDbDriverNS.ConnectionInputArgs | string) {
|
|
15
|
+
super(conn);
|
|
16
|
+
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
switchDb (targetDb: string) {
|
|
20
|
+
this.execute(`SET SCHEMA ${escapeSchemaName(targetDb)}`);
|
|
21
|
+
this.currentDb = targetDb;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
open (): Class_DbConnection { return super.open() }
|
|
25
|
+
close (): void {
|
|
26
|
+
if (this.connection) this.connection.close()
|
|
27
|
+
}
|
|
28
|
+
ping (): void { return }
|
|
29
|
+
begin (): void { return this.connection.begin() }
|
|
30
|
+
commit (): void { return this.connection.commit() }
|
|
31
|
+
trans<T = any> (cb: FxOrmCoreCallbackNS.ExecutionCallback<T>): boolean { return this.connection.trans((conn: any) => cb(null, conn)); }
|
|
32
|
+
rollback (): void { return this.connection.rollback() }
|
|
33
|
+
|
|
34
|
+
getConnection (): Class_DbConnection { return (db as any).openDM(this.uri) }
|
|
35
|
+
|
|
36
|
+
dbExists (dbname: string): boolean {
|
|
37
|
+
const schema = dbname.toUpperCase();
|
|
38
|
+
return this.execute(
|
|
39
|
+
`SELECT OBJECT_NAME FROM ALL_OBJECTS WHERE OBJECT_TYPE='SCH' AND OBJECT_NAME='${schema}'`
|
|
40
|
+
).length > 0;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
execute<T = any> (sql: string): T {
|
|
44
|
+
if (this.extend_config.debug_sql) {
|
|
45
|
+
logDebugSQL('dm', sql);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
if (!this.connection) this.open()
|
|
49
|
+
try {
|
|
50
|
+
return this.connection.execute(sql) as any;
|
|
51
|
+
} catch (e) {
|
|
52
|
+
const err = e as any;
|
|
53
|
+
if (err && typeof err.message === 'string' && !err.message.includes('SQL:')) {
|
|
54
|
+
err.message += `\nSQL: ${sql}`;
|
|
55
|
+
}
|
|
56
|
+
if (err && !err.sql) {
|
|
57
|
+
err.sql = sql;
|
|
58
|
+
}
|
|
59
|
+
throw err;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { createRequire } from 'node:module';
|
|
2
|
+
const require = createRequire(import.meta.url);
|
|
3
|
+
const db = require('db');
|
|
4
|
+
import type { FxDbDriverNS } from '../Typo';
|
|
5
|
+
import type { FxOrmCoreCallbackNS } from '../../orm-core/index';
|
|
6
|
+
import { SQLDriver } from "./base.class";
|
|
7
|
+
import { logDebugSQL } from '../utils';
|
|
8
|
+
|
|
9
|
+
function escapeIdentifier(name: string) {
|
|
10
|
+
return `[${String(name).replace(/]/g, ']]')}]`;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function escapeLiteral(value: string) {
|
|
14
|
+
return `'${String(value).replace(/'/g, "''")}'`;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export default class MSSQLDriver extends SQLDriver<Class_DbConnection> implements FxDbDriverNS.SQLDriver {
|
|
18
|
+
constructor (conn: FxDbDriverNS.ConnectionInputArgs | string) {
|
|
19
|
+
super(conn);
|
|
20
|
+
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
switchDb (targetDb: string) {
|
|
24
|
+
this.execute(`USE ${escapeIdentifier(targetDb)}`);
|
|
25
|
+
this.currentDb = targetDb;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
open (): Class_DbConnection { return super.open() }
|
|
29
|
+
close (): void {
|
|
30
|
+
if (this.connection) this.connection.close()
|
|
31
|
+
}
|
|
32
|
+
ping (): void {
|
|
33
|
+
this.execute('SELECT 1');
|
|
34
|
+
}
|
|
35
|
+
begin (): void { return this.connection.begin() }
|
|
36
|
+
commit (): void { return this.connection.commit() }
|
|
37
|
+
trans<T = any> (cb: FxOrmCoreCallbackNS.ExecutionCallback<T>): boolean { return this.connection.trans((conn: any) => cb(null, conn)); }
|
|
38
|
+
rollback (): void { return this.connection.rollback() }
|
|
39
|
+
|
|
40
|
+
getConnection (): Class_DbConnection { return db.openMSSQL(this.uri) }
|
|
41
|
+
|
|
42
|
+
dbExists (dbname: string): boolean {
|
|
43
|
+
return this.execute(
|
|
44
|
+
`SELECT name FROM sys.databases WHERE name = ${escapeLiteral(dbname)}`
|
|
45
|
+
).length > 0;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
execute<T = any> (sql: string): T {
|
|
49
|
+
if (this.extend_config.debug_sql) {
|
|
50
|
+
logDebugSQL('mssql', sql);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (!this.connection) this.open()
|
|
54
|
+
try {
|
|
55
|
+
return this.connection.execute(sql) as any;
|
|
56
|
+
} catch (e) {
|
|
57
|
+
const err = e as any;
|
|
58
|
+
if (err && typeof err.message === 'string' && !err.message.includes('SQL:')) {
|
|
59
|
+
err.message += `\nSQL: ${sql}`;
|
|
60
|
+
}
|
|
61
|
+
if (err && !err.sql) {
|
|
62
|
+
err.sql = sql;
|
|
63
|
+
}
|
|
64
|
+
throw err;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { createRequire } from 'node:module';
|
|
2
|
+
const require = createRequire(import.meta.url);
|
|
3
|
+
const db = require('db');
|
|
4
|
+
import type { FxDbDriverNS } from '../Typo';
|
|
5
|
+
import type { FxOrmCoreCallbackNS } from '../../orm-core/index';
|
|
6
|
+
import { SQLDriver } from "./base.class";
|
|
7
|
+
import { logDebugSQL } from '../utils';
|
|
8
|
+
|
|
9
|
+
export default class MySQLDriver extends SQLDriver<Class_MySQL> implements FxDbDriverNS.SQLDriver {
|
|
10
|
+
constructor (conn: FxDbDriverNS.ConnectionInputArgs | string) {
|
|
11
|
+
super(conn);
|
|
12
|
+
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
switchDb (targetDb: string) {
|
|
16
|
+
this.execute(`use \`${targetDb}\``);
|
|
17
|
+
this.currentDb = targetDb;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
open (): Class_MySQL { return super.open() }
|
|
21
|
+
close (): void {
|
|
22
|
+
if (this.connection) this.connection.close()
|
|
23
|
+
}
|
|
24
|
+
ping (): void { return }
|
|
25
|
+
begin (): void { return this.connection.begin() }
|
|
26
|
+
commit (): void { return this.connection.commit() }
|
|
27
|
+
trans<T = any> (cb: FxOrmCoreCallbackNS.ExecutionCallback<T>): boolean { return this.connection.trans((conn: any) => cb(null, conn)); }
|
|
28
|
+
rollback (): void { return this.connection.rollback() }
|
|
29
|
+
|
|
30
|
+
getConnection (): Class_MySQL { return db.openMySQL(this.uri) }
|
|
31
|
+
|
|
32
|
+
dbExists (dbname: string): boolean {
|
|
33
|
+
return this.execute(`SELECT SCHEMA_NAME FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME = '${dbname}'`).length > 0;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
execute<T = any> (sql: string): T {
|
|
37
|
+
if (this.extend_config.debug_sql) {
|
|
38
|
+
logDebugSQL('mysql', sql);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
if (!this.connection) this.open()
|
|
42
|
+
return this.connection.execute(sql) as any;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { createRequire } from 'node:module';
|
|
2
|
+
const require = createRequire(import.meta.url);
|
|
3
|
+
const db = require('db');
|
|
4
|
+
import type { FxDbDriverNS } from '../Typo';
|
|
5
|
+
import type { FxOrmCoreCallbackNS } from '../../orm-core/index';
|
|
6
|
+
import { SQLDriver } from "./base.class";
|
|
7
|
+
import { logDebugSQL, detectWindowsCodePoints, filterPSQLSearchPath } from '../utils';
|
|
8
|
+
|
|
9
|
+
type CodePointItem = {
|
|
10
|
+
codepoint: string
|
|
11
|
+
dotNetName: string
|
|
12
|
+
comment: string
|
|
13
|
+
}
|
|
14
|
+
const CodepointsList: CodePointItem[] = require('../../codepoints-map.json')
|
|
15
|
+
const CodepointsMap = CodepointsList.reduce((accu, item) => {
|
|
16
|
+
accu[item.codepoint] = item;
|
|
17
|
+
return accu;
|
|
18
|
+
}, {} as Record<CodePointItem['codepoint'], CodePointItem>);
|
|
19
|
+
|
|
20
|
+
const win32CpInfo = detectWindowsCodePoints();
|
|
21
|
+
|
|
22
|
+
export default class PostgreSQLDriver extends SQLDriver<Class_DbConnection> implements FxDbDriverNS.SQLDriver {
|
|
23
|
+
constructor (conn: FxDbDriverNS.ConnectionInputArgs | string) {
|
|
24
|
+
super(conn);
|
|
25
|
+
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* @description unsafe for parallel execution, make sure call it in serial
|
|
30
|
+
* @param targetDb
|
|
31
|
+
*/
|
|
32
|
+
switchDb (targetDb: string) {
|
|
33
|
+
// // will throw out error now, postgresql does not support run commmand as sql
|
|
34
|
+
// this.execute(`\\c ${targetDb};`);
|
|
35
|
+
|
|
36
|
+
this.config.database = targetDb;
|
|
37
|
+
this.reopen();
|
|
38
|
+
this.currentDb = targetDb;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
open (): Class_DbConnection {
|
|
42
|
+
if (!win32CpInfo.codepoints) return super.open();
|
|
43
|
+
|
|
44
|
+
const conn = super.open() as Class_DbConnection & { codec?: string };
|
|
45
|
+
|
|
46
|
+
const matchedCodepoint = CodepointsMap[win32CpInfo.codepoints]
|
|
47
|
+
|
|
48
|
+
// TODO: support common codepoints -> postgresql-encoding
|
|
49
|
+
if (conn.codec && win32CpInfo.codepoints === '936') {
|
|
50
|
+
conn.codec = 'GBK';
|
|
51
|
+
} else if (conn.codec && matchedCodepoint) {
|
|
52
|
+
conn.codec = matchedCodepoint.dotNetName;
|
|
53
|
+
} else if (conn.codec === 'utf8' && win32CpInfo.codepoints !== '65001') {
|
|
54
|
+
console.error(`system default code points is '${win32CpInfo.codepoints}', but odbc try to use codec UTF8 with codepoints 65001, refer to https://learn.microsoft.com/en-us/windows/win32/intl/code-page-identifiers to set connection.codec as UTF8`);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return conn;
|
|
58
|
+
}
|
|
59
|
+
close (): void {
|
|
60
|
+
if (this.connection) this.connection.close()
|
|
61
|
+
}
|
|
62
|
+
ping (): void { return }
|
|
63
|
+
begin (): void { return this.connection.begin() }
|
|
64
|
+
commit (): void { return this.connection.commit() }
|
|
65
|
+
trans<T = any> (cb: FxOrmCoreCallbackNS.ExecutionCallback<T>): boolean { return this.connection.trans((conn: any) => cb(null, conn)); }
|
|
66
|
+
rollback (): void { return this.connection.rollback() }
|
|
67
|
+
|
|
68
|
+
getConnection (): Class_DbConnection {
|
|
69
|
+
const conn = this.config.protocol === 'kingbase:'
|
|
70
|
+
? (db as any).openKingbase(this.uri)
|
|
71
|
+
: db.openPSQL(this.uri);
|
|
72
|
+
|
|
73
|
+
let searchPath = this.config.query?.search_path || this.config.query?.searchPath || '';
|
|
74
|
+
if(searchPath) {
|
|
75
|
+
searchPath = filterPSQLSearchPath(searchPath);
|
|
76
|
+
searchPath && conn.execute(`SET search_path TO ${searchPath}`);
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
return conn;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
dbExists (dbname: string): boolean {
|
|
83
|
+
return this.execute(`SELECT datname FROM pg_database WHERE datname = '${dbname}'`).length > 0;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
execute<T = any> (sql: string): T {
|
|
87
|
+
if (this.extend_config.debug_sql) {
|
|
88
|
+
logDebugSQL(this.config.protocol === 'kingbase:' ? 'kingbase' : 'postgresql', sql);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
if (!this.connection) this.open()
|
|
92
|
+
return this.connection.execute(sql) as any;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { createRequire } from 'node:module';
|
|
2
|
+
const require = createRequire(import.meta.url);
|
|
3
|
+
const db = require('db');
|
|
4
|
+
const coroutine = require('coroutine');
|
|
5
|
+
import type { FxDbDriverNS } from '../Typo';
|
|
6
|
+
import { Driver } from "./base.class";
|
|
7
|
+
import * as Utils from '../utils';
|
|
8
|
+
export default class RedisDriver extends Driver<Class_Redis> implements FxDbDriverNS.CommandDriver {
|
|
9
|
+
constructor (conn: FxDbDriverNS.ConnectionInputArgs | string) {
|
|
10
|
+
super(conn);
|
|
11
|
+
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
open (): Class_Redis { return super.open() }
|
|
15
|
+
|
|
16
|
+
close (): void {
|
|
17
|
+
if (this.connection) this.connection.close()
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
ping (): void {}
|
|
21
|
+
|
|
22
|
+
command<T = any> (cmd: string, ...args: any[]): T {
|
|
23
|
+
|
|
24
|
+
if (!this.connection) this.open()
|
|
25
|
+
return this.connection.command(cmd, ...args) as any;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
commands<T = any> (
|
|
29
|
+
cmds: Record<string, any>,
|
|
30
|
+
opts?: FxDbDriverNS.CommandDriverCommandOptions
|
|
31
|
+
): T {
|
|
32
|
+
const { parallel = false } = opts || {};
|
|
33
|
+
|
|
34
|
+
if (parallel)
|
|
35
|
+
return coroutine.parallel(Object.keys(cmds), (cmd: string) => {
|
|
36
|
+
return { cmd, result: this.command(cmd, ...Utils.arraify(cmds[cmd])) }
|
|
37
|
+
}) as any
|
|
38
|
+
else
|
|
39
|
+
return Object.keys(cmds).map((cmd: string) => {
|
|
40
|
+
return { cmd, result: this.command(cmd, ...Utils.arraify(cmds[cmd])) }
|
|
41
|
+
}) as any
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
getConnection (): Class_Redis { return db.openRedis(this.uri) }
|
|
45
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { createRequire } from 'node:module';
|
|
2
|
+
const require = createRequire(import.meta.url);
|
|
3
|
+
const db = require('db');
|
|
4
|
+
import type { FxDbDriverNS } from '../Typo';
|
|
5
|
+
import type { FxOrmCoreCallbackNS } from '../../orm-core/index';
|
|
6
|
+
import { SQLDriver } from "./base.class";
|
|
7
|
+
import { logDebugSQL } from '../utils';
|
|
8
|
+
|
|
9
|
+
export default class SQLiteDriver extends SQLDriver<Class_SQLite> implements FxDbDriverNS.SQLDriver {
|
|
10
|
+
constructor (conn: FxDbDriverNS.ConnectionInputArgs | string) {
|
|
11
|
+
super(conn);
|
|
12
|
+
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
open (): Class_SQLite { return super.open() }
|
|
16
|
+
|
|
17
|
+
close (): void {
|
|
18
|
+
if (this.connection) this.connection.close()
|
|
19
|
+
}
|
|
20
|
+
ping (): void { return }
|
|
21
|
+
begin (): void { return this.connection.begin() }
|
|
22
|
+
commit (): void { return this.connection.commit() }
|
|
23
|
+
trans<T = any> (cb: FxOrmCoreCallbackNS.ExecutionCallback<T>): boolean { return this.connection.trans((conn: any) => cb(null, conn)); }
|
|
24
|
+
rollback (): void { return this.connection.rollback() }
|
|
25
|
+
|
|
26
|
+
getConnection (): Class_SQLite { return db.openSQLite(this.uri) }
|
|
27
|
+
|
|
28
|
+
dbExists(dbname: string): boolean {
|
|
29
|
+
// return this.execute(`SELECT name FROM sqlite_master WHERE type='table' AND name='${dbname}'`).length > 0;
|
|
30
|
+
return true;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
execute<T = any> (sql: string): T {
|
|
34
|
+
if (this.extend_config.debug_sql) {
|
|
35
|
+
logDebugSQL('sqlite', sql);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
if (!this.connection) this.open()
|
|
39
|
+
return this.connection.execute(sql) as any;
|
|
40
|
+
}
|
|
41
|
+
}
|