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,87 @@
|
|
|
1
|
+
import { ChainBuilderBase } from "./Helpers";
|
|
2
|
+
import type { FxSqlQueryDialect } from "./Typo/Dialect";
|
|
3
|
+
import type { FxSqlQueryColumns } from "./Typo/Field";
|
|
4
|
+
import type { FxSqlQuery } from "./Typo/Query";
|
|
5
|
+
import type { FxSqlQueryChainBuilder } from "./Typo/Query-ChainBuilder";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Instantiate a new CREATE-type query builder
|
|
9
|
+
* @param Dialect
|
|
10
|
+
* @returns {{table: table, field: field, fields: fields, build: build}}
|
|
11
|
+
* @constructor
|
|
12
|
+
*/
|
|
13
|
+
export class CreateQuery extends ChainBuilderBase implements FxSqlQueryChainBuilder.ChainBuilder__Create {
|
|
14
|
+
tableName: string = null as any;
|
|
15
|
+
structure: FxSqlQueryColumns.FieldItemTypeMap = {};
|
|
16
|
+
|
|
17
|
+
constructor (Dialect: FxSqlQueryDialect.Dialect) {
|
|
18
|
+
super(Dialect);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Set the table name
|
|
23
|
+
* @param table_name
|
|
24
|
+
*/
|
|
25
|
+
table (table_name: string) {
|
|
26
|
+
this.tableName = table_name;
|
|
27
|
+
|
|
28
|
+
return this;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Add a field
|
|
32
|
+
* @param name
|
|
33
|
+
* @param type
|
|
34
|
+
*/
|
|
35
|
+
field (name: string, type: FxSqlQueryDialect.DialectFieldType) {
|
|
36
|
+
this.structure[name] = type;
|
|
37
|
+
|
|
38
|
+
return this;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Set all the fields
|
|
42
|
+
* @param fields
|
|
43
|
+
*/
|
|
44
|
+
fields (fields?: FxSqlQueryColumns.FieldItemTypeMap) {
|
|
45
|
+
if (!fields) {
|
|
46
|
+
return this.structure as any;
|
|
47
|
+
}
|
|
48
|
+
this.structure = fields;
|
|
49
|
+
|
|
50
|
+
return this;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Build a query from the passed params
|
|
55
|
+
*/
|
|
56
|
+
build () {
|
|
57
|
+
if(!this.tableName){
|
|
58
|
+
return '';
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const structure = this.structure;
|
|
62
|
+
const sqlBuilder = this.Dialect.knex.schema.createTable(this.tableName, function (t: any) {
|
|
63
|
+
Object.keys(structure).forEach(field => {
|
|
64
|
+
const desc = structure[field];
|
|
65
|
+
switch (desc) {
|
|
66
|
+
case 'id':
|
|
67
|
+
t.increments(field);
|
|
68
|
+
break
|
|
69
|
+
case 'int':
|
|
70
|
+
t.integer(field);
|
|
71
|
+
break
|
|
72
|
+
case 'float':
|
|
73
|
+
t.float(field, 12, 2);
|
|
74
|
+
break
|
|
75
|
+
case 'bool':
|
|
76
|
+
t.specificType(field, 'TINYINT(1)');
|
|
77
|
+
break
|
|
78
|
+
case 'text':
|
|
79
|
+
t.text(field);
|
|
80
|
+
break
|
|
81
|
+
}
|
|
82
|
+
})
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
return sqlBuilder.toQuery();
|
|
86
|
+
}
|
|
87
|
+
}
|
|
@@ -1,48 +1,65 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { createRequire } from 'node:module';
|
|
2
|
+
const require = createRequire(import.meta.url);
|
|
3
3
|
const util = require("util");
|
|
4
|
-
|
|
4
|
+
import * as helpers from '../Helpers';
|
|
5
|
+
import type { FxSqlQueryDialect } from "../Typo/Dialect";
|
|
6
|
+
import type { FxSqlQuery } from "../Typo/Query";
|
|
7
|
+
import type { FxSqlQuerySql } from "../Typo/Sql";
|
|
8
|
+
|
|
5
9
|
const DataTypes = {
|
|
6
|
-
id:
|
|
7
|
-
int:
|
|
10
|
+
id: 'INT IDENTITY(1,1) NOT NULL PRIMARY KEY',
|
|
11
|
+
int: 'INTEGER',
|
|
8
12
|
float: 'DOUBLE',
|
|
9
|
-
bool:
|
|
10
|
-
text:
|
|
13
|
+
bool: 'BIT',
|
|
14
|
+
text: 'TEXT'
|
|
11
15
|
};
|
|
12
|
-
|
|
16
|
+
|
|
17
|
+
const escape = function (
|
|
18
|
+
query: FxSqlQuerySql.SqlFragmentStr,
|
|
19
|
+
args: FxSqlQuerySql.SqlAssignmentValues
|
|
20
|
+
) {
|
|
13
21
|
return helpers.escapeQuery(Dialect, query, args);
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const escapeId = function (...args: ({
|
|
25
|
+
str: string,
|
|
26
|
+
escapes: string[],
|
|
27
|
+
} | string)[]) {
|
|
28
|
+
return args.map(function (el): string {
|
|
17
29
|
if (typeof el == "object") {
|
|
18
30
|
return el.str.replace(/\?:(id|value)/g, function (m) {
|
|
19
31
|
if (m == "?:id") {
|
|
20
|
-
return escapeId(el.escapes.shift());
|
|
32
|
+
return escapeId(el.escapes.shift()!);
|
|
21
33
|
}
|
|
22
|
-
return escapeVal(el.escapes.shift());
|
|
34
|
+
return escapeVal(el.escapes.shift()!);
|
|
23
35
|
});
|
|
24
36
|
}
|
|
25
|
-
return el.split(".").map(function (ele) {
|
|
37
|
+
return el.split(".").map(function (ele): string {
|
|
26
38
|
return "\"" + ele.replace(/\"/g, "\"\"") + "\"";
|
|
27
39
|
}).join(".");
|
|
28
40
|
}).join(".");
|
|
29
41
|
};
|
|
30
|
-
|
|
42
|
+
|
|
43
|
+
const escapeVal = function (this: any, val: any, timeZone?: FxSqlQuery.FxSqlQueryTimezone): string {
|
|
31
44
|
if (val === undefined || val === null || typeof val === "symbol") {
|
|
32
45
|
return 'NULL';
|
|
33
46
|
}
|
|
47
|
+
|
|
34
48
|
if (Array.isArray(val)) {
|
|
35
49
|
if (val.length === 1 && Array.isArray(val[0])) {
|
|
36
|
-
return "(" + val[0].map(escapeVal.
|
|
50
|
+
return "(" + val[0].map((v: any) => escapeVal.call(this, v)) + ")";
|
|
37
51
|
}
|
|
38
|
-
return "(" + val.map(escapeVal.
|
|
52
|
+
return "(" + val.map((v: any) => escapeVal.call(this, v)).join(", ") + ")";
|
|
39
53
|
}
|
|
54
|
+
|
|
40
55
|
if (util.isDate(val)) {
|
|
41
56
|
return "'" + helpers.dateToString(val, timeZone || "local", { dialect: 'dm' }) + "'";
|
|
42
57
|
}
|
|
58
|
+
|
|
43
59
|
if (Buffer.isBuffer(val)) {
|
|
44
60
|
return helpers.bufferToString(val, 'dm');
|
|
45
61
|
}
|
|
62
|
+
|
|
46
63
|
switch (typeof val) {
|
|
47
64
|
case "number":
|
|
48
65
|
if (!isFinite(val)) {
|
|
@@ -61,15 +78,18 @@ const escapeVal = function (val, timeZone) {
|
|
|
61
78
|
default:
|
|
62
79
|
val = JSON.stringify(val);
|
|
63
80
|
}
|
|
81
|
+
|
|
64
82
|
return "'" + val.replace(/\'/g, "''") + "'";
|
|
65
83
|
};
|
|
66
|
-
|
|
67
|
-
|
|
84
|
+
|
|
85
|
+
const Dialect: FxSqlQueryDialect.Dialect = ({
|
|
86
|
+
type: 'dm' as const,
|
|
68
87
|
DataTypes,
|
|
69
88
|
escape,
|
|
70
89
|
escapeId,
|
|
71
90
|
escapeVal,
|
|
72
91
|
limitAsTop: false,
|
|
73
|
-
knex: null
|
|
74
|
-
};
|
|
75
|
-
|
|
92
|
+
knex: null as any
|
|
93
|
+
} as any);
|
|
94
|
+
|
|
95
|
+
export default Dialect
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import mysql from './mysql'
|
|
2
|
+
export { mysql }
|
|
3
|
+
|
|
4
|
+
import postgresql from './postgresql'
|
|
5
|
+
export { postgresql }
|
|
6
|
+
|
|
7
|
+
import sqlite from './sqlite'
|
|
8
|
+
export { sqlite }
|
|
9
|
+
|
|
10
|
+
import mssql from './mssql'
|
|
11
|
+
export { mssql }
|
|
12
|
+
|
|
13
|
+
import dm from './dm'
|
|
14
|
+
export { dm }
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { createRequire } from 'node:module';
|
|
2
|
+
const require = createRequire(import.meta.url);
|
|
3
|
+
const util = require("util");
|
|
4
|
+
import * as helpers from '../Helpers';
|
|
5
|
+
import type { FxSqlQueryDialect } from "../Typo/Dialect";
|
|
6
|
+
import type { FxSqlQuery } from "../Typo/Query";
|
|
7
|
+
import type { FxSqlQuerySql } from "../Typo/Sql";
|
|
8
|
+
|
|
9
|
+
const DataTypes = {
|
|
10
|
+
id: 'INT IDENTITY(1,1) NOT NULL PRIMARY KEY',
|
|
11
|
+
int: 'INT',
|
|
12
|
+
float: 'FLOAT',
|
|
13
|
+
bool: 'BIT',
|
|
14
|
+
text: 'TEXT'
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
const escape = function (
|
|
18
|
+
query: FxSqlQuerySql.SqlFragmentStr,
|
|
19
|
+
args: FxSqlQuerySql.SqlAssignmentValues
|
|
20
|
+
) {
|
|
21
|
+
return helpers.escapeQuery(Dialect, query, args);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function escapeId (...els: any[]) {
|
|
25
|
+
return els.map(function (el) {
|
|
26
|
+
if (typeof el == "object") {
|
|
27
|
+
return el.str.replace(/\?:(id|value)/g, function (m: string) {
|
|
28
|
+
if (m == "?:id") {
|
|
29
|
+
return escapeId(el.escapes.shift()!);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return escapeVal(el.escapes.shift()!);
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
return "[" + el + "]";
|
|
36
|
+
}).join(".");
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
const escapeVal = function (this: any, val: any, timeZone?: FxSqlQuery.FxSqlQueryTimezone): any {
|
|
40
|
+
if (val === undefined || val === null || typeof val === "symbol") {
|
|
41
|
+
return 'NULL';
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
if (Array.isArray(val)) {
|
|
45
|
+
if (val.length === 1 && Array.isArray(val[0])) {
|
|
46
|
+
return "(" + val[0].map((v: any) => escapeVal.call(this, v)) + ")";
|
|
47
|
+
}
|
|
48
|
+
return "(" + val.map((v: any) => escapeVal.call(this, v)).join(", ") + ")";
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
if (util.isDate(val)) {
|
|
52
|
+
return "'" + helpers.dateToString(val, timeZone || "local", { dialect: 'mssql' }) + "'";
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if (Buffer.isBuffer(val)) {
|
|
56
|
+
return helpers.bufferToString( val, 'mssql');
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
switch (typeof val) {
|
|
60
|
+
case "number":
|
|
61
|
+
if (!isFinite(val)) {
|
|
62
|
+
val = val.toString();
|
|
63
|
+
break;
|
|
64
|
+
}
|
|
65
|
+
return val;
|
|
66
|
+
case "boolean":
|
|
67
|
+
return val ? 1 : 0;
|
|
68
|
+
case "function":
|
|
69
|
+
return val(Dialect);
|
|
70
|
+
case "string":
|
|
71
|
+
break;
|
|
72
|
+
case "bigint":
|
|
73
|
+
return val.toString();
|
|
74
|
+
default:
|
|
75
|
+
val = JSON.stringify(val);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
return "'" + val.replace(/\'/g, "''") + "'";
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
const Dialect: FxSqlQueryDialect.Dialect = ({
|
|
82
|
+
type: 'mssql' as const,
|
|
83
|
+
DataTypes,
|
|
84
|
+
escape,
|
|
85
|
+
escapeId,
|
|
86
|
+
escapeVal,
|
|
87
|
+
limitAsTop: true,
|
|
88
|
+
knex: null as any
|
|
89
|
+
} as any);
|
|
90
|
+
|
|
91
|
+
export default Dialect
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { createRequire } from 'node:module';
|
|
2
|
+
const require = createRequire(import.meta.url);
|
|
3
|
+
const util = require("util");
|
|
4
|
+
import * as helpers from '../Helpers';
|
|
5
|
+
import type { FxSqlQueryDialect } from "../Typo/Dialect";
|
|
6
|
+
import type { FxSqlQuery } from "../Typo/Query";
|
|
7
|
+
import type { FxSqlQuerySql } from "../Typo/Sql";
|
|
8
|
+
|
|
9
|
+
const DataTypes = {
|
|
10
|
+
id: 'INTEGER PRIMARY KEY AUTO_INCREMENT',
|
|
11
|
+
int: 'INTEGER',
|
|
12
|
+
float: 'FLOAT(12,2)',
|
|
13
|
+
bool: 'TINYINT(1)',
|
|
14
|
+
text: 'TEXT'
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
function escape (
|
|
18
|
+
query: FxSqlQuerySql.SqlFragmentStr,
|
|
19
|
+
args: FxSqlQuerySql.SqlAssignmentValues
|
|
20
|
+
) {
|
|
21
|
+
return helpers.escapeQuery(Dialect, query, args);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function escapeId (...els: (string | {str: string, escapes: string[]})[]): string {
|
|
25
|
+
return els.map(function (el) {
|
|
26
|
+
if (typeof el == "object") {
|
|
27
|
+
return el.str.replace(/\?:(id|value)/g, function (m: string) {
|
|
28
|
+
if (m == "?:id") {
|
|
29
|
+
return escapeId(el.escapes.shift()!);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return escapeVal(el.escapes.shift()!);
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
return "`" + el.replace(/`/g, '``') + "`";
|
|
36
|
+
}).join(".");
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
function escapeVal (this: any, val: any, timeZone?: FxSqlQuery.FxSqlQueryTimezone): any {
|
|
40
|
+
if (val === undefined || val === null || typeof val === "symbol") {
|
|
41
|
+
return 'NULL';
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
if (Buffer.isBuffer(val)) {
|
|
45
|
+
return helpers.bufferToString( val, 'mysql');
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
if (Array.isArray(val)) {
|
|
49
|
+
return arrayToList(val, timeZone || "local");
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
if (util.isDate(val)) {
|
|
53
|
+
val = helpers.dateToString(val, timeZone || "local", { dialect: 'mysql' });
|
|
54
|
+
} else {
|
|
55
|
+
switch (typeof val) {
|
|
56
|
+
case 'boolean':
|
|
57
|
+
return (val) ? 'true' : 'false';
|
|
58
|
+
case 'number':
|
|
59
|
+
if (!isFinite(val)) {
|
|
60
|
+
val = val.toString();
|
|
61
|
+
break;
|
|
62
|
+
}
|
|
63
|
+
return val + '';
|
|
64
|
+
case "object":
|
|
65
|
+
return objectToValues(val, timeZone || "Z");
|
|
66
|
+
case "function":
|
|
67
|
+
return val(Dialect);
|
|
68
|
+
case 'bigint':
|
|
69
|
+
return val.toString();
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
val = val.replace(/[\0\n\r\b\t\\\'\"\x1a]/g, function(s: string) {
|
|
74
|
+
switch(s) {
|
|
75
|
+
case "\0": return "\\0";
|
|
76
|
+
case "\n": return "\\n";
|
|
77
|
+
case "\r": return "\\r";
|
|
78
|
+
case "\b": return "\\b";
|
|
79
|
+
case "\t": return "\\t";
|
|
80
|
+
case "\x1a": return "\\Z";
|
|
81
|
+
default: return "\\" + s;
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
return "'" + val + "'";
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
function objectToValues(object: {[key: string]: any}, timeZone: FxSqlQuery.FxSqlQueryTimezone): string {
|
|
89
|
+
var values = [];
|
|
90
|
+
for (var key in object) {
|
|
91
|
+
var value = object[key];
|
|
92
|
+
|
|
93
|
+
if(typeof value === 'function') {
|
|
94
|
+
continue;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
values.push(escapeId(key) + ' = ' + escapeVal(value, timeZone));
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
return values.join(', ');
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function arrayToList(array: any[], timeZone?: FxSqlQuery.FxSqlQueryTimezone): string {
|
|
104
|
+
return "(" + array.map(function(v) {
|
|
105
|
+
if (Array.isArray(v)) return arrayToList(v);
|
|
106
|
+
return escapeVal(v, timeZone);
|
|
107
|
+
}).join(', ') + ")";
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
const Dialect: FxSqlQueryDialect.Dialect = ({
|
|
111
|
+
type: 'mysql' as const,
|
|
112
|
+
DataTypes,
|
|
113
|
+
escape,
|
|
114
|
+
escapeId,
|
|
115
|
+
escapeVal,
|
|
116
|
+
limitAsTop: false,
|
|
117
|
+
knex: null as any
|
|
118
|
+
} as any);
|
|
119
|
+
|
|
120
|
+
export default Dialect
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { createRequire } from 'node:module';
|
|
2
|
+
const require = createRequire(import.meta.url);
|
|
3
|
+
const util = require("util");
|
|
4
|
+
import * as helpers from '../Helpers';
|
|
5
|
+
|
|
6
|
+
import type { FxSqlQueryDialect } from "../Typo/Dialect";
|
|
7
|
+
import type { FxSqlQuery } from "../Typo/Query";
|
|
8
|
+
import type { FxSqlQuerySql } from "../Typo/Sql";
|
|
9
|
+
|
|
10
|
+
const DataTypes = {
|
|
11
|
+
id: 'SERIAL PRIMARY KEY',
|
|
12
|
+
int: 'INTEGER',
|
|
13
|
+
float: 'REAL',
|
|
14
|
+
bool: 'SMALLINT',
|
|
15
|
+
text: 'TEXT'
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
const escape = function (
|
|
19
|
+
query: FxSqlQuerySql.SqlFragmentStr,
|
|
20
|
+
args: FxSqlQuerySql.SqlAssignmentValues
|
|
21
|
+
) {
|
|
22
|
+
return helpers.escapeQuery(Dialect, query, args);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const escapeId = function (...args: ({
|
|
26
|
+
str: string,
|
|
27
|
+
escapes: string[],
|
|
28
|
+
} | string)[]) {
|
|
29
|
+
return args.map(function (el): string {
|
|
30
|
+
if (typeof el == "object") {
|
|
31
|
+
return el.str.replace(/\?:(id|value)/g, function (m) {
|
|
32
|
+
if (m == "?:id") {
|
|
33
|
+
return escapeId(el.escapes.shift()!);
|
|
34
|
+
}
|
|
35
|
+
// ?:value
|
|
36
|
+
return escapeVal(el.escapes.shift()!);
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
return el.split(".").map(function (ele): string { return "\"" + ele.replace(/\"/g, "\"\"") + "\""; }).join(".");
|
|
40
|
+
}).join(".");
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
const escapeVal = function (this: any, val: any, timeZone?: FxSqlQuery.FxSqlQueryTimezone): string {
|
|
44
|
+
if (val === undefined || val === null || typeof val === "symbol") {
|
|
45
|
+
return 'NULL';
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
if (Array.isArray(val)) {
|
|
49
|
+
if (val.length === 1 && Array.isArray(val[0])) {
|
|
50
|
+
return "(" + val[0].map((v: any) => escapeVal.call(this, v)) + ")";
|
|
51
|
+
}
|
|
52
|
+
return "(" + val.map((v: any) => escapeVal.call(this, v)).join(", ") + ")";
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if (util.isDate(val)) {
|
|
56
|
+
return "'" + helpers.dateToString(val, timeZone || "local", { dialect: 'postgresql' }) + "'";
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
if (Buffer.isBuffer(val)) {
|
|
60
|
+
return helpers.bufferToString(val, 'postgresql');
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
switch (typeof val) {
|
|
64
|
+
case "number":
|
|
65
|
+
if (!isFinite(val)) {
|
|
66
|
+
val = val.toString();
|
|
67
|
+
break;
|
|
68
|
+
}
|
|
69
|
+
return val.toString();
|
|
70
|
+
case "boolean":
|
|
71
|
+
return val ? "true" : "false";
|
|
72
|
+
case "function":
|
|
73
|
+
return val(exports);
|
|
74
|
+
case "string":
|
|
75
|
+
break;
|
|
76
|
+
case "bigint":
|
|
77
|
+
return val.toString();
|
|
78
|
+
default:
|
|
79
|
+
val = JSON.stringify(val);
|
|
80
|
+
}
|
|
81
|
+
// No need to escape backslashes with default PostgreSQL 9.1+ config.
|
|
82
|
+
// Google 'postgresql standard_conforming_strings' for details.
|
|
83
|
+
return "'" + val.replace(/\'/g, "''") + "'";
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
const defaultValuesStmt = "DEFAULT VALUES";
|
|
87
|
+
|
|
88
|
+
const Dialect: FxSqlQueryDialect.Dialect = ({
|
|
89
|
+
type: 'postgresql' as const,
|
|
90
|
+
DataTypes,
|
|
91
|
+
escape,
|
|
92
|
+
escapeId,
|
|
93
|
+
escapeVal,
|
|
94
|
+
limitAsTop: false,
|
|
95
|
+
knex: null as any,
|
|
96
|
+
defaultValuesStmt
|
|
97
|
+
} as any);
|
|
98
|
+
|
|
99
|
+
export default Dialect;
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { createRequire } from 'node:module';
|
|
2
|
+
const require = createRequire(import.meta.url);
|
|
3
|
+
import mysql from './mysql';
|
|
4
|
+
const util = require("util");
|
|
5
|
+
import * as helpers from '../Helpers';
|
|
6
|
+
import type { FxSqlQueryDialect } from "../Typo/Dialect";
|
|
7
|
+
import type { FxSqlQuery } from "../Typo/Query";
|
|
8
|
+
import type { FxSqlQuerySql } from "../Typo/Sql";
|
|
9
|
+
|
|
10
|
+
const DataTypes = {
|
|
11
|
+
isSQLITE: true,
|
|
12
|
+
id: 'INTEGER PRIMARY KEY AUTOINCREMENT',
|
|
13
|
+
int: 'INTEGER',
|
|
14
|
+
float: 'FLOAT(12,2)',
|
|
15
|
+
bool: 'TINYINT(1)',
|
|
16
|
+
text: 'TEXT'
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
function escape (
|
|
20
|
+
query: FxSqlQuerySql.SqlFragmentStr,
|
|
21
|
+
args: FxSqlQuerySql.SqlAssignmentValues
|
|
22
|
+
) {
|
|
23
|
+
return helpers.escapeQuery(Dialect, query, args);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const escapeId = mysql.escapeId;
|
|
27
|
+
|
|
28
|
+
function escapeVal (this: any, val: any, timeZone?: FxSqlQuery.FxSqlQueryTimezone): any {
|
|
29
|
+
if (val === undefined || val === null || typeof val === "symbol") {
|
|
30
|
+
return 'NULL';
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
if (Array.isArray(val)) {
|
|
34
|
+
if (val.length === 1 && Array.isArray(val[0])) {
|
|
35
|
+
return "(" + val[0].map((v: any) => escapeVal.call(this, v)) + ")";
|
|
36
|
+
}
|
|
37
|
+
return "(" + val.map((v: any) => escapeVal.call(this, v)).join(", ") + ")";
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
if (util.isDate(val)) {
|
|
41
|
+
return "'" + helpers.dateToString(val, timeZone || "local", { dialect: 'sqlite' }) + "'";
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
if (Buffer.isBuffer(val)) {
|
|
45
|
+
return helpers.bufferToString( val, 'sqlite');
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
switch (typeof val) {
|
|
49
|
+
case "number":
|
|
50
|
+
if (!isFinite(val)) {
|
|
51
|
+
val = val.toString();
|
|
52
|
+
break;
|
|
53
|
+
}
|
|
54
|
+
return val;
|
|
55
|
+
case "boolean":
|
|
56
|
+
return val ? 1 : 0;
|
|
57
|
+
case "function":
|
|
58
|
+
return val(Dialect);
|
|
59
|
+
case "string":
|
|
60
|
+
break;
|
|
61
|
+
case "bigint":
|
|
62
|
+
return val.toString();
|
|
63
|
+
default:
|
|
64
|
+
val = JSON.stringify(val);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return "'" + val.replace(/\'/g, "''") + "'";
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
const Dialect: FxSqlQueryDialect.Dialect = ({
|
|
71
|
+
type: 'sqlite' as const,
|
|
72
|
+
DataTypes,
|
|
73
|
+
escape,
|
|
74
|
+
escapeId,
|
|
75
|
+
escapeVal,
|
|
76
|
+
limitAsTop: false,
|
|
77
|
+
knex: null as any
|
|
78
|
+
} as any);
|
|
79
|
+
|
|
80
|
+
export default Dialect
|