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,3228 @@
|
|
|
1
|
+
import { createRequire } from 'node:module';
|
|
2
|
+
const require = createRequire(import.meta.url);
|
|
3
|
+
// Originally based on contributions to DefinitelyTyped:
|
|
4
|
+
// Definitions by: Qubo <https://github.com/tkQubo>
|
|
5
|
+
// Pablo Rodríguez <https://github.com/MeLlamoPablo>
|
|
6
|
+
// Matt R. Wilson <https://github.com/mastermatt>
|
|
7
|
+
// Satana Charuwichitratana <https://github.com/micksatana>
|
|
8
|
+
// Shrey Jain <https://github.com/shreyjain1994>
|
|
9
|
+
// TypeScript Version: 4.1
|
|
10
|
+
import type { Pool as TarnPool } from './deps/tarn/Pool';
|
|
11
|
+
const events = require('events');
|
|
12
|
+
const stream = require('stream');
|
|
13
|
+
const ResultTypes = require('./result');
|
|
14
|
+
|
|
15
|
+
import type { Tables } from './tables';
|
|
16
|
+
|
|
17
|
+
// # Generic type-level utilities
|
|
18
|
+
|
|
19
|
+
// If T is object then make it a partial otherwise fallback to any
|
|
20
|
+
//
|
|
21
|
+
// This is primarily to prevent type incompatibilities where target can be unknown.
|
|
22
|
+
// While unknown can be assigned to any, Partial<unknown> can't be.
|
|
23
|
+
type SafePartial<T> = Partial<AnyOrUnknownToOther<T, {}>>;
|
|
24
|
+
|
|
25
|
+
type MaybeArray<T> = T | T[];
|
|
26
|
+
|
|
27
|
+
type StrKey<T> = string & keyof T;
|
|
28
|
+
|
|
29
|
+
// If T is unknown then convert to any, else retain original
|
|
30
|
+
type UnknownToAny<T> = unknown extends T ? any : T;
|
|
31
|
+
type CurlyCurlyToAny<T> = T extends unknown // distribute
|
|
32
|
+
? (<U>() => U extends T ? 0 : 1) extends <U>() => U extends {} ? 0 : 1
|
|
33
|
+
? any
|
|
34
|
+
: T
|
|
35
|
+
: never;
|
|
36
|
+
type UnknownOrCurlyCurlyToAny<T> = [UnknownToAny<T> | CurlyCurlyToAny<T>][0];
|
|
37
|
+
type AnyToUnknown<T> = unknown extends T ? unknown : T;
|
|
38
|
+
type AnyOrUnknownToOther<T1, T2> = unknown extends T1 ? T2 : T1;
|
|
39
|
+
|
|
40
|
+
// Intersection conditionally applied only when TParams is non-empty
|
|
41
|
+
// This is primarily to keep the signatures more intuitive.
|
|
42
|
+
type AugmentParams<TTarget, TParams> = TParams extends {}
|
|
43
|
+
? keyof TParams extends never
|
|
44
|
+
? TTarget
|
|
45
|
+
: {} & TTarget & TParams
|
|
46
|
+
: TTarget;
|
|
47
|
+
|
|
48
|
+
// Check if provided keys (expressed as a single or union type) are members of TBase
|
|
49
|
+
type AreKeysOf<TBase, TKeys> = Boxed<TKeys> extends Boxed<keyof TBase>
|
|
50
|
+
? true
|
|
51
|
+
: false;
|
|
52
|
+
|
|
53
|
+
// https://stackoverflow.com/a/50375286/476712
|
|
54
|
+
type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (
|
|
55
|
+
k: infer I
|
|
56
|
+
) => void
|
|
57
|
+
? I
|
|
58
|
+
: never;
|
|
59
|
+
|
|
60
|
+
type ComparisonOperator = '=' | '>' | '>=' | '<' | '<=' | '<>';
|
|
61
|
+
|
|
62
|
+
// If T is an array, get the type of member, else fall back to never
|
|
63
|
+
type ArrayMember<T> = T extends (infer M)[] ? M : never;
|
|
64
|
+
|
|
65
|
+
// If T is an array, get the type of member, else retain original
|
|
66
|
+
type UnwrapArrayMember<T> = T extends (infer M)[] ? M : T;
|
|
67
|
+
|
|
68
|
+
// Wrap a type in a container, making it an object type.
|
|
69
|
+
// This is primarily useful in circumventing special handling of union/intersection in typescript
|
|
70
|
+
interface Boxed<T> {
|
|
71
|
+
_value: T;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// If T can't be assigned to TBase fallback to an alternate type TAlt
|
|
75
|
+
type IncompatibleToAlt<T, TBase, TAlt> = T extends TBase ? T : TAlt;
|
|
76
|
+
|
|
77
|
+
type ArrayIfAlready<T1, T2> = AnyToUnknown<T1> extends any[] ? T2[] : T2;
|
|
78
|
+
|
|
79
|
+
// Boxing is necessary to prevent distribution of conditional types:
|
|
80
|
+
// https://lorefnon.tech/2019/05/02/using-boxing-to-prevent-distribution-of-conditional-types/
|
|
81
|
+
type PartialOrAny<TBase, TKeys> = Boxed<TKeys> extends Boxed<never>
|
|
82
|
+
? {}
|
|
83
|
+
: Boxed<TKeys> extends Boxed<keyof TBase>
|
|
84
|
+
? SafePick<TBase, TKeys & keyof TBase>
|
|
85
|
+
: any;
|
|
86
|
+
|
|
87
|
+
// Retain the association of original keys with aliased keys at type level
|
|
88
|
+
// to facilitates type-safe aliasing for object syntax
|
|
89
|
+
type MappedAliasType<TBase, TAliasMapping> = {} & {
|
|
90
|
+
[K in keyof TAliasMapping]: TAliasMapping[K] extends keyof TBase
|
|
91
|
+
? TBase[TAliasMapping[K]]
|
|
92
|
+
: any;
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
// Container type for situations when we want a partial/intersection eventually
|
|
96
|
+
// but the keys being selected or additional properties being augmented are not
|
|
97
|
+
// all known at once and we would want to effectively build up a partial/intersection
|
|
98
|
+
// over multiple steps.
|
|
99
|
+
type DeferredKeySelection<
|
|
100
|
+
// The base of selection. In intermediate stages this may be unknown.
|
|
101
|
+
// If it remains unknown at the point of resolution, the selection will fall back to any
|
|
102
|
+
TBase,
|
|
103
|
+
// Union of keys to be selected
|
|
104
|
+
// In intermediate stages this may be never.
|
|
105
|
+
TKeys extends string,
|
|
106
|
+
// Changes how the resolution should behave if TKeys is never.
|
|
107
|
+
// If true, then we assume that some keys were selected, and if TKeys is never, we will fall back to any.
|
|
108
|
+
// If false, and TKeys is never, then we select TBase in its entirety
|
|
109
|
+
THasSelect extends true | false = false,
|
|
110
|
+
// Mapping of aliases <key in result> -> <key in TBase>
|
|
111
|
+
TAliasMapping extends {} = {},
|
|
112
|
+
// If enabled, then instead of extracting a partial, during resolution
|
|
113
|
+
// we will pick just a single property.
|
|
114
|
+
TSingle extends boolean = false,
|
|
115
|
+
// Extra props which will be intersected with the result
|
|
116
|
+
TIntersectProps extends {} = {},
|
|
117
|
+
// Extra props which will be unioned with the result
|
|
118
|
+
TUnionProps = never
|
|
119
|
+
> = {
|
|
120
|
+
// These properties are not actually used, but exist simply because
|
|
121
|
+
// typescript doesn't end up happy when type parameters are unused
|
|
122
|
+
_base: TBase;
|
|
123
|
+
_hasSelection: THasSelect;
|
|
124
|
+
_keys: TKeys;
|
|
125
|
+
_aliases: TAliasMapping;
|
|
126
|
+
_single: TSingle;
|
|
127
|
+
_intersectProps: TIntersectProps;
|
|
128
|
+
_unionProps: TUnionProps;
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
// An companion namespace for DeferredKeySelection which provides type operators
|
|
132
|
+
// to build up participants of intersection/partial over multiple invocations
|
|
133
|
+
// and for final resolution.
|
|
134
|
+
//
|
|
135
|
+
// While the comments use wordings such as replacement and addition, it is important
|
|
136
|
+
// to keep in mind that types are always immutable and all type operators return new altered types.
|
|
137
|
+
declare namespace DeferredKeySelection {
|
|
138
|
+
type Any = DeferredKeySelection<any, any, any, any, any, any, any>;
|
|
139
|
+
|
|
140
|
+
// Replace the Base if already a deferred selection.
|
|
141
|
+
// If not, create a new deferred selection with specified base.
|
|
142
|
+
type SetBase<TSelection, TBase> = TSelection extends DeferredKeySelection<
|
|
143
|
+
any,
|
|
144
|
+
infer TKeys,
|
|
145
|
+
infer THasSelect,
|
|
146
|
+
infer TAliasMapping,
|
|
147
|
+
infer TSingle,
|
|
148
|
+
infer TIntersectProps,
|
|
149
|
+
infer TUnionProps
|
|
150
|
+
>
|
|
151
|
+
? DeferredKeySelection<
|
|
152
|
+
TBase,
|
|
153
|
+
TKeys,
|
|
154
|
+
THasSelect,
|
|
155
|
+
TAliasMapping,
|
|
156
|
+
TSingle,
|
|
157
|
+
TIntersectProps,
|
|
158
|
+
TUnionProps
|
|
159
|
+
>
|
|
160
|
+
: DeferredKeySelection<TBase, never>;
|
|
161
|
+
|
|
162
|
+
// If TSelection is already a deferred selection, then replace the base with TBase
|
|
163
|
+
// If unknown, create a new deferred selection with TBase as the base
|
|
164
|
+
// Else, retain original
|
|
165
|
+
//
|
|
166
|
+
// For practical reasons applicable to current context, we always return arrays of
|
|
167
|
+
// deferred selections. So, this particular operator may not be useful in generic contexts.
|
|
168
|
+
type ReplaceBase<TSelection, TBase> =
|
|
169
|
+
UnwrapArrayMember<TSelection> extends DeferredKeySelection.Any
|
|
170
|
+
? ArrayIfAlready<
|
|
171
|
+
TSelection,
|
|
172
|
+
DeferredKeySelection.SetBase<UnwrapArrayMember<TSelection>, TBase>
|
|
173
|
+
>
|
|
174
|
+
: unknown extends UnwrapArrayMember<TSelection>
|
|
175
|
+
? ArrayIfAlready<TSelection, DeferredKeySelection.SetBase<unknown, TBase>>
|
|
176
|
+
: TSelection;
|
|
177
|
+
|
|
178
|
+
// Type operators to substitute individual type parameters:
|
|
179
|
+
|
|
180
|
+
type SetSingle<
|
|
181
|
+
TSelection,
|
|
182
|
+
TSingle extends boolean
|
|
183
|
+
> = TSelection extends DeferredKeySelection<
|
|
184
|
+
infer TBase,
|
|
185
|
+
infer TKeys,
|
|
186
|
+
infer THasSelect,
|
|
187
|
+
infer TAliasMapping,
|
|
188
|
+
any,
|
|
189
|
+
infer TIntersectProps,
|
|
190
|
+
infer TUnionProps
|
|
191
|
+
>
|
|
192
|
+
? DeferredKeySelection<
|
|
193
|
+
TBase,
|
|
194
|
+
TKeys,
|
|
195
|
+
THasSelect,
|
|
196
|
+
TAliasMapping,
|
|
197
|
+
TSingle,
|
|
198
|
+
TIntersectProps,
|
|
199
|
+
TUnionProps
|
|
200
|
+
>
|
|
201
|
+
: never;
|
|
202
|
+
|
|
203
|
+
type AddKey<
|
|
204
|
+
TSelection,
|
|
205
|
+
TKey extends string
|
|
206
|
+
> = TSelection extends DeferredKeySelection<
|
|
207
|
+
infer TBase,
|
|
208
|
+
infer TKeys,
|
|
209
|
+
any,
|
|
210
|
+
infer TAliasMapping,
|
|
211
|
+
infer TSingle,
|
|
212
|
+
infer TIntersectProps,
|
|
213
|
+
infer TUnionProps
|
|
214
|
+
>
|
|
215
|
+
? DeferredKeySelection<
|
|
216
|
+
TBase,
|
|
217
|
+
TKeys | TKey,
|
|
218
|
+
true,
|
|
219
|
+
TAliasMapping,
|
|
220
|
+
TSingle,
|
|
221
|
+
TIntersectProps,
|
|
222
|
+
TUnionProps
|
|
223
|
+
>
|
|
224
|
+
: DeferredKeySelection<unknown, TKey, true>;
|
|
225
|
+
|
|
226
|
+
type AddAliases<
|
|
227
|
+
TSelection,
|
|
228
|
+
T extends {}
|
|
229
|
+
> = TSelection extends DeferredKeySelection<
|
|
230
|
+
infer TBase,
|
|
231
|
+
infer TKeys,
|
|
232
|
+
infer THasSelect,
|
|
233
|
+
infer TAliasMapping,
|
|
234
|
+
infer TSingle,
|
|
235
|
+
infer TIntersectProps,
|
|
236
|
+
infer TUnionProps
|
|
237
|
+
>
|
|
238
|
+
? DeferredKeySelection<
|
|
239
|
+
TBase,
|
|
240
|
+
TKeys,
|
|
241
|
+
THasSelect,
|
|
242
|
+
TAliasMapping & T,
|
|
243
|
+
TSingle,
|
|
244
|
+
TIntersectProps,
|
|
245
|
+
TUnionProps
|
|
246
|
+
>
|
|
247
|
+
: DeferredKeySelection<unknown, never, false, T>;
|
|
248
|
+
|
|
249
|
+
type AddUnionMember<TSelection, T> = TSelection extends DeferredKeySelection<
|
|
250
|
+
infer TBase,
|
|
251
|
+
infer TKeys,
|
|
252
|
+
infer THasSelect,
|
|
253
|
+
infer TAliasMapping,
|
|
254
|
+
infer TSingle,
|
|
255
|
+
infer TIntersectProps,
|
|
256
|
+
infer TUnionProps
|
|
257
|
+
>
|
|
258
|
+
? DeferredKeySelection<
|
|
259
|
+
TBase,
|
|
260
|
+
TKeys,
|
|
261
|
+
THasSelect,
|
|
262
|
+
TAliasMapping,
|
|
263
|
+
TSingle,
|
|
264
|
+
TIntersectProps,
|
|
265
|
+
TUnionProps | T
|
|
266
|
+
>
|
|
267
|
+
: DeferredKeySelection<TSelection, never, false, {}, false, {}, T>;
|
|
268
|
+
|
|
269
|
+
// Convenience utility to set base, keys and aliases in a single type
|
|
270
|
+
// application
|
|
271
|
+
type Augment<
|
|
272
|
+
T,
|
|
273
|
+
TBase,
|
|
274
|
+
TKey extends string,
|
|
275
|
+
TAliasMapping extends {} = {}
|
|
276
|
+
> = AddAliases<AddKey<SetBase<T, TBase>, TKey>, TAliasMapping>;
|
|
277
|
+
|
|
278
|
+
// Core resolution logic -- Refer to docs for DeferredKeySelection for specifics
|
|
279
|
+
type ResolveOne<TSelection> = TSelection extends DeferredKeySelection<
|
|
280
|
+
infer TBase,
|
|
281
|
+
infer TKeys,
|
|
282
|
+
infer THasSelect,
|
|
283
|
+
infer TAliasMapping,
|
|
284
|
+
infer TSingle,
|
|
285
|
+
infer TIntersectProps,
|
|
286
|
+
infer TUnionProps
|
|
287
|
+
>
|
|
288
|
+
? UnknownOrCurlyCurlyToAny<
|
|
289
|
+
// ^ We convert final result to any if it is unknown for backward compatibility.
|
|
290
|
+
// Historically knex typings have been liberal with returning any and changing
|
|
291
|
+
// default return type to unknown would be a major breaking change for users.
|
|
292
|
+
//
|
|
293
|
+
// So we compromise on type safety here and return any.
|
|
294
|
+
| AugmentParams<
|
|
295
|
+
AnyToUnknown<TBase> extends {}
|
|
296
|
+
? // ^ Conversion of any -> unknown is needed here to prevent distribution
|
|
297
|
+
// of any over the conditional
|
|
298
|
+
TSingle extends true
|
|
299
|
+
? TKeys extends keyof TBase
|
|
300
|
+
? TBase[TKeys]
|
|
301
|
+
: any
|
|
302
|
+
: AugmentParams<
|
|
303
|
+
true extends THasSelect
|
|
304
|
+
? PartialOrAny<TBase, TKeys>
|
|
305
|
+
: TBase,
|
|
306
|
+
MappedAliasType<TBase, TAliasMapping>
|
|
307
|
+
>
|
|
308
|
+
: unknown,
|
|
309
|
+
TIntersectProps
|
|
310
|
+
>
|
|
311
|
+
| TUnionProps
|
|
312
|
+
>
|
|
313
|
+
: TSelection;
|
|
314
|
+
|
|
315
|
+
type Resolve<TSelection> = TSelection extends DeferredKeySelection.Any
|
|
316
|
+
? Knex.ResolveTableType<ResolveOne<TSelection>>
|
|
317
|
+
: TSelection extends DeferredKeySelection.Any[]
|
|
318
|
+
? Knex.ResolveTableType<ResolveOne<TSelection[0]>>[]
|
|
319
|
+
: TSelection extends (infer I)[]
|
|
320
|
+
? UnknownOrCurlyCurlyToAny<Knex.ResolveTableType<I>>[]
|
|
321
|
+
: UnknownOrCurlyCurlyToAny<Knex.ResolveTableType<TSelection>>;
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
type AggregationQueryResult<
|
|
325
|
+
TResult,
|
|
326
|
+
TIntersectProps2 extends {}
|
|
327
|
+
> = ArrayIfAlready<
|
|
328
|
+
TResult,
|
|
329
|
+
UnwrapArrayMember<TResult> extends DeferredKeySelection<
|
|
330
|
+
infer TBase,
|
|
331
|
+
infer TKeys,
|
|
332
|
+
infer THasSelect,
|
|
333
|
+
infer TAliasMapping,
|
|
334
|
+
infer TSingle,
|
|
335
|
+
infer TIntersectProps,
|
|
336
|
+
infer TUnionProps
|
|
337
|
+
>
|
|
338
|
+
? true extends THasSelect
|
|
339
|
+
? DeferredKeySelection<
|
|
340
|
+
TBase,
|
|
341
|
+
TKeys,
|
|
342
|
+
THasSelect,
|
|
343
|
+
TAliasMapping,
|
|
344
|
+
TSingle,
|
|
345
|
+
TIntersectProps & TIntersectProps2,
|
|
346
|
+
TUnionProps
|
|
347
|
+
>
|
|
348
|
+
: DeferredKeySelection<{}, never, true, {}, false, TIntersectProps2>
|
|
349
|
+
: TIntersectProps2
|
|
350
|
+
>;
|
|
351
|
+
|
|
352
|
+
// If we have more categories of deferred selection in future,
|
|
353
|
+
// this will combine all of them
|
|
354
|
+
type ResolveResult<S> = DeferredKeySelection.Resolve<S>;
|
|
355
|
+
|
|
356
|
+
// # Type-aliases for common type combinations
|
|
357
|
+
|
|
358
|
+
type Callback = Function;
|
|
359
|
+
type Client = Function;
|
|
360
|
+
|
|
361
|
+
type Dict<T = any> = { [k: string]: T };
|
|
362
|
+
|
|
363
|
+
type SafePick<T, K extends keyof T> = T extends {} ? Pick<T, K> : any;
|
|
364
|
+
|
|
365
|
+
type TableOptions = PgTableOptions;
|
|
366
|
+
|
|
367
|
+
interface PgTableOptions {
|
|
368
|
+
only?: boolean;
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
interface DMLOptions {
|
|
372
|
+
includeTriggerModifications?: boolean;
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
export interface Knex<TRecord extends {} = any, TResult = any[]>
|
|
376
|
+
extends Knex.QueryInterface<TRecord, TResult>,
|
|
377
|
+
Class_EventEmitter {
|
|
378
|
+
<TTable extends Knex.TableNames>(
|
|
379
|
+
tableName: TTable,
|
|
380
|
+
options?: TableOptions
|
|
381
|
+
): Knex.QueryBuilder<
|
|
382
|
+
Knex.TableType<TTable>,
|
|
383
|
+
DeferredKeySelection<Knex.ResolveTableType<Knex.TableType<TTable>>, never>[]
|
|
384
|
+
>;
|
|
385
|
+
<
|
|
386
|
+
TRecord2 extends {} = TRecord,
|
|
387
|
+
TResult2 = DeferredKeySelection<TRecord2, never>[]
|
|
388
|
+
>(
|
|
389
|
+
tableName?: Knex.TableDescriptor | Knex.AliasDict,
|
|
390
|
+
options?: TableOptions
|
|
391
|
+
): Knex.QueryBuilder<TRecord2, TResult2>;
|
|
392
|
+
VERSION: string;
|
|
393
|
+
__knex__: string;
|
|
394
|
+
|
|
395
|
+
raw: Knex.RawBuilder<TRecord>;
|
|
396
|
+
|
|
397
|
+
transactionProvider(
|
|
398
|
+
config?: Knex.TransactionConfig
|
|
399
|
+
): Knex.TransactionProvider;
|
|
400
|
+
transaction(config?: Knex.TransactionConfig): Promise<Knex.Transaction>;
|
|
401
|
+
transaction(
|
|
402
|
+
transactionScope?: null,
|
|
403
|
+
config?: Knex.TransactionConfig
|
|
404
|
+
): Promise<Knex.Transaction>;
|
|
405
|
+
transaction<T>(
|
|
406
|
+
transactionScope: (trx: Knex.Transaction) => Promise<T> | void,
|
|
407
|
+
config?: Knex.TransactionConfig
|
|
408
|
+
): Promise<T>;
|
|
409
|
+
initialize(config?: Knex.Config): void;
|
|
410
|
+
destroy(callback: Function): void;
|
|
411
|
+
destroy(): Promise<void>;
|
|
412
|
+
|
|
413
|
+
batchInsert<TRecord2 extends {} = TRecord, TResult2 = number[]>(
|
|
414
|
+
tableName: Knex.TableDescriptor,
|
|
415
|
+
data: TRecord2 extends Knex.CompositeTableType<unknown>
|
|
416
|
+
? ReadonlyArray<Knex.ResolveTableType<TRecord2, 'insert'>>
|
|
417
|
+
: ReadonlyArray<Knex.DbRecordArr<TRecord2>>,
|
|
418
|
+
chunkSize?: number
|
|
419
|
+
): Knex.BatchInsertBuilder<TRecord2, TResult2>;
|
|
420
|
+
|
|
421
|
+
schema: Knex.SchemaBuilder;
|
|
422
|
+
queryBuilder<
|
|
423
|
+
TRecord2 extends {} = TRecord,
|
|
424
|
+
TResult2 = TResult
|
|
425
|
+
>(): Knex.QueryBuilder<TRecord2, TResult2>;
|
|
426
|
+
|
|
427
|
+
client: any;
|
|
428
|
+
migrate: Knex.Migrator;
|
|
429
|
+
seed: Knex.Seeder;
|
|
430
|
+
fn: Knex.FunctionHelper;
|
|
431
|
+
ref: Knex.RefBuilder;
|
|
432
|
+
userParams: Record<string, any>;
|
|
433
|
+
withUserParams(params: Record<string, any>): Knex;
|
|
434
|
+
isTransaction?: boolean;
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
export declare function knex<TRecord extends {} = any, TResult = unknown[]>(
|
|
438
|
+
config: Knex.Config | string
|
|
439
|
+
): Knex<TRecord, TResult>;
|
|
440
|
+
|
|
441
|
+
export declare namespace knex {
|
|
442
|
+
class QueryBuilder {
|
|
443
|
+
static extend(
|
|
444
|
+
methodName: string,
|
|
445
|
+
fn: <TRecord extends {} = any, TResult extends {} = unknown[]>(
|
|
446
|
+
this: Knex.QueryBuilder<TRecord, TResult>,
|
|
447
|
+
...args: any[]
|
|
448
|
+
) =>
|
|
449
|
+
| Knex.QueryBuilder<TRecord, TResult>
|
|
450
|
+
| Promise<
|
|
451
|
+
| Knex.QueryBuilder<TRecord | TResult>
|
|
452
|
+
| DeferredKeySelection.Resolve<TResult>
|
|
453
|
+
>
|
|
454
|
+
): void;
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
class TableBuilder {
|
|
458
|
+
static extend<T = Knex.TableBuilder, B = Knex.TableBuilder>(
|
|
459
|
+
methodName: string,
|
|
460
|
+
fn: (this: T, ...args: any[]) => B
|
|
461
|
+
): void;
|
|
462
|
+
}
|
|
463
|
+
class ViewBuilder {
|
|
464
|
+
static extend<T = Knex.ViewBuilder, B = Knex.ViewBuilder>(
|
|
465
|
+
methodName: string,
|
|
466
|
+
fn: (this: T, ...args: any[]) => B
|
|
467
|
+
): void;
|
|
468
|
+
}
|
|
469
|
+
class SchemaBuilder {
|
|
470
|
+
static extend<T = Knex.SchemaBuilder, B = Knex.SchemaBuilder>(
|
|
471
|
+
methodName: string,
|
|
472
|
+
fn: (this: T, ...args: any[]) => B
|
|
473
|
+
): void;
|
|
474
|
+
}
|
|
475
|
+
class ColumnBuilder {
|
|
476
|
+
static extend<T = Knex.ColumnBuilder, B = Knex.ColumnBuilder>(
|
|
477
|
+
methodName: string,
|
|
478
|
+
fn: (this: T, ...args: any[]) => B
|
|
479
|
+
): void;
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
export class KnexTimeoutError extends Error {}
|
|
483
|
+
|
|
484
|
+
export const Client: typeof Knex.Client;
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
export declare namespace Knex {
|
|
488
|
+
//
|
|
489
|
+
// Utility Types
|
|
490
|
+
//
|
|
491
|
+
|
|
492
|
+
type Value =
|
|
493
|
+
| string
|
|
494
|
+
| number
|
|
495
|
+
| boolean
|
|
496
|
+
| null
|
|
497
|
+
| Date
|
|
498
|
+
| Array<string>
|
|
499
|
+
| Array<number>
|
|
500
|
+
| Array<Date>
|
|
501
|
+
| Array<boolean>
|
|
502
|
+
| Class_Buffer
|
|
503
|
+
| object
|
|
504
|
+
| Knex.Raw;
|
|
505
|
+
|
|
506
|
+
interface ValueDict extends Dict<Value | Knex.QueryBuilder> {}
|
|
507
|
+
interface AliasDict extends Dict<string> {}
|
|
508
|
+
|
|
509
|
+
type ColumnDescriptor<TRecord extends {}, TResult> =
|
|
510
|
+
| string
|
|
511
|
+
| Knex.Raw
|
|
512
|
+
| Knex.QueryBuilder<TRecord, TResult>
|
|
513
|
+
| Dict<string>;
|
|
514
|
+
|
|
515
|
+
type InferrableColumnDescriptor<TRecord extends {}> =
|
|
516
|
+
| keyof TRecord
|
|
517
|
+
| Knex.Ref<any, any>
|
|
518
|
+
| Dict<keyof TRecord>;
|
|
519
|
+
|
|
520
|
+
type TableDescriptor = string | Knex.Raw | Knex.QueryBuilder;
|
|
521
|
+
|
|
522
|
+
type Lookup<
|
|
523
|
+
TRegistry extends {},
|
|
524
|
+
TKey extends string,
|
|
525
|
+
TDefault = never
|
|
526
|
+
> = TKey extends keyof TRegistry ? TRegistry[TKey] : TDefault;
|
|
527
|
+
|
|
528
|
+
type MaybeRawColumn<TColumn> = TColumn | Raw<TColumn>;
|
|
529
|
+
|
|
530
|
+
type MaybeRawRecord<TRecord> = {
|
|
531
|
+
[K in keyof TRecord]: MaybeRawColumn<TRecord[K]>;
|
|
532
|
+
};
|
|
533
|
+
|
|
534
|
+
type DbColumn<TColumn> = Readonly<MaybeRawColumn<TColumn>>;
|
|
535
|
+
|
|
536
|
+
type DbRecord<TRecord> = Readonly<SafePartial<MaybeRawRecord<TRecord>>>;
|
|
537
|
+
|
|
538
|
+
type DbRecordArr<TRecord> = Readonly<MaybeArray<DbRecord<TRecord>>>;
|
|
539
|
+
|
|
540
|
+
export type CompositeTableType<
|
|
541
|
+
TBase,
|
|
542
|
+
TInsert = TBase,
|
|
543
|
+
TUpdate = Partial<TInsert>,
|
|
544
|
+
TUpsert = Partial<TInsert>
|
|
545
|
+
> = {
|
|
546
|
+
base: TBase;
|
|
547
|
+
insert: TInsert;
|
|
548
|
+
update: TUpdate;
|
|
549
|
+
upsert: TUpsert;
|
|
550
|
+
};
|
|
551
|
+
|
|
552
|
+
type TableNames = keyof Tables;
|
|
553
|
+
|
|
554
|
+
type TableInterfaceScope = keyof CompositeTableType<unknown>;
|
|
555
|
+
|
|
556
|
+
type TableType<TTable extends keyof Tables> = Tables[TTable];
|
|
557
|
+
|
|
558
|
+
type ResolveTableType<
|
|
559
|
+
TCompositeTableType,
|
|
560
|
+
TScope extends TableInterfaceScope = 'base'
|
|
561
|
+
> = TCompositeTableType extends CompositeTableType<unknown>
|
|
562
|
+
? TCompositeTableType[TScope]
|
|
563
|
+
: TCompositeTableType;
|
|
564
|
+
|
|
565
|
+
interface OnConflictQueryBuilder<TRecord extends {}, TResult> {
|
|
566
|
+
ignore(): QueryBuilder<TRecord, TResult>;
|
|
567
|
+
merge(mergeColumns?: (keyof TRecord)[]): QueryBuilder<TRecord, TResult>;
|
|
568
|
+
merge(
|
|
569
|
+
data?: Extract<DbRecord<ResolveTableType<TRecord, 'update'>>, object>
|
|
570
|
+
): QueryBuilder<TRecord, TResult>;
|
|
571
|
+
}
|
|
572
|
+
|
|
573
|
+
//
|
|
574
|
+
// QueryInterface
|
|
575
|
+
//
|
|
576
|
+
type ClearStatements =
|
|
577
|
+
| 'with'
|
|
578
|
+
| 'select'
|
|
579
|
+
| 'columns'
|
|
580
|
+
| 'hintComments'
|
|
581
|
+
| 'where'
|
|
582
|
+
| 'union'
|
|
583
|
+
| 'using'
|
|
584
|
+
| 'join'
|
|
585
|
+
| 'group'
|
|
586
|
+
| 'order'
|
|
587
|
+
| 'having'
|
|
588
|
+
| 'limit'
|
|
589
|
+
| 'offset'
|
|
590
|
+
| 'counter'
|
|
591
|
+
| 'counters';
|
|
592
|
+
|
|
593
|
+
interface QueryInterface<TRecord extends {} = any, TResult = any> {
|
|
594
|
+
select: Select<TRecord, TResult>;
|
|
595
|
+
as: As<TRecord, TResult>;
|
|
596
|
+
columns: Select<TRecord, TResult>;
|
|
597
|
+
column: Select<TRecord, TResult>;
|
|
598
|
+
hintComment: HintComment<TRecord, TResult>;
|
|
599
|
+
from: Table<TRecord, TResult>;
|
|
600
|
+
fromRaw: Table<TRecord, TResult>;
|
|
601
|
+
into: Table<TRecord, TResult>;
|
|
602
|
+
table: Table<TRecord, TResult>;
|
|
603
|
+
distinct: Distinct<TRecord, TResult>;
|
|
604
|
+
distinctOn: DistinctOn<TRecord, TResult>;
|
|
605
|
+
|
|
606
|
+
// Joins
|
|
607
|
+
join: Join<TRecord, TResult>;
|
|
608
|
+
joinRaw: JoinRaw<TRecord, TResult>;
|
|
609
|
+
innerJoin: Join<TRecord, TResult>;
|
|
610
|
+
leftJoin: Join<TRecord, TResult>;
|
|
611
|
+
leftOuterJoin: Join<TRecord, TResult>;
|
|
612
|
+
rightJoin: Join<TRecord, TResult>;
|
|
613
|
+
rightOuterJoin: Join<TRecord, TResult>;
|
|
614
|
+
outerJoin: Join<TRecord, TResult>;
|
|
615
|
+
fullOuterJoin: Join<TRecord, TResult>;
|
|
616
|
+
crossJoin: Join<TRecord, TResult>;
|
|
617
|
+
|
|
618
|
+
// Json manipulation
|
|
619
|
+
jsonExtract: JsonExtract<TRecord, TResult>;
|
|
620
|
+
jsonSet: JsonSet<TRecord, TResult>;
|
|
621
|
+
jsonInsert: JsonInsert<TRecord, TResult>;
|
|
622
|
+
jsonRemove: JsonRemove<TRecord, TResult>;
|
|
623
|
+
|
|
624
|
+
// Using
|
|
625
|
+
using: Using<TRecord, TResult>;
|
|
626
|
+
|
|
627
|
+
// Withs
|
|
628
|
+
with: With<TRecord, TResult>;
|
|
629
|
+
withMaterialized: With<TRecord, TResult>;
|
|
630
|
+
withNotMaterialized: With<TRecord, TResult>;
|
|
631
|
+
withRecursive: With<TRecord, TResult>;
|
|
632
|
+
withRaw: WithRaw<TRecord, TResult>;
|
|
633
|
+
withSchema: WithSchema<TRecord, TResult>;
|
|
634
|
+
withWrapped: WithWrapped<TRecord, TResult>;
|
|
635
|
+
|
|
636
|
+
// Wheres
|
|
637
|
+
where: Where<TRecord, TResult>;
|
|
638
|
+
andWhere: Where<TRecord, TResult>;
|
|
639
|
+
orWhere: Where<TRecord, TResult>;
|
|
640
|
+
whereNot: Where<TRecord, TResult>;
|
|
641
|
+
andWhereNot: Where<TRecord, TResult>;
|
|
642
|
+
orWhereNot: Where<TRecord, TResult>;
|
|
643
|
+
whereRaw: WhereRaw<TRecord, TResult>;
|
|
644
|
+
orWhereRaw: WhereRaw<TRecord, TResult>;
|
|
645
|
+
andWhereRaw: WhereRaw<TRecord, TResult>;
|
|
646
|
+
whereWrapped: WhereWrapped<TRecord, TResult>;
|
|
647
|
+
havingWrapped: WhereWrapped<TRecord, TResult>;
|
|
648
|
+
whereExists: WhereExists<TRecord, TResult>;
|
|
649
|
+
orWhereExists: WhereExists<TRecord, TResult>;
|
|
650
|
+
whereNotExists: WhereExists<TRecord, TResult>;
|
|
651
|
+
orWhereNotExists: WhereExists<TRecord, TResult>;
|
|
652
|
+
whereIn: WhereIn<TRecord, TResult>;
|
|
653
|
+
orWhereIn: WhereIn<TRecord, TResult>;
|
|
654
|
+
whereNotIn: WhereIn<TRecord, TResult>;
|
|
655
|
+
orWhereNotIn: WhereIn<TRecord, TResult>;
|
|
656
|
+
whereLike: Where<TRecord, TResult>;
|
|
657
|
+
andWhereLike: Where<TRecord, TResult>;
|
|
658
|
+
orWhereLike: Where<TRecord, TResult>;
|
|
659
|
+
whereILike: Where<TRecord, TResult>;
|
|
660
|
+
andWhereILike: Where<TRecord, TResult>;
|
|
661
|
+
orWhereILike: Where<TRecord, TResult>;
|
|
662
|
+
whereNull: WhereNull<TRecord, TResult>;
|
|
663
|
+
orWhereNull: WhereNull<TRecord, TResult>;
|
|
664
|
+
whereNotNull: WhereNull<TRecord, TResult>;
|
|
665
|
+
orWhereNotNull: WhereNull<TRecord, TResult>;
|
|
666
|
+
whereBetween: WhereBetween<TRecord, TResult>;
|
|
667
|
+
orWhereBetween: WhereBetween<TRecord, TResult>;
|
|
668
|
+
andWhereBetween: WhereBetween<TRecord, TResult>;
|
|
669
|
+
whereNotBetween: WhereBetween<TRecord, TResult>;
|
|
670
|
+
orWhereNotBetween: WhereBetween<TRecord, TResult>;
|
|
671
|
+
andWhereNotBetween: WhereBetween<TRecord, TResult>;
|
|
672
|
+
|
|
673
|
+
whereJsonObject: WhereJsonObject<TRecord, TResult>;
|
|
674
|
+
orWhereJsonObject: WhereJsonObject<TRecord, TResult>;
|
|
675
|
+
andWhereJsonObject: WhereJsonObject<TRecord, TResult>;
|
|
676
|
+
whereNotJsonObject: WhereJsonObject<TRecord, TResult>;
|
|
677
|
+
orWhereNotJsonObject: WhereJsonObject<TRecord, TResult>;
|
|
678
|
+
andWhereNotJsonObject: WhereJsonObject<TRecord, TResult>;
|
|
679
|
+
|
|
680
|
+
whereJsonPath: WhereJsonPath<TRecord, TResult>;
|
|
681
|
+
orWhereJsonPath: WhereJsonPath<TRecord, TResult>;
|
|
682
|
+
andWhereJsonPath: WhereJsonPath<TRecord, TResult>;
|
|
683
|
+
|
|
684
|
+
whereJsonSupersetOf: WhereJsonObject<TRecord, TResult>;
|
|
685
|
+
orWhereJsonSupersetOf: WhereJsonObject<TRecord, TResult>;
|
|
686
|
+
andWhereJsonSupersetOf: WhereJsonObject<TRecord, TResult>;
|
|
687
|
+
whereJsonNotSupersetOf: WhereJsonObject<TRecord, TResult>;
|
|
688
|
+
orWhereJsonNotSupersetOf: WhereJsonObject<TRecord, TResult>;
|
|
689
|
+
andWhereJsonNotSupersetOf: WhereJsonObject<TRecord, TResult>;
|
|
690
|
+
|
|
691
|
+
whereJsonSubsetOf: WhereJsonObject<TRecord, TResult>;
|
|
692
|
+
orWhereJsonSubsetOf: WhereJsonObject<TRecord, TResult>;
|
|
693
|
+
andWhereJsonSubsetOf: WhereJsonObject<TRecord, TResult>;
|
|
694
|
+
whereJsonNotSubsetOf: WhereJsonObject<TRecord, TResult>;
|
|
695
|
+
orWhereJsonNotSubsetOf: WhereJsonObject<TRecord, TResult>;
|
|
696
|
+
andWhereJsonNotSubsetOf: WhereJsonObject<TRecord, TResult>;
|
|
697
|
+
|
|
698
|
+
// Group by
|
|
699
|
+
groupBy: GroupBy<TRecord, TResult>;
|
|
700
|
+
groupByRaw: RawQueryBuilder<TRecord, TResult>;
|
|
701
|
+
|
|
702
|
+
// Order by
|
|
703
|
+
orderBy: OrderBy<TRecord, TResult>;
|
|
704
|
+
orderByRaw: RawQueryBuilder<TRecord, TResult>;
|
|
705
|
+
|
|
706
|
+
// Partition by
|
|
707
|
+
partitionBy: PartitionBy<TRecord, TResult>;
|
|
708
|
+
|
|
709
|
+
// Intersect
|
|
710
|
+
intersect: Intersect<TRecord, TResult>;
|
|
711
|
+
|
|
712
|
+
// Union
|
|
713
|
+
union: Union<TRecord, TResult>;
|
|
714
|
+
unionAll: Union<TRecord, TResult>;
|
|
715
|
+
|
|
716
|
+
// Having
|
|
717
|
+
having: Having<TRecord, TResult>;
|
|
718
|
+
andHaving: Having<TRecord, TResult>;
|
|
719
|
+
havingRaw: RawQueryBuilder<TRecord, TResult>;
|
|
720
|
+
orHaving: Having<TRecord, TResult>;
|
|
721
|
+
orHavingRaw: RawQueryBuilder<TRecord, TResult>;
|
|
722
|
+
havingIn: HavingRange<TRecord, TResult>;
|
|
723
|
+
orHavingNotBetween: HavingRange<TRecord, TResult>;
|
|
724
|
+
havingNotBetween: HavingRange<TRecord, TResult>;
|
|
725
|
+
orHavingBetween: HavingRange<TRecord, TResult>;
|
|
726
|
+
havingBetween: HavingRange<TRecord, TResult>;
|
|
727
|
+
havingNotIn: HavingRange<TRecord, TResult>;
|
|
728
|
+
andHavingNotIn: HavingRange<TRecord, TResult>;
|
|
729
|
+
orHavingNotIn: HavingRange<TRecord, TResult>;
|
|
730
|
+
|
|
731
|
+
// Clear
|
|
732
|
+
clearSelect(): QueryBuilder<
|
|
733
|
+
TRecord,
|
|
734
|
+
UnwrapArrayMember<TResult> extends DeferredKeySelection<
|
|
735
|
+
infer TBase,
|
|
736
|
+
infer TKeys,
|
|
737
|
+
true,
|
|
738
|
+
any,
|
|
739
|
+
any,
|
|
740
|
+
any,
|
|
741
|
+
any
|
|
742
|
+
>
|
|
743
|
+
? DeferredKeySelection<TBase, never>[]
|
|
744
|
+
: TResult
|
|
745
|
+
>;
|
|
746
|
+
clearWhere(): QueryBuilder<TRecord, TResult>;
|
|
747
|
+
clearGroup(): QueryBuilder<TRecord, TResult>;
|
|
748
|
+
clearOrder(): QueryBuilder<TRecord, TResult>;
|
|
749
|
+
clearHaving(): QueryBuilder<TRecord, TResult>;
|
|
750
|
+
clearCounters(): QueryBuilder<TRecord, TResult>;
|
|
751
|
+
clear(statement: ClearStatements): QueryBuilder<TRecord, TResult>;
|
|
752
|
+
|
|
753
|
+
// Paging
|
|
754
|
+
offset(
|
|
755
|
+
offset: number,
|
|
756
|
+
options?: boolean | Readonly<{ skipBinding?: boolean }>
|
|
757
|
+
): QueryBuilder<TRecord, TResult>;
|
|
758
|
+
limit(
|
|
759
|
+
limit: number,
|
|
760
|
+
options?: string | Readonly<{ skipBinding?: boolean }>
|
|
761
|
+
): QueryBuilder<TRecord, TResult>;
|
|
762
|
+
|
|
763
|
+
// Aggregation
|
|
764
|
+
count: AsymmetricAggregation<
|
|
765
|
+
TRecord,
|
|
766
|
+
TResult,
|
|
767
|
+
Lookup<ResultTypes.Registry, 'Count', number | string>
|
|
768
|
+
>;
|
|
769
|
+
countDistinct: AsymmetricAggregation<
|
|
770
|
+
TRecord,
|
|
771
|
+
TResult,
|
|
772
|
+
Lookup<ResultTypes.Registry, 'Count', number | string>
|
|
773
|
+
>;
|
|
774
|
+
min: TypePreservingAggregation<TRecord, TResult>;
|
|
775
|
+
max: TypePreservingAggregation<TRecord, TResult>;
|
|
776
|
+
sum: TypePreservingAggregation<TRecord, TResult>;
|
|
777
|
+
sumDistinct: TypePreservingAggregation<TRecord, TResult>;
|
|
778
|
+
avg: TypePreservingAggregation<TRecord, TResult>;
|
|
779
|
+
avgDistinct: TypePreservingAggregation<TRecord, TResult>;
|
|
780
|
+
|
|
781
|
+
increment(
|
|
782
|
+
columnName: keyof TRecord,
|
|
783
|
+
amount?: number
|
|
784
|
+
): QueryBuilder<TRecord, number>;
|
|
785
|
+
increment(
|
|
786
|
+
columnName: string,
|
|
787
|
+
amount?: number
|
|
788
|
+
): QueryBuilder<TRecord, number>;
|
|
789
|
+
|
|
790
|
+
decrement(
|
|
791
|
+
columnName: keyof TRecord,
|
|
792
|
+
amount?: number
|
|
793
|
+
): QueryBuilder<TRecord, number>;
|
|
794
|
+
decrement(
|
|
795
|
+
columnName: string,
|
|
796
|
+
amount?: number
|
|
797
|
+
): QueryBuilder<TRecord, number>;
|
|
798
|
+
|
|
799
|
+
// Analytics
|
|
800
|
+
rank: AnalyticFunction<TRecord, TResult>;
|
|
801
|
+
denseRank: AnalyticFunction<TRecord, TResult>;
|
|
802
|
+
rowNumber: AnalyticFunction<TRecord, TResult>;
|
|
803
|
+
|
|
804
|
+
// Others
|
|
805
|
+
first: Select<
|
|
806
|
+
TRecord,
|
|
807
|
+
DeferredKeySelection.AddUnionMember<UnwrapArrayMember<TResult>, undefined>
|
|
808
|
+
>;
|
|
809
|
+
|
|
810
|
+
pluck<K extends keyof TRecord>(
|
|
811
|
+
column: K
|
|
812
|
+
): QueryBuilder<TRecord, TRecord[K][]>;
|
|
813
|
+
pluck<TResult2 extends {}>(column: string): QueryBuilder<TRecord, TResult2>;
|
|
814
|
+
|
|
815
|
+
insert(
|
|
816
|
+
data: TRecord extends CompositeTableType<unknown>
|
|
817
|
+
?
|
|
818
|
+
| ResolveTableType<TRecord, 'insert'>
|
|
819
|
+
| ReadonlyArray<ResolveTableType<TRecord, 'insert'>>
|
|
820
|
+
: DbRecordArr<TRecord> | ReadonlyArray<DbRecordArr<TRecord>>,
|
|
821
|
+
returning: '*',
|
|
822
|
+
options?: DMLOptions
|
|
823
|
+
): QueryBuilder<TRecord, DeferredKeySelection<TRecord, never>[]>;
|
|
824
|
+
insert<
|
|
825
|
+
TKey extends StrKey<ResolveTableType<TRecord>>,
|
|
826
|
+
TResult2 = DeferredKeySelection.Augment<
|
|
827
|
+
UnwrapArrayMember<TResult>,
|
|
828
|
+
ResolveTableType<TRecord>,
|
|
829
|
+
TKey
|
|
830
|
+
>[]
|
|
831
|
+
>(
|
|
832
|
+
data: TRecord extends CompositeTableType<unknown>
|
|
833
|
+
?
|
|
834
|
+
| ResolveTableType<TRecord, 'insert'>
|
|
835
|
+
| ReadonlyArray<ResolveTableType<TRecord, 'insert'>>
|
|
836
|
+
: DbRecordArr<TRecord> | ReadonlyArray<DbRecordArr<TRecord>>,
|
|
837
|
+
returning: TKey,
|
|
838
|
+
options?: DMLOptions
|
|
839
|
+
): QueryBuilder<TRecord, TResult2>;
|
|
840
|
+
insert<
|
|
841
|
+
TKey extends StrKey<ResolveTableType<TRecord>>,
|
|
842
|
+
TResult2 = DeferredKeySelection.Augment<
|
|
843
|
+
UnwrapArrayMember<TResult>,
|
|
844
|
+
ResolveTableType<TRecord>,
|
|
845
|
+
TKey
|
|
846
|
+
>[]
|
|
847
|
+
>(
|
|
848
|
+
data: TRecord extends CompositeTableType<unknown>
|
|
849
|
+
?
|
|
850
|
+
| ResolveTableType<TRecord, 'insert'>
|
|
851
|
+
| ReadonlyArray<ResolveTableType<TRecord, 'insert'>>
|
|
852
|
+
: DbRecordArr<TRecord> | ReadonlyArray<DbRecordArr<TRecord>>,
|
|
853
|
+
returning: readonly TKey[],
|
|
854
|
+
options?: DMLOptions
|
|
855
|
+
): QueryBuilder<TRecord, TResult2>;
|
|
856
|
+
insert<
|
|
857
|
+
TKey extends string,
|
|
858
|
+
TResult2 = DeferredKeySelection.Augment<
|
|
859
|
+
UnwrapArrayMember<TResult>,
|
|
860
|
+
TRecord,
|
|
861
|
+
TKey
|
|
862
|
+
>[]
|
|
863
|
+
>(
|
|
864
|
+
data: TRecord extends CompositeTableType<unknown>
|
|
865
|
+
?
|
|
866
|
+
| ResolveTableType<TRecord, 'insert'>
|
|
867
|
+
| ReadonlyArray<ResolveTableType<TRecord, 'insert'>>
|
|
868
|
+
: DbRecordArr<TRecord> | ReadonlyArray<DbRecordArr<TRecord>>,
|
|
869
|
+
returning: TKey,
|
|
870
|
+
options?: DMLOptions
|
|
871
|
+
): QueryBuilder<TRecord, TResult2>;
|
|
872
|
+
insert<
|
|
873
|
+
TKey extends string,
|
|
874
|
+
TResult2 = DeferredKeySelection.Augment<
|
|
875
|
+
UnwrapArrayMember<TResult>,
|
|
876
|
+
TRecord,
|
|
877
|
+
TKey
|
|
878
|
+
>[]
|
|
879
|
+
>(
|
|
880
|
+
data: TRecord extends CompositeTableType<unknown>
|
|
881
|
+
?
|
|
882
|
+
| ResolveTableType<TRecord, 'insert'>
|
|
883
|
+
| ReadonlyArray<ResolveTableType<TRecord, 'insert'>>
|
|
884
|
+
: DbRecordArr<TRecord> | ReadonlyArray<DbRecordArr<TRecord>>,
|
|
885
|
+
returning: readonly TKey[],
|
|
886
|
+
options?: DMLOptions
|
|
887
|
+
): QueryBuilder<TRecord, TResult2>;
|
|
888
|
+
insert<TResult2 = number[]>(
|
|
889
|
+
data: TRecord extends CompositeTableType<unknown>
|
|
890
|
+
?
|
|
891
|
+
| ResolveTableType<TRecord, 'insert'>
|
|
892
|
+
| ReadonlyArray<ResolveTableType<TRecord, 'insert'>>
|
|
893
|
+
: DbRecordArr<TRecord> | ReadonlyArray<DbRecordArr<TRecord>>
|
|
894
|
+
): QueryBuilder<TRecord, TResult2>;
|
|
895
|
+
|
|
896
|
+
upsert(
|
|
897
|
+
data: TRecord extends CompositeTableType<unknown>
|
|
898
|
+
?
|
|
899
|
+
| ResolveTableType<TRecord, 'upsert'>
|
|
900
|
+
| ReadonlyArray<ResolveTableType<TRecord, 'upsert'>>
|
|
901
|
+
: DbRecordArr<TRecord> | ReadonlyArray<DbRecordArr<TRecord>>,
|
|
902
|
+
returning: '*',
|
|
903
|
+
options?: DMLOptions
|
|
904
|
+
): QueryBuilder<TRecord, DeferredKeySelection<TRecord, never>[]>;
|
|
905
|
+
upsert<
|
|
906
|
+
TKey extends StrKey<ResolveTableType<TRecord>>,
|
|
907
|
+
TResult2 = DeferredKeySelection.Augment<
|
|
908
|
+
UnwrapArrayMember<TResult>,
|
|
909
|
+
ResolveTableType<TRecord>,
|
|
910
|
+
TKey
|
|
911
|
+
>[]
|
|
912
|
+
>(
|
|
913
|
+
data: TRecord extends CompositeTableType<unknown>
|
|
914
|
+
?
|
|
915
|
+
| ResolveTableType<TRecord, 'upsert'>
|
|
916
|
+
| ReadonlyArray<ResolveTableType<TRecord, 'upsert'>>
|
|
917
|
+
: DbRecordArr<TRecord> | ReadonlyArray<DbRecordArr<TRecord>>,
|
|
918
|
+
returning: TKey,
|
|
919
|
+
options?: DMLOptions
|
|
920
|
+
): QueryBuilder<TRecord, TResult2>;
|
|
921
|
+
upsert<
|
|
922
|
+
TKey extends StrKey<ResolveTableType<TRecord>>,
|
|
923
|
+
TResult2 = DeferredKeySelection.Augment<
|
|
924
|
+
UnwrapArrayMember<TResult>,
|
|
925
|
+
ResolveTableType<TRecord>,
|
|
926
|
+
TKey
|
|
927
|
+
>[]
|
|
928
|
+
>(
|
|
929
|
+
data: TRecord extends CompositeTableType<unknown>
|
|
930
|
+
?
|
|
931
|
+
| ResolveTableType<TRecord, 'upsert'>
|
|
932
|
+
| ReadonlyArray<ResolveTableType<TRecord, 'upsert'>>
|
|
933
|
+
: DbRecordArr<TRecord> | ReadonlyArray<DbRecordArr<TRecord>>,
|
|
934
|
+
returning: readonly TKey[],
|
|
935
|
+
options?: DMLOptions
|
|
936
|
+
): QueryBuilder<TRecord, TResult2>;
|
|
937
|
+
upsert<
|
|
938
|
+
TKey extends string,
|
|
939
|
+
TResult2 = DeferredKeySelection.Augment<
|
|
940
|
+
UnwrapArrayMember<TResult>,
|
|
941
|
+
TRecord,
|
|
942
|
+
TKey
|
|
943
|
+
>[]
|
|
944
|
+
>(
|
|
945
|
+
data: TRecord extends CompositeTableType<unknown>
|
|
946
|
+
?
|
|
947
|
+
| ResolveTableType<TRecord, 'upsert'>
|
|
948
|
+
| ReadonlyArray<ResolveTableType<TRecord, 'upsert'>>
|
|
949
|
+
: DbRecordArr<TRecord> | ReadonlyArray<DbRecordArr<TRecord>>,
|
|
950
|
+
returning: TKey,
|
|
951
|
+
options?: DMLOptions
|
|
952
|
+
): QueryBuilder<TRecord, TResult2>;
|
|
953
|
+
upsert<
|
|
954
|
+
TKey extends string,
|
|
955
|
+
TResult2 = DeferredKeySelection.Augment<
|
|
956
|
+
UnwrapArrayMember<TResult>,
|
|
957
|
+
TRecord,
|
|
958
|
+
TKey
|
|
959
|
+
>[]
|
|
960
|
+
>(
|
|
961
|
+
data: TRecord extends CompositeTableType<unknown>
|
|
962
|
+
?
|
|
963
|
+
| ResolveTableType<TRecord, 'upsert'>
|
|
964
|
+
| ReadonlyArray<ResolveTableType<TRecord, 'upsert'>>
|
|
965
|
+
: DbRecordArr<TRecord> | ReadonlyArray<DbRecordArr<TRecord>>,
|
|
966
|
+
returning: readonly TKey[],
|
|
967
|
+
options?: DMLOptions
|
|
968
|
+
): QueryBuilder<TRecord, TResult2>;
|
|
969
|
+
upsert<TResult2 = number[]>(
|
|
970
|
+
data: TRecord extends CompositeTableType<unknown>
|
|
971
|
+
?
|
|
972
|
+
| ResolveTableType<TRecord, 'upsert'>
|
|
973
|
+
| ReadonlyArray<ResolveTableType<TRecord, 'upsert'>>
|
|
974
|
+
: DbRecordArr<TRecord> | ReadonlyArray<DbRecordArr<TRecord>>
|
|
975
|
+
): QueryBuilder<TRecord, TResult2>;
|
|
976
|
+
|
|
977
|
+
modify<TRecord2 extends {} = any, TResult2 extends {} = any>(
|
|
978
|
+
callback: QueryCallbackWithArgs<TRecord, any>,
|
|
979
|
+
...args: any[]
|
|
980
|
+
): QueryBuilder<TRecord2, TResult2>;
|
|
981
|
+
update<
|
|
982
|
+
K1 extends StrKey<ResolveTableType<TRecord, 'update'>>,
|
|
983
|
+
K2 extends StrKey<ResolveTableType<TRecord>>,
|
|
984
|
+
TResult2 = DeferredKeySelection.Augment<
|
|
985
|
+
UnwrapArrayMember<TResult>,
|
|
986
|
+
ResolveTableType<TRecord>,
|
|
987
|
+
K2
|
|
988
|
+
>[]
|
|
989
|
+
>(
|
|
990
|
+
columnName: K1,
|
|
991
|
+
value: DbColumn<ResolveTableType<TRecord, 'update'>[K1]>,
|
|
992
|
+
returning: K2,
|
|
993
|
+
options?: DMLOptions
|
|
994
|
+
): QueryBuilder<TRecord, TResult2>;
|
|
995
|
+
update<
|
|
996
|
+
K1 extends StrKey<ResolveTableType<TRecord, 'update'>>,
|
|
997
|
+
K2 extends StrKey<ResolveTableType<TRecord>>,
|
|
998
|
+
TResult2 = DeferredKeySelection.Augment<
|
|
999
|
+
UnwrapArrayMember<TResult>,
|
|
1000
|
+
ResolveTableType<TRecord>,
|
|
1001
|
+
K2
|
|
1002
|
+
>[]
|
|
1003
|
+
>(
|
|
1004
|
+
columnName: K1,
|
|
1005
|
+
value: DbColumn<ResolveTableType<TRecord, 'update'>[K1]>,
|
|
1006
|
+
returning: readonly K2[],
|
|
1007
|
+
options?: DMLOptions
|
|
1008
|
+
): QueryBuilder<TRecord, TResult2>;
|
|
1009
|
+
update<K extends keyof TRecord>(
|
|
1010
|
+
columnName: K,
|
|
1011
|
+
value: DbColumn<TRecord[K]>
|
|
1012
|
+
): QueryBuilder<TRecord, number>;
|
|
1013
|
+
update<TResult2 = SafePartial<TRecord>[]>(
|
|
1014
|
+
columnName: string,
|
|
1015
|
+
value: Value,
|
|
1016
|
+
returning: string | readonly string[],
|
|
1017
|
+
options?: DMLOptions
|
|
1018
|
+
): QueryBuilder<TRecord, TResult2>;
|
|
1019
|
+
update(
|
|
1020
|
+
data: DbRecordArr<TRecord>,
|
|
1021
|
+
returning: '*',
|
|
1022
|
+
options?: DMLOptions
|
|
1023
|
+
): QueryBuilder<TRecord, DeferredKeySelection<TRecord, never>[]>;
|
|
1024
|
+
update<
|
|
1025
|
+
TKey extends StrKey<ResolveTableType<TRecord>>,
|
|
1026
|
+
TResult2 = DeferredKeySelection.Augment<
|
|
1027
|
+
UnwrapArrayMember<TResult>,
|
|
1028
|
+
ResolveTableType<TRecord>,
|
|
1029
|
+
TKey
|
|
1030
|
+
>[]
|
|
1031
|
+
>(
|
|
1032
|
+
data: TRecord extends CompositeTableType<unknown>
|
|
1033
|
+
? ResolveTableType<TRecord, 'update'>
|
|
1034
|
+
: DbRecordArr<TRecord>,
|
|
1035
|
+
returning: TKey,
|
|
1036
|
+
options?: DMLOptions
|
|
1037
|
+
): QueryBuilder<TRecord, TResult2>;
|
|
1038
|
+
update<
|
|
1039
|
+
TKey extends StrKey<ResolveTableType<TRecord>>,
|
|
1040
|
+
TResult2 = DeferredKeySelection.Augment<
|
|
1041
|
+
UnwrapArrayMember<TResult>,
|
|
1042
|
+
ResolveTableType<TRecord>,
|
|
1043
|
+
TKey
|
|
1044
|
+
>[]
|
|
1045
|
+
>(
|
|
1046
|
+
data: TRecord extends CompositeTableType<unknown>
|
|
1047
|
+
? ResolveTableType<TRecord, 'update'>
|
|
1048
|
+
: DbRecordArr<TRecord>,
|
|
1049
|
+
returning: readonly TKey[],
|
|
1050
|
+
options?: DMLOptions
|
|
1051
|
+
): QueryBuilder<TRecord, TResult2>;
|
|
1052
|
+
update<
|
|
1053
|
+
TKey extends string = string,
|
|
1054
|
+
TResult2 extends {}[] = DeferredKeySelection.Augment<
|
|
1055
|
+
UnwrapArrayMember<TResult>,
|
|
1056
|
+
TRecord,
|
|
1057
|
+
TKey
|
|
1058
|
+
>[]
|
|
1059
|
+
>(
|
|
1060
|
+
data: TRecord extends CompositeTableType<unknown>
|
|
1061
|
+
? ResolveTableType<TRecord, 'update'>
|
|
1062
|
+
: DbRecordArr<TRecord>,
|
|
1063
|
+
returning: TKey | readonly TKey[],
|
|
1064
|
+
options?: DMLOptions
|
|
1065
|
+
): QueryBuilder<TRecord, TResult2>;
|
|
1066
|
+
update<
|
|
1067
|
+
TKey extends string,
|
|
1068
|
+
TResult2 extends {}[] = DeferredKeySelection.Augment<
|
|
1069
|
+
UnwrapArrayMember<TResult>,
|
|
1070
|
+
TRecord,
|
|
1071
|
+
TKey
|
|
1072
|
+
>[]
|
|
1073
|
+
>(
|
|
1074
|
+
data: TRecord extends CompositeTableType<unknown>
|
|
1075
|
+
? ResolveTableType<TRecord, 'update'>
|
|
1076
|
+
: DbRecordArr<TRecord>,
|
|
1077
|
+
returning: readonly TKey[],
|
|
1078
|
+
options?: DMLOptions
|
|
1079
|
+
): QueryBuilder<TRecord, TResult2>;
|
|
1080
|
+
update<TResult2 = number>(
|
|
1081
|
+
data: TRecord extends CompositeTableType<unknown>
|
|
1082
|
+
? ResolveTableType<TRecord, 'update'>
|
|
1083
|
+
: DbRecordArr<TRecord>
|
|
1084
|
+
): QueryBuilder<TRecord, TResult2>;
|
|
1085
|
+
|
|
1086
|
+
update<TResult2 = number>(
|
|
1087
|
+
columnName: string,
|
|
1088
|
+
value: Value
|
|
1089
|
+
): QueryBuilder<TRecord, TResult2>;
|
|
1090
|
+
|
|
1091
|
+
returning(
|
|
1092
|
+
column: '*',
|
|
1093
|
+
options?: DMLOptions
|
|
1094
|
+
): QueryBuilder<TRecord, DeferredKeySelection<TRecord, never>[]>;
|
|
1095
|
+
returning<
|
|
1096
|
+
TKey extends StrKey<ResolveTableType<TRecord>>,
|
|
1097
|
+
TResult2 = DeferredKeySelection.Augment<
|
|
1098
|
+
UnwrapArrayMember<TResult>,
|
|
1099
|
+
ResolveTableType<TRecord>,
|
|
1100
|
+
TKey
|
|
1101
|
+
>[]
|
|
1102
|
+
>(
|
|
1103
|
+
column: TKey,
|
|
1104
|
+
options?: DMLOptions
|
|
1105
|
+
): QueryBuilder<TRecord, TResult2>;
|
|
1106
|
+
returning<
|
|
1107
|
+
TKey extends StrKey<ResolveTableType<TRecord>>,
|
|
1108
|
+
TResult2 = DeferredKeySelection.SetSingle<
|
|
1109
|
+
DeferredKeySelection.Augment<
|
|
1110
|
+
UnwrapArrayMember<TResult>,
|
|
1111
|
+
ResolveTableType<TRecord>,
|
|
1112
|
+
TKey
|
|
1113
|
+
>,
|
|
1114
|
+
false
|
|
1115
|
+
>[]
|
|
1116
|
+
>(
|
|
1117
|
+
columns: readonly TKey[],
|
|
1118
|
+
options?: DMLOptions
|
|
1119
|
+
): QueryBuilder<TRecord, TResult2>;
|
|
1120
|
+
returning<TResult2 = SafePartial<TRecord>[]>(
|
|
1121
|
+
column: string | readonly (string | Raw)[] | Raw,
|
|
1122
|
+
options?: DMLOptions
|
|
1123
|
+
): QueryBuilder<TRecord, TResult2>;
|
|
1124
|
+
|
|
1125
|
+
onConflict<TKey extends StrKey<ResolveTableType<TRecord>>>(
|
|
1126
|
+
column: TKey
|
|
1127
|
+
): OnConflictQueryBuilder<TRecord, TResult>;
|
|
1128
|
+
onConflict<TKey extends StrKey<ResolveTableType<TRecord>>>(
|
|
1129
|
+
columns: readonly TKey[]
|
|
1130
|
+
): OnConflictQueryBuilder<TRecord, TResult>;
|
|
1131
|
+
|
|
1132
|
+
onConflict(columns: string): OnConflictQueryBuilder<TRecord, TResult>;
|
|
1133
|
+
|
|
1134
|
+
onConflict(columns: string[]): OnConflictQueryBuilder<TRecord, TResult>;
|
|
1135
|
+
|
|
1136
|
+
onConflict(raw: Raw): OnConflictQueryBuilder<TRecord, TResult>;
|
|
1137
|
+
|
|
1138
|
+
onConflict(): OnConflictQueryBuilder<TRecord, TResult>;
|
|
1139
|
+
|
|
1140
|
+
del(
|
|
1141
|
+
returning: '*',
|
|
1142
|
+
options?: DMLOptions
|
|
1143
|
+
): QueryBuilder<TRecord, DeferredKeySelection<TRecord, never>[]>;
|
|
1144
|
+
del<
|
|
1145
|
+
TKey extends StrKey<TRecord>,
|
|
1146
|
+
TResult2 = DeferredKeySelection.Augment<
|
|
1147
|
+
UnwrapArrayMember<TResult>,
|
|
1148
|
+
TRecord,
|
|
1149
|
+
TKey
|
|
1150
|
+
>[]
|
|
1151
|
+
>(
|
|
1152
|
+
returning: TKey,
|
|
1153
|
+
options?: DMLOptions
|
|
1154
|
+
): QueryBuilder<TRecord, TResult2>;
|
|
1155
|
+
del<
|
|
1156
|
+
TKey extends StrKey<TRecord>,
|
|
1157
|
+
TResult2 = DeferredKeySelection.Augment<
|
|
1158
|
+
UnwrapArrayMember<TResult>,
|
|
1159
|
+
TRecord,
|
|
1160
|
+
TKey
|
|
1161
|
+
>[]
|
|
1162
|
+
>(
|
|
1163
|
+
returning: readonly TKey[],
|
|
1164
|
+
options?: DMLOptions
|
|
1165
|
+
): QueryBuilder<TRecord, TResult2[]>;
|
|
1166
|
+
del<TResult2 = SafePartial<TRecord>[]>(
|
|
1167
|
+
returning: string | readonly string[],
|
|
1168
|
+
options?: DMLOptions
|
|
1169
|
+
): QueryBuilder<TRecord, TResult2>;
|
|
1170
|
+
del<TResult2 = number>(): QueryBuilder<TRecord, TResult2>;
|
|
1171
|
+
|
|
1172
|
+
delete(
|
|
1173
|
+
returning: '*',
|
|
1174
|
+
options?: DMLOptions
|
|
1175
|
+
): QueryBuilder<TRecord, DeferredKeySelection<TRecord, never>[]>;
|
|
1176
|
+
delete<
|
|
1177
|
+
TKey extends StrKey<ResolveTableType<TRecord>>,
|
|
1178
|
+
TResult2 = DeferredKeySelection.Augment<
|
|
1179
|
+
UnwrapArrayMember<TResult>,
|
|
1180
|
+
ResolveTableType<TRecord>,
|
|
1181
|
+
TKey
|
|
1182
|
+
>[]
|
|
1183
|
+
>(
|
|
1184
|
+
returning: TKey,
|
|
1185
|
+
options?: DMLOptions
|
|
1186
|
+
): QueryBuilder<TRecord, TResult2>;
|
|
1187
|
+
delete<
|
|
1188
|
+
TKey extends StrKey<TRecord>,
|
|
1189
|
+
TResult2 = DeferredKeySelection.Augment<
|
|
1190
|
+
UnwrapArrayMember<TResult>,
|
|
1191
|
+
TRecord,
|
|
1192
|
+
TKey
|
|
1193
|
+
>[]
|
|
1194
|
+
>(
|
|
1195
|
+
returning: readonly TKey[],
|
|
1196
|
+
options?: DMLOptions
|
|
1197
|
+
): QueryBuilder<TRecord, TResult2>;
|
|
1198
|
+
delete<TResult2 = any>(
|
|
1199
|
+
returning: string | readonly (string | Raw)[] | Raw,
|
|
1200
|
+
options?: DMLOptions
|
|
1201
|
+
): QueryBuilder<TRecord, TResult2>;
|
|
1202
|
+
delete<TResult2 = number>(): QueryBuilder<TRecord, TResult2>;
|
|
1203
|
+
|
|
1204
|
+
truncate(): QueryBuilder<TRecord, void>;
|
|
1205
|
+
}
|
|
1206
|
+
|
|
1207
|
+
interface As<TRecord extends {}, TResult> {
|
|
1208
|
+
(columnName: keyof TRecord): QueryBuilder<TRecord, TResult>;
|
|
1209
|
+
(columnName: string): QueryBuilder<TRecord, TResult>;
|
|
1210
|
+
}
|
|
1211
|
+
|
|
1212
|
+
type IntersectAliases<AliasUT> = UnionToIntersection<
|
|
1213
|
+
IncompatibleToAlt<
|
|
1214
|
+
AliasUT extends (infer I)[]
|
|
1215
|
+
? I extends Ref<any, infer TMapping>
|
|
1216
|
+
? TMapping
|
|
1217
|
+
: I
|
|
1218
|
+
: never,
|
|
1219
|
+
Dict,
|
|
1220
|
+
{}
|
|
1221
|
+
>
|
|
1222
|
+
> & {}; // filters out `null` and `undefined`
|
|
1223
|
+
|
|
1224
|
+
interface AliasQueryBuilder<TRecord extends {} = any, TResult = unknown[]> {
|
|
1225
|
+
<
|
|
1226
|
+
AliasUT extends InferrableColumnDescriptor<ResolveTableType<TRecord>>[],
|
|
1227
|
+
TResult2 = ArrayIfAlready<
|
|
1228
|
+
TResult,
|
|
1229
|
+
DeferredKeySelection.Augment<
|
|
1230
|
+
UnwrapArrayMember<TResult>,
|
|
1231
|
+
ResolveTableType<TRecord>,
|
|
1232
|
+
IncompatibleToAlt<ArrayMember<AliasUT>, string, never>,
|
|
1233
|
+
IntersectAliases<AliasUT>
|
|
1234
|
+
>
|
|
1235
|
+
>
|
|
1236
|
+
>(
|
|
1237
|
+
...aliases: AliasUT
|
|
1238
|
+
): QueryBuilder<TRecord, TResult2>;
|
|
1239
|
+
|
|
1240
|
+
<
|
|
1241
|
+
AliasUT extends InferrableColumnDescriptor<ResolveTableType<TRecord>>[],
|
|
1242
|
+
TResult2 = ArrayIfAlready<
|
|
1243
|
+
TResult,
|
|
1244
|
+
DeferredKeySelection.Augment<
|
|
1245
|
+
UnwrapArrayMember<TResult>,
|
|
1246
|
+
ResolveTableType<TRecord>,
|
|
1247
|
+
IncompatibleToAlt<ArrayMember<AliasUT>, string, never>,
|
|
1248
|
+
IntersectAliases<AliasUT>
|
|
1249
|
+
>
|
|
1250
|
+
>
|
|
1251
|
+
>(
|
|
1252
|
+
aliases: AliasUT
|
|
1253
|
+
): QueryBuilder<TRecord, TResult2>;
|
|
1254
|
+
|
|
1255
|
+
<
|
|
1256
|
+
AliasUT extends (Dict | string)[],
|
|
1257
|
+
TResult2 = ArrayIfAlready<
|
|
1258
|
+
TResult,
|
|
1259
|
+
DeferredKeySelection.Augment<
|
|
1260
|
+
UnwrapArrayMember<TResult>,
|
|
1261
|
+
ResolveTableType<TRecord>,
|
|
1262
|
+
IncompatibleToAlt<ArrayMember<AliasUT>, string, never>,
|
|
1263
|
+
IntersectAliases<AliasUT>
|
|
1264
|
+
>
|
|
1265
|
+
>
|
|
1266
|
+
>(
|
|
1267
|
+
...aliases: AliasUT
|
|
1268
|
+
): QueryBuilder<TRecord, TResult2>;
|
|
1269
|
+
|
|
1270
|
+
<
|
|
1271
|
+
AliasUT extends (Dict | string)[],
|
|
1272
|
+
TResult2 = ArrayIfAlready<
|
|
1273
|
+
TResult,
|
|
1274
|
+
DeferredKeySelection.Augment<
|
|
1275
|
+
UnwrapArrayMember<TResult>,
|
|
1276
|
+
TRecord,
|
|
1277
|
+
IncompatibleToAlt<ArrayMember<AliasUT>, string, never>,
|
|
1278
|
+
IntersectAliases<AliasUT>
|
|
1279
|
+
>
|
|
1280
|
+
>
|
|
1281
|
+
>(
|
|
1282
|
+
aliases: AliasUT
|
|
1283
|
+
): QueryBuilder<TRecord, TResult2>;
|
|
1284
|
+
}
|
|
1285
|
+
|
|
1286
|
+
interface Select<TRecord extends {} = any, TResult = unknown[]>
|
|
1287
|
+
extends AliasQueryBuilder<TRecord, TResult>,
|
|
1288
|
+
ColumnNameQueryBuilder<TRecord, TResult> {
|
|
1289
|
+
(): QueryBuilder<TRecord, TResult>;
|
|
1290
|
+
|
|
1291
|
+
<
|
|
1292
|
+
TResult2 = ArrayIfAlready<TResult, any>,
|
|
1293
|
+
TInnerRecord extends {} = any,
|
|
1294
|
+
TInnerResult = any
|
|
1295
|
+
>(
|
|
1296
|
+
...subQueryBuilders: readonly QueryBuilder<TInnerRecord, TInnerResult>[]
|
|
1297
|
+
): QueryBuilder<TRecord, TResult2>;
|
|
1298
|
+
|
|
1299
|
+
<
|
|
1300
|
+
TResult2 = ArrayIfAlready<TResult, any>,
|
|
1301
|
+
TInnerRecord extends {} = any,
|
|
1302
|
+
TInnerResult = any
|
|
1303
|
+
>(
|
|
1304
|
+
subQueryBuilders: readonly QueryBuilder<TInnerRecord, TInnerResult>[]
|
|
1305
|
+
): QueryBuilder<TRecord, TResult2>;
|
|
1306
|
+
}
|
|
1307
|
+
|
|
1308
|
+
interface JsonExtraction {
|
|
1309
|
+
column: string | Raw | QueryBuilder;
|
|
1310
|
+
path: string;
|
|
1311
|
+
alias?: string;
|
|
1312
|
+
singleValue?: boolean;
|
|
1313
|
+
}
|
|
1314
|
+
|
|
1315
|
+
interface JsonExtract<TRecord extends {} = any, TResult = any> {
|
|
1316
|
+
(
|
|
1317
|
+
column: string | Raw | QueryBuilder,
|
|
1318
|
+
path: string,
|
|
1319
|
+
alias?: string,
|
|
1320
|
+
singleValue?: boolean
|
|
1321
|
+
): QueryBuilder<TRecord, TResult>;
|
|
1322
|
+
(column: JsonExtraction[] | any[][], singleValue?: boolean): QueryBuilder<
|
|
1323
|
+
TRecord,
|
|
1324
|
+
TResult
|
|
1325
|
+
>;
|
|
1326
|
+
}
|
|
1327
|
+
|
|
1328
|
+
interface JsonSet<TRecord extends {} = any, TResult = any> {
|
|
1329
|
+
(
|
|
1330
|
+
column: string | Raw | QueryBuilder,
|
|
1331
|
+
path: string,
|
|
1332
|
+
value: any,
|
|
1333
|
+
alias?: string
|
|
1334
|
+
): QueryBuilder<TRecord, TResult>;
|
|
1335
|
+
}
|
|
1336
|
+
|
|
1337
|
+
interface JsonInsert<TRecord extends {} = any, TResult = any> {
|
|
1338
|
+
(
|
|
1339
|
+
column: string | Raw | QueryBuilder,
|
|
1340
|
+
path: string,
|
|
1341
|
+
value: any,
|
|
1342
|
+
alias?: string
|
|
1343
|
+
): QueryBuilder<TRecord, TResult>;
|
|
1344
|
+
}
|
|
1345
|
+
|
|
1346
|
+
interface JsonRemove<TRecord extends {} = any, TResult = any> {
|
|
1347
|
+
(
|
|
1348
|
+
column: string | Raw | QueryBuilder,
|
|
1349
|
+
path: string,
|
|
1350
|
+
alias?: string
|
|
1351
|
+
): QueryBuilder<TRecord, TResult>;
|
|
1352
|
+
}
|
|
1353
|
+
|
|
1354
|
+
interface HintComment<TRecord extends {} = any, TResult = any> {
|
|
1355
|
+
(hint: string): QueryBuilder<TRecord, TResult>;
|
|
1356
|
+
(hints: readonly string[]): QueryBuilder<TRecord, TResult>;
|
|
1357
|
+
}
|
|
1358
|
+
|
|
1359
|
+
interface Table<TRecord extends {} = any, TResult = any> {
|
|
1360
|
+
<
|
|
1361
|
+
TTable extends TableNames,
|
|
1362
|
+
TRecord2 extends {} = TableType<TTable>,
|
|
1363
|
+
TResult2 = DeferredKeySelection.ReplaceBase<
|
|
1364
|
+
TResult,
|
|
1365
|
+
ResolveTableType<TRecord2>
|
|
1366
|
+
>
|
|
1367
|
+
>(
|
|
1368
|
+
tableName: TTable,
|
|
1369
|
+
options?: TableOptions
|
|
1370
|
+
): QueryBuilder<TRecord2, TResult2>;
|
|
1371
|
+
<
|
|
1372
|
+
TRecord2 extends {} = {},
|
|
1373
|
+
TResult2 = DeferredKeySelection.ReplaceBase<TResult, TRecord2>
|
|
1374
|
+
>(
|
|
1375
|
+
tableName: TableDescriptor | AliasDict,
|
|
1376
|
+
options?: TableOptions
|
|
1377
|
+
): QueryBuilder<TRecord2, TResult2>;
|
|
1378
|
+
<
|
|
1379
|
+
TRecord2 extends {} = {},
|
|
1380
|
+
TResult2 = DeferredKeySelection.ReplaceBase<TResult, TRecord2>
|
|
1381
|
+
>(
|
|
1382
|
+
callback: Function,
|
|
1383
|
+
options?: TableOptions
|
|
1384
|
+
): QueryBuilder<TRecord2, TResult2>;
|
|
1385
|
+
<
|
|
1386
|
+
TRecord2 extends {} = {},
|
|
1387
|
+
TResult2 = DeferredKeySelection.ReplaceBase<TResult, TRecord2>
|
|
1388
|
+
>(
|
|
1389
|
+
raw: Raw,
|
|
1390
|
+
options?: TableOptions
|
|
1391
|
+
): QueryBuilder<TRecord2, TResult2>;
|
|
1392
|
+
}
|
|
1393
|
+
|
|
1394
|
+
interface Distinct<TRecord extends {}, TResult = {}[]>
|
|
1395
|
+
extends ColumnNameQueryBuilder<TRecord, TResult> {}
|
|
1396
|
+
|
|
1397
|
+
interface DistinctOn<TRecord extends {}, TResult = {}[]> {
|
|
1398
|
+
<ColNameUT extends keyof TRecord>(
|
|
1399
|
+
...columnNames: readonly ColNameUT[]
|
|
1400
|
+
): QueryBuilder<TRecord, TResult>;
|
|
1401
|
+
|
|
1402
|
+
<ColNameUT extends keyof TRecord>(
|
|
1403
|
+
columnNames: readonly ColNameUT[]
|
|
1404
|
+
): QueryBuilder<TRecord, TResult>;
|
|
1405
|
+
|
|
1406
|
+
(...columnNames: readonly string[]): QueryBuilder<TRecord, TResult>;
|
|
1407
|
+
(columnNames: readonly string[]): QueryBuilder<TRecord, TResult>;
|
|
1408
|
+
}
|
|
1409
|
+
|
|
1410
|
+
interface JoinCallback {
|
|
1411
|
+
(this: JoinClause, join: JoinClause): void;
|
|
1412
|
+
}
|
|
1413
|
+
|
|
1414
|
+
interface Join<TRecord extends {} = any, TResult = unknown[]> {
|
|
1415
|
+
<
|
|
1416
|
+
TJoinTargetRecord extends {} = any,
|
|
1417
|
+
TRecord2 extends {} = TRecord & TJoinTargetRecord,
|
|
1418
|
+
TResult2 = DeferredKeySelection.ReplaceBase<TResult, TRecord2>
|
|
1419
|
+
>(
|
|
1420
|
+
raw: Raw
|
|
1421
|
+
): QueryBuilder<TRecord2, TResult2>;
|
|
1422
|
+
<
|
|
1423
|
+
TTable extends TableNames,
|
|
1424
|
+
TRecord2 extends {} = ResolveTableType<TRecord> &
|
|
1425
|
+
ResolveTableType<TableType<TTable>>,
|
|
1426
|
+
TResult2 = DeferredKeySelection.ReplaceBase<TResult, TRecord2>
|
|
1427
|
+
>(
|
|
1428
|
+
tableName: TTable,
|
|
1429
|
+
clause: JoinCallback
|
|
1430
|
+
): QueryBuilder<TRecord2, TResult2>;
|
|
1431
|
+
<
|
|
1432
|
+
TJoinTargetRecord extends {} = any,
|
|
1433
|
+
TRecord2 extends {} = TRecord & TJoinTargetRecord,
|
|
1434
|
+
TResult2 = DeferredKeySelection.ReplaceBase<TResult, TRecord2>
|
|
1435
|
+
>(
|
|
1436
|
+
tableName: TableDescriptor | AliasDict | QueryCallback,
|
|
1437
|
+
clause: JoinCallback
|
|
1438
|
+
): QueryBuilder<TRecord2, TResult2>;
|
|
1439
|
+
<
|
|
1440
|
+
TJoinTargetRecord extends {} = any,
|
|
1441
|
+
TRecord2 extends {} = TRecord & TJoinTargetRecord,
|
|
1442
|
+
TResult2 = DeferredKeySelection.ReplaceBase<TResult, TRecord2>
|
|
1443
|
+
>(
|
|
1444
|
+
tableName: TableDescriptor | AliasDict | QueryCallback,
|
|
1445
|
+
columns: { [key: string]: string | number | boolean | Raw }
|
|
1446
|
+
): QueryBuilder<TRecord2, TResult2>;
|
|
1447
|
+
<
|
|
1448
|
+
TJoinTargetRecord extends {} = any,
|
|
1449
|
+
TRecord2 extends {} = TRecord & TJoinTargetRecord,
|
|
1450
|
+
TResult2 = DeferredKeySelection.ReplaceBase<TResult, TRecord2>
|
|
1451
|
+
>(
|
|
1452
|
+
tableName: TableDescriptor | AliasDict | QueryCallback,
|
|
1453
|
+
raw: Raw
|
|
1454
|
+
): QueryBuilder<TRecord2, TResult2>;
|
|
1455
|
+
<
|
|
1456
|
+
TTable1 extends TableNames,
|
|
1457
|
+
TTable2 extends TableNames,
|
|
1458
|
+
TKey1 extends StrKey<ResolveTableType<TableType<TTable1>>> &
|
|
1459
|
+
StrKey<TRecord1>,
|
|
1460
|
+
TKey2 extends StrKey<ResolveTableType<TableType<TTable2>>>,
|
|
1461
|
+
TRecord1 = ResolveTableType<TRecord>,
|
|
1462
|
+
TRecord2 extends {} = TRecord1 & ResolveTableType<TableType<TTable2>>,
|
|
1463
|
+
TResult2 = DeferredKeySelection.ReplaceBase<TResult, TRecord2>
|
|
1464
|
+
>(
|
|
1465
|
+
tableName: TTable2,
|
|
1466
|
+
column1: `${TTable1}.${TKey1}`,
|
|
1467
|
+
column2: `${TTable2}.${TKey2}`
|
|
1468
|
+
): QueryBuilder<TRecord2, TResult2>;
|
|
1469
|
+
<
|
|
1470
|
+
TTable1 extends TableNames,
|
|
1471
|
+
TTable2 extends TableNames,
|
|
1472
|
+
TKey1 extends StrKey<ResolveTableType<TableType<TTable1>>> &
|
|
1473
|
+
StrKey<TRecord1>,
|
|
1474
|
+
TKey2 extends StrKey<ResolveTableType<TableType<TTable2>>>,
|
|
1475
|
+
TRecord1 = ResolveTableType<TRecord>,
|
|
1476
|
+
TRecord2 extends {} = TRecord1 & ResolveTableType<TableType<TTable2>>,
|
|
1477
|
+
TResult2 = DeferredKeySelection.ReplaceBase<TResult, TRecord2>
|
|
1478
|
+
>(
|
|
1479
|
+
tableName: TTable2,
|
|
1480
|
+
column1: `${TTable2}.${TKey2}`,
|
|
1481
|
+
column2: `${TTable1}.${TKey1}`
|
|
1482
|
+
): QueryBuilder<TRecord2, TResult2>;
|
|
1483
|
+
<
|
|
1484
|
+
TJoinTargetRecord extends {} = any,
|
|
1485
|
+
TRecord2 extends {} = TRecord & TJoinTargetRecord,
|
|
1486
|
+
TResult2 = DeferredKeySelection.ReplaceBase<TResult, TRecord2>
|
|
1487
|
+
>(
|
|
1488
|
+
tableName: TableDescriptor | AliasDict | QueryCallback,
|
|
1489
|
+
column1: string,
|
|
1490
|
+
column2: string
|
|
1491
|
+
): QueryBuilder<TRecord2, TResult2>;
|
|
1492
|
+
<
|
|
1493
|
+
TJoinTargetRecord extends {} = any,
|
|
1494
|
+
TRecord2 extends {} = TRecord & TJoinTargetRecord,
|
|
1495
|
+
TResult2 = DeferredKeySelection.ReplaceBase<TResult, TRecord2>
|
|
1496
|
+
>(
|
|
1497
|
+
tableName: TableDescriptor | AliasDict | QueryCallback,
|
|
1498
|
+
column1: string,
|
|
1499
|
+
raw: Raw
|
|
1500
|
+
): QueryBuilder<TRecord2, TResult2>;
|
|
1501
|
+
<
|
|
1502
|
+
TTable1 extends TableNames,
|
|
1503
|
+
TTable2 extends TableNames,
|
|
1504
|
+
TKey1 extends StrKey<ResolveTableType<TableType<TTable1>>> &
|
|
1505
|
+
StrKey<TRecord1>,
|
|
1506
|
+
TKey2 extends StrKey<ResolveTableType<TableType<TTable2>>>,
|
|
1507
|
+
TRecord1 = ResolveTableType<TRecord>,
|
|
1508
|
+
TRecord2 extends {} = TRecord1 & ResolveTableType<TableType<TTable2>>,
|
|
1509
|
+
TResult2 = DeferredKeySelection.ReplaceBase<TResult, TRecord2>
|
|
1510
|
+
>(
|
|
1511
|
+
tableName: TTable2,
|
|
1512
|
+
column1: `${TTable1}.${TKey1}`,
|
|
1513
|
+
operator: string,
|
|
1514
|
+
column2: `${TTable2}.${TKey2}`
|
|
1515
|
+
): QueryBuilder<TRecord2, TResult2>;
|
|
1516
|
+
<
|
|
1517
|
+
TTable1 extends TableNames,
|
|
1518
|
+
TTable2 extends TableNames,
|
|
1519
|
+
TKey1 extends StrKey<ResolveTableType<TableType<TTable1>>> &
|
|
1520
|
+
StrKey<TRecord1>,
|
|
1521
|
+
TKey2 extends StrKey<ResolveTableType<TableType<TTable2>>>,
|
|
1522
|
+
TRecord1 = ResolveTableType<TRecord>,
|
|
1523
|
+
TRecord2 extends {} = TRecord1 & ResolveTableType<TableType<TTable2>>,
|
|
1524
|
+
TResult2 = DeferredKeySelection.ReplaceBase<TResult, TRecord2>
|
|
1525
|
+
>(
|
|
1526
|
+
tableName: TTable2,
|
|
1527
|
+
column1: `${TTable2}.${TKey2}`,
|
|
1528
|
+
operator: string,
|
|
1529
|
+
column2: `${TTable1}.${TKey1}`
|
|
1530
|
+
): QueryBuilder<TRecord2, TResult2>;
|
|
1531
|
+
<
|
|
1532
|
+
TJoinTargetRecord extends {} = any,
|
|
1533
|
+
TRecord2 extends {} = TRecord & TJoinTargetRecord,
|
|
1534
|
+
TResult2 = DeferredKeySelection.ReplaceBase<TResult, TRecord2>
|
|
1535
|
+
>(
|
|
1536
|
+
tableName: TableDescriptor | AliasDict | QueryCallback,
|
|
1537
|
+
column1: string,
|
|
1538
|
+
operator: string,
|
|
1539
|
+
column2: string
|
|
1540
|
+
): QueryBuilder<TRecord2, TResult2>;
|
|
1541
|
+
}
|
|
1542
|
+
|
|
1543
|
+
interface JoinClause {
|
|
1544
|
+
on(raw: Raw): JoinClause;
|
|
1545
|
+
on(callback: JoinCallback): JoinClause;
|
|
1546
|
+
on(columns: { [key: string]: string | Raw }): JoinClause;
|
|
1547
|
+
on(column1: string, column2: string): JoinClause;
|
|
1548
|
+
on(column1: string, raw: Raw): JoinClause;
|
|
1549
|
+
on(column1: string, operator: string, column2: string | Raw): JoinClause;
|
|
1550
|
+
andOn(raw: Raw): JoinClause;
|
|
1551
|
+
andOn(callback: JoinCallback): JoinClause;
|
|
1552
|
+
andOn(columns: { [key: string]: string | Raw }): JoinClause;
|
|
1553
|
+
andOn(column1: string, column2: string): JoinClause;
|
|
1554
|
+
andOn(column1: string, raw: Raw): JoinClause;
|
|
1555
|
+
andOn(column1: string, operator: string, column2: string | Raw): JoinClause;
|
|
1556
|
+
orOn(raw: Raw): JoinClause;
|
|
1557
|
+
orOn(callback: JoinCallback): JoinClause;
|
|
1558
|
+
orOn(columns: { [key: string]: string | Raw }): JoinClause;
|
|
1559
|
+
orOn(column1: string, column2: string): JoinClause;
|
|
1560
|
+
orOn(column1: string, raw: Raw): JoinClause;
|
|
1561
|
+
orOn(column1: string, operator: string, column2: string | Raw): JoinClause;
|
|
1562
|
+
onVal(column1: string, value: Value): JoinClause;
|
|
1563
|
+
onVal(column1: string, operator: string, value: Value): JoinClause;
|
|
1564
|
+
andOnVal(column1: string, value: Value): JoinClause;
|
|
1565
|
+
andOnVal(column1: string, operator: string, value: Value): JoinClause;
|
|
1566
|
+
orOnVal(column1: string, value: Value): JoinClause;
|
|
1567
|
+
orOnVal(column1: string, operator: string, value: Value): JoinClause;
|
|
1568
|
+
onIn(column1: string, values: readonly any[] | Raw): JoinClause;
|
|
1569
|
+
andOnIn(column1: string, values: readonly any[] | Raw): JoinClause;
|
|
1570
|
+
orOnIn(column1: string, values: readonly any[] | Raw): JoinClause;
|
|
1571
|
+
onNotIn(column1: string, values: readonly any[] | Raw): JoinClause;
|
|
1572
|
+
andOnNotIn(column1: string, values: readonly any[] | Raw): JoinClause;
|
|
1573
|
+
orOnNotIn(column1: string, values: readonly any[] | Raw): JoinClause;
|
|
1574
|
+
onNull(column1: string): JoinClause;
|
|
1575
|
+
andOnNull(column1: string): JoinClause;
|
|
1576
|
+
orOnNull(column1: string): JoinClause;
|
|
1577
|
+
onNotNull(column1: string): JoinClause;
|
|
1578
|
+
andOnNotNull(column1: string): JoinClause;
|
|
1579
|
+
orOnNotNull(column1: string): JoinClause;
|
|
1580
|
+
onExists(callback: QueryCallback): JoinClause;
|
|
1581
|
+
andOnExists(callback: QueryCallback): JoinClause;
|
|
1582
|
+
orOnExists(callback: QueryCallback): JoinClause;
|
|
1583
|
+
onNotExists(callback: QueryCallback): JoinClause;
|
|
1584
|
+
andOnNotExists(callback: QueryCallback): JoinClause;
|
|
1585
|
+
orOnNotExists(callback: QueryCallback): JoinClause;
|
|
1586
|
+
onBetween(column1: string, range: readonly [any, any]): JoinClause;
|
|
1587
|
+
andOnBetween(column1: string, range: readonly [any, any]): JoinClause;
|
|
1588
|
+
orOnBetween(column1: string, range: readonly [any, any]): JoinClause;
|
|
1589
|
+
onNotBetween(column1: string, range: readonly [any, any]): JoinClause;
|
|
1590
|
+
andOnNotBetween(column1: string, range: readonly [any, any]): JoinClause;
|
|
1591
|
+
orOnNotBetween(column1: string, range: readonly [any, any]): JoinClause;
|
|
1592
|
+
onJsonPathEquals(
|
|
1593
|
+
columnFirst: string,
|
|
1594
|
+
jsonPathFirst: string,
|
|
1595
|
+
columnSecond: string,
|
|
1596
|
+
jsonPathSecond: string
|
|
1597
|
+
): JoinClause;
|
|
1598
|
+
orOnJsonPathEquals(
|
|
1599
|
+
columnFirst: string,
|
|
1600
|
+
jsonPathFirst: string,
|
|
1601
|
+
columnSecond: string,
|
|
1602
|
+
jsonPathSecond: string
|
|
1603
|
+
): JoinClause;
|
|
1604
|
+
using(
|
|
1605
|
+
column: string | readonly string[] | Raw | { [key: string]: string | Raw }
|
|
1606
|
+
): JoinClause;
|
|
1607
|
+
type(type: string): JoinClause;
|
|
1608
|
+
}
|
|
1609
|
+
|
|
1610
|
+
interface JoinRaw<TRecord extends {} = any, TResult = unknown[]> {
|
|
1611
|
+
(tableName: string, binding?: Value | Value[] | ValueDict): QueryBuilder<
|
|
1612
|
+
TRecord,
|
|
1613
|
+
TResult
|
|
1614
|
+
>;
|
|
1615
|
+
}
|
|
1616
|
+
|
|
1617
|
+
interface Using<TRecord extends {} = any, TResult = unknown[]> {
|
|
1618
|
+
(tables: string[]): QueryBuilder<TRecord, TResult>;
|
|
1619
|
+
}
|
|
1620
|
+
|
|
1621
|
+
interface With<TRecord extends {} = any, TResult = unknown[]>
|
|
1622
|
+
extends WithRaw<TRecord, TResult>,
|
|
1623
|
+
WithWrapped<TRecord, TResult> {}
|
|
1624
|
+
|
|
1625
|
+
interface WithRaw<TRecord extends {} = any, TResult = unknown[]> {
|
|
1626
|
+
(alias: string, raw: Raw | QueryBuilder): QueryBuilder<TRecord, TResult>;
|
|
1627
|
+
(
|
|
1628
|
+
alias: string,
|
|
1629
|
+
sql: string,
|
|
1630
|
+
bindings?: readonly Value[] | Object
|
|
1631
|
+
): QueryBuilder<TRecord, TResult>;
|
|
1632
|
+
(
|
|
1633
|
+
alias: string,
|
|
1634
|
+
columnList: string[],
|
|
1635
|
+
raw: Raw | QueryBuilder
|
|
1636
|
+
): QueryBuilder<TRecord, TResult>;
|
|
1637
|
+
(
|
|
1638
|
+
alias: string,
|
|
1639
|
+
columnList: string[],
|
|
1640
|
+
sql: string,
|
|
1641
|
+
bindings?: readonly Value[] | Object
|
|
1642
|
+
): QueryBuilder<TRecord, TResult>;
|
|
1643
|
+
}
|
|
1644
|
+
|
|
1645
|
+
interface WithSchema<TRecord extends {} = any, TResult = unknown[]> {
|
|
1646
|
+
(schema: string): QueryBuilder<TRecord, TResult>;
|
|
1647
|
+
}
|
|
1648
|
+
|
|
1649
|
+
interface WithWrapped<TRecord extends {} = any, TResult = unknown[]> {
|
|
1650
|
+
(alias: string, queryBuilder: QueryBuilder): QueryBuilder<TRecord, TResult>;
|
|
1651
|
+
(
|
|
1652
|
+
alias: string,
|
|
1653
|
+
callback: (queryBuilder: QueryBuilder) => any
|
|
1654
|
+
): QueryBuilder<TRecord, TResult>;
|
|
1655
|
+
(
|
|
1656
|
+
alias: string,
|
|
1657
|
+
columnList: string[],
|
|
1658
|
+
queryBuilder: QueryBuilder
|
|
1659
|
+
): QueryBuilder<TRecord, TResult>;
|
|
1660
|
+
(
|
|
1661
|
+
alias: string,
|
|
1662
|
+
columnList: string[],
|
|
1663
|
+
callback: (queryBuilder: QueryBuilder) => any
|
|
1664
|
+
): QueryBuilder<TRecord, TResult>;
|
|
1665
|
+
}
|
|
1666
|
+
|
|
1667
|
+
interface Where<TRecord extends {} = any, TResult = unknown>
|
|
1668
|
+
extends WhereRaw<TRecord, TResult>,
|
|
1669
|
+
WhereWrapped<TRecord, TResult>,
|
|
1670
|
+
WhereNull<TRecord, TResult> {
|
|
1671
|
+
(raw: Raw): QueryBuilder<TRecord, TResult>;
|
|
1672
|
+
|
|
1673
|
+
(callback: QueryCallback<TRecord, TResult>): QueryBuilder<TRecord, TResult>;
|
|
1674
|
+
|
|
1675
|
+
(object: DbRecord<ResolveTableType<TRecord>>): QueryBuilder<
|
|
1676
|
+
TRecord,
|
|
1677
|
+
TResult
|
|
1678
|
+
>;
|
|
1679
|
+
|
|
1680
|
+
(object: Readonly<Object>): QueryBuilder<TRecord, TResult>;
|
|
1681
|
+
|
|
1682
|
+
<T extends keyof ResolveTableType<TRecord>>(
|
|
1683
|
+
columnName: T,
|
|
1684
|
+
value: DbColumn<ResolveTableType<TRecord>[T]> | null
|
|
1685
|
+
): QueryBuilder<TRecord, TResult>;
|
|
1686
|
+
|
|
1687
|
+
(columnName: string, value: Value | null): QueryBuilder<TRecord, TResult>;
|
|
1688
|
+
|
|
1689
|
+
<T extends keyof ResolveTableType<TRecord>>(
|
|
1690
|
+
columnName: T,
|
|
1691
|
+
operator: ComparisonOperator,
|
|
1692
|
+
value: DbColumn<ResolveTableType<TRecord>[T]> | null
|
|
1693
|
+
): QueryBuilder<TRecord, TResult>;
|
|
1694
|
+
|
|
1695
|
+
(columnName: string, operator: string, value: Value | null): QueryBuilder<
|
|
1696
|
+
TRecord,
|
|
1697
|
+
TResult
|
|
1698
|
+
>;
|
|
1699
|
+
|
|
1700
|
+
<
|
|
1701
|
+
T extends keyof ResolveTableType<TRecord>,
|
|
1702
|
+
TRecordInner extends {},
|
|
1703
|
+
TResultInner
|
|
1704
|
+
>(
|
|
1705
|
+
columnName: T,
|
|
1706
|
+
operator: ComparisonOperator,
|
|
1707
|
+
value: QueryBuilder<TRecordInner, TResultInner>
|
|
1708
|
+
): QueryBuilder<TRecord, TResult>;
|
|
1709
|
+
|
|
1710
|
+
<TRecordInner extends {}, TResultInner>(
|
|
1711
|
+
columnName: string,
|
|
1712
|
+
operator: string,
|
|
1713
|
+
value: QueryBuilder<TRecordInner, TResultInner>
|
|
1714
|
+
): QueryBuilder<TRecord, TResult>;
|
|
1715
|
+
|
|
1716
|
+
(left: Raw, operator: string, right: Value | null): QueryBuilder<
|
|
1717
|
+
TRecord,
|
|
1718
|
+
TResult
|
|
1719
|
+
>;
|
|
1720
|
+
|
|
1721
|
+
<TRecordInner extends {}, TResultInner>(
|
|
1722
|
+
left: Raw,
|
|
1723
|
+
operator: string,
|
|
1724
|
+
right: QueryBuilder<TRecordInner, TResultInner>
|
|
1725
|
+
): QueryBuilder<TRecord, TResult>;
|
|
1726
|
+
}
|
|
1727
|
+
|
|
1728
|
+
interface WhereRaw<TRecord extends {} = any, TResult = unknown[]>
|
|
1729
|
+
extends RawQueryBuilder<TRecord, TResult> {
|
|
1730
|
+
(condition: boolean): QueryBuilder<TRecord, TResult>;
|
|
1731
|
+
}
|
|
1732
|
+
|
|
1733
|
+
interface WhereWrapped<TRecord extends {} = any, TResult = unknown[]> {
|
|
1734
|
+
(callback: QueryCallback<TRecord, TResult>): QueryBuilder<TRecord, TResult>;
|
|
1735
|
+
}
|
|
1736
|
+
|
|
1737
|
+
interface WhereNull<TRecord extends {} = any, TResult = unknown[]> {
|
|
1738
|
+
(columnName: keyof TRecord): QueryBuilder<TRecord, TResult>;
|
|
1739
|
+
(columnName: string): QueryBuilder<TRecord, TResult>;
|
|
1740
|
+
}
|
|
1741
|
+
|
|
1742
|
+
interface WhereBetween<TRecord extends {} = any, TResult = unknown[]> {
|
|
1743
|
+
<K extends keyof TRecord>(
|
|
1744
|
+
columnName: K,
|
|
1745
|
+
range: readonly [DbColumn<TRecord[K]>, DbColumn<TRecord[K]>]
|
|
1746
|
+
): QueryBuilder<TRecord, TResult>;
|
|
1747
|
+
(columnName: string, range: readonly [Value, Value]): QueryBuilder<
|
|
1748
|
+
TRecord,
|
|
1749
|
+
TResult
|
|
1750
|
+
>;
|
|
1751
|
+
}
|
|
1752
|
+
|
|
1753
|
+
interface WhereExists<TRecord extends {} = any, TResult = unknown[]> {
|
|
1754
|
+
(callback: QueryCallback<TRecord, TResult>): QueryBuilder<TRecord, TResult>;
|
|
1755
|
+
<TRecordInner extends {}, TResultInner>(
|
|
1756
|
+
query: QueryBuilder<TRecordInner, TResultInner>
|
|
1757
|
+
): QueryBuilder<TRecord, TResult>;
|
|
1758
|
+
}
|
|
1759
|
+
|
|
1760
|
+
interface WhereJsonObject<TRecord extends {} = any, TResult = unknown[]> {
|
|
1761
|
+
(columnName: keyof ResolveTableType<TRecord>, value: any): QueryBuilder<TRecord, TResult>;
|
|
1762
|
+
}
|
|
1763
|
+
|
|
1764
|
+
interface WhereJsonPath<TRecord extends {} = any, TResult = unknown[]> {
|
|
1765
|
+
(
|
|
1766
|
+
columnName: keyof ResolveTableType<TRecord>,
|
|
1767
|
+
jsonPath: string,
|
|
1768
|
+
operator: string,
|
|
1769
|
+
value: any
|
|
1770
|
+
): QueryBuilder<TRecord, TResult>;
|
|
1771
|
+
}
|
|
1772
|
+
|
|
1773
|
+
interface WhereIn<TRecord extends {} = any, TResult = unknown[]> {
|
|
1774
|
+
<K extends keyof ResolveTableType<TRecord>>(
|
|
1775
|
+
columnName: K,
|
|
1776
|
+
values: readonly DbColumn<ResolveTableType<TRecord>[K]>[] | QueryCallback
|
|
1777
|
+
): QueryBuilder<TRecord, TResult>;
|
|
1778
|
+
(
|
|
1779
|
+
columnName: string,
|
|
1780
|
+
values: readonly Value[] | QueryCallback
|
|
1781
|
+
): QueryBuilder<TRecord, TResult>;
|
|
1782
|
+
<K extends keyof ResolveTableType<TRecord>>(
|
|
1783
|
+
columnNames: readonly K[],
|
|
1784
|
+
values:
|
|
1785
|
+
| readonly (readonly DbColumn<ResolveTableType<TRecord>[K]>[])[]
|
|
1786
|
+
| QueryCallback
|
|
1787
|
+
): QueryBuilder<TRecord, TResult>;
|
|
1788
|
+
(
|
|
1789
|
+
columnNames: readonly string[],
|
|
1790
|
+
values: readonly Value[][] | QueryCallback
|
|
1791
|
+
): QueryBuilder<TRecord, TResult>;
|
|
1792
|
+
<K extends keyof TRecord, TRecordInner extends {}, TResultInner>(
|
|
1793
|
+
columnName: K,
|
|
1794
|
+
values: QueryBuilder<TRecordInner, TRecord[K]>
|
|
1795
|
+
): QueryBuilder<TRecord, TResult>;
|
|
1796
|
+
<TRecordInner extends {}, TResultInner>(
|
|
1797
|
+
columnName: string,
|
|
1798
|
+
values: Value[] | QueryBuilder<TRecordInner, TResultInner>
|
|
1799
|
+
): QueryBuilder<TRecord, TResult>;
|
|
1800
|
+
<K extends keyof TRecord, TRecordInner extends {}, TResultInner>(
|
|
1801
|
+
columnNames: readonly K[],
|
|
1802
|
+
values: QueryBuilder<TRecordInner, TRecord[K]>
|
|
1803
|
+
): QueryBuilder<TRecord, TResult>;
|
|
1804
|
+
<TRecordInner extends {}, TResultInner>(
|
|
1805
|
+
columnNames: readonly string[],
|
|
1806
|
+
values: QueryBuilder<TRecordInner, TResultInner>
|
|
1807
|
+
): QueryBuilder<TRecord, TResult>;
|
|
1808
|
+
}
|
|
1809
|
+
|
|
1810
|
+
// Note: Attempting to unify AsymmetricAggregation & TypePreservingAggregation
|
|
1811
|
+
// by extracting out a common base interface will not work because order of overloads
|
|
1812
|
+
// is significant.
|
|
1813
|
+
|
|
1814
|
+
interface AsymmetricAggregation<
|
|
1815
|
+
TRecord extends {} = any,
|
|
1816
|
+
TResult = unknown[],
|
|
1817
|
+
TValue = any
|
|
1818
|
+
> {
|
|
1819
|
+
<
|
|
1820
|
+
TOptions extends { as: string },
|
|
1821
|
+
TResult2 = AggregationQueryResult<
|
|
1822
|
+
TResult,
|
|
1823
|
+
{ [k in TOptions['as']]: TValue }
|
|
1824
|
+
>
|
|
1825
|
+
>(
|
|
1826
|
+
columnName: Readonly<keyof ResolveTableType<TRecord>>,
|
|
1827
|
+
options: Readonly<TOptions>
|
|
1828
|
+
): QueryBuilder<TRecord, TResult2>;
|
|
1829
|
+
<TResult2 = AggregationQueryResult<TResult, Dict<TValue>>>(
|
|
1830
|
+
...columnNames: readonly (keyof ResolveTableType<TRecord>)[]
|
|
1831
|
+
): QueryBuilder<TRecord, TResult2>;
|
|
1832
|
+
<
|
|
1833
|
+
TAliases extends {} = Record<string, string | string[] | Knex.Raw>,
|
|
1834
|
+
TResult2 = AggregationQueryResult<
|
|
1835
|
+
TResult,
|
|
1836
|
+
{ [k in keyof TAliases]?: TValue }
|
|
1837
|
+
>
|
|
1838
|
+
>(
|
|
1839
|
+
aliases: TAliases
|
|
1840
|
+
): QueryBuilder<TRecord, TResult2>;
|
|
1841
|
+
<TResult2 = AggregationQueryResult<TResult, Dict<TValue>>>(
|
|
1842
|
+
...columnNames: ReadonlyArray<
|
|
1843
|
+
| Readonly<Record<string, string | string[] | Knex.Raw>>
|
|
1844
|
+
| Knex.Raw
|
|
1845
|
+
| string
|
|
1846
|
+
>
|
|
1847
|
+
): QueryBuilder<TRecord, TResult2>;
|
|
1848
|
+
}
|
|
1849
|
+
|
|
1850
|
+
interface TypePreservingAggregation<
|
|
1851
|
+
TRecord extends {} = any,
|
|
1852
|
+
TResult = unknown[],
|
|
1853
|
+
TValue = any
|
|
1854
|
+
> {
|
|
1855
|
+
<
|
|
1856
|
+
TKey extends keyof ResolveTableType<TRecord>,
|
|
1857
|
+
TOptions extends { as: string },
|
|
1858
|
+
TResult2 = AggregationQueryResult<
|
|
1859
|
+
TResult,
|
|
1860
|
+
{
|
|
1861
|
+
[k in TOptions['as']]: ResolveTableType<TRecord>[TKey];
|
|
1862
|
+
}
|
|
1863
|
+
>
|
|
1864
|
+
>(
|
|
1865
|
+
columnName: TKey,
|
|
1866
|
+
options: Readonly<TOptions>
|
|
1867
|
+
): QueryBuilder<TRecord, TResult2>;
|
|
1868
|
+
<
|
|
1869
|
+
TKey extends keyof ResolveTableType<TRecord>,
|
|
1870
|
+
TResult2 = AggregationQueryResult<
|
|
1871
|
+
TResult,
|
|
1872
|
+
Dict<ResolveTableType<TRecord>[TKey]>
|
|
1873
|
+
>
|
|
1874
|
+
>(
|
|
1875
|
+
...columnNames: readonly TKey[]
|
|
1876
|
+
): QueryBuilder<TRecord, TResult2>;
|
|
1877
|
+
<
|
|
1878
|
+
TAliases extends {} = Readonly<
|
|
1879
|
+
Record<string, string | string[] | Knex.Raw>
|
|
1880
|
+
>,
|
|
1881
|
+
TResult2 = AggregationQueryResult<
|
|
1882
|
+
TResult,
|
|
1883
|
+
{
|
|
1884
|
+
// We have optional here because in most dialects aggregating by multiple keys simultaneously
|
|
1885
|
+
// causes rest of the keys to be dropped and only first to be considered
|
|
1886
|
+
[K in keyof TAliases]?: K extends keyof TRecord ? TRecord[K] : TValue;
|
|
1887
|
+
}
|
|
1888
|
+
>
|
|
1889
|
+
>(
|
|
1890
|
+
aliases: TAliases
|
|
1891
|
+
): QueryBuilder<TRecord, TResult2>;
|
|
1892
|
+
<TResult2 = AggregationQueryResult<TResult, Dict<TValue>>>(
|
|
1893
|
+
...columnNames: ReadonlyArray<
|
|
1894
|
+
| Readonly<Record<string, string | readonly string[] | Knex.Raw>>
|
|
1895
|
+
| Knex.Raw
|
|
1896
|
+
| string
|
|
1897
|
+
>
|
|
1898
|
+
): QueryBuilder<TRecord, TResult2>;
|
|
1899
|
+
}
|
|
1900
|
+
|
|
1901
|
+
interface AnalyticFunction<TRecord extends {} = any, TResult = unknown[]> {
|
|
1902
|
+
<
|
|
1903
|
+
TAlias extends string,
|
|
1904
|
+
TResult2 = AggregationQueryResult<TResult, { [x in TAlias]: number }>
|
|
1905
|
+
>(
|
|
1906
|
+
alias: TAlias,
|
|
1907
|
+
raw: Raw | QueryCallback<TRecord, TResult>
|
|
1908
|
+
): QueryBuilder<TRecord, TResult2>;
|
|
1909
|
+
<
|
|
1910
|
+
TAlias extends string,
|
|
1911
|
+
TKey extends keyof ResolveTableType<TRecord>,
|
|
1912
|
+
TResult2 = AggregationQueryResult<TResult, { [x in TAlias]: number }>
|
|
1913
|
+
>(
|
|
1914
|
+
alias: TAlias,
|
|
1915
|
+
orderBy:
|
|
1916
|
+
| TKey
|
|
1917
|
+
| TKey[]
|
|
1918
|
+
| {
|
|
1919
|
+
column: TKey;
|
|
1920
|
+
order?: 'asc' | 'desc';
|
|
1921
|
+
nulls?: 'first' | 'last';
|
|
1922
|
+
},
|
|
1923
|
+
partitionBy?: TKey | TKey[] | { column: TKey; order?: 'asc' | 'desc' }
|
|
1924
|
+
): QueryBuilder<TRecord, TResult2>;
|
|
1925
|
+
}
|
|
1926
|
+
|
|
1927
|
+
interface GroupBy<TRecord extends {} = any, TResult = unknown[]>
|
|
1928
|
+
extends RawQueryBuilder<TRecord, TResult>,
|
|
1929
|
+
ColumnNameQueryBuilder<TRecord, TResult> {}
|
|
1930
|
+
|
|
1931
|
+
interface OrderBy<TRecord extends {} = any, TResult = unknown[]> {
|
|
1932
|
+
(
|
|
1933
|
+
columnName: keyof TRecord | QueryBuilder,
|
|
1934
|
+
order?: 'asc' | 'desc',
|
|
1935
|
+
nulls?: 'first' | 'last'
|
|
1936
|
+
): QueryBuilder<TRecord, TResult>;
|
|
1937
|
+
(
|
|
1938
|
+
columnName: string | QueryBuilder,
|
|
1939
|
+
order?: string,
|
|
1940
|
+
nulls?: string
|
|
1941
|
+
): QueryBuilder<TRecord, TResult>;
|
|
1942
|
+
(
|
|
1943
|
+
columnDefs: Array<
|
|
1944
|
+
| keyof TRecord
|
|
1945
|
+
| Readonly<{
|
|
1946
|
+
column: keyof TRecord | QueryBuilder;
|
|
1947
|
+
order?: 'asc' | 'desc';
|
|
1948
|
+
nulls?: 'first' | 'last';
|
|
1949
|
+
}>
|
|
1950
|
+
>
|
|
1951
|
+
): QueryBuilder<TRecord, TResult>;
|
|
1952
|
+
(
|
|
1953
|
+
columnDefs: Array<
|
|
1954
|
+
| string
|
|
1955
|
+
| Readonly<{
|
|
1956
|
+
column: string | QueryBuilder;
|
|
1957
|
+
order?: string;
|
|
1958
|
+
nulls?: string;
|
|
1959
|
+
}>
|
|
1960
|
+
>
|
|
1961
|
+
): QueryBuilder<TRecord, TResult>;
|
|
1962
|
+
}
|
|
1963
|
+
|
|
1964
|
+
interface PartitionBy<TRecord extends {} = any, TResult = unknown[]>
|
|
1965
|
+
extends OrderBy<TRecord, TResult> {}
|
|
1966
|
+
|
|
1967
|
+
interface Intersect<TRecord extends {} = any, TResult = unknown[]> {
|
|
1968
|
+
(
|
|
1969
|
+
callback: MaybeArray<QueryCallback | QueryBuilder<TRecord> | Raw>,
|
|
1970
|
+
wrap?: boolean
|
|
1971
|
+
): QueryBuilder<TRecord, TResult>;
|
|
1972
|
+
(
|
|
1973
|
+
...callbacks: readonly (QueryCallback | Raw | QueryBuilder<TRecord>)[]
|
|
1974
|
+
): QueryBuilder<TRecord, TResult>;
|
|
1975
|
+
}
|
|
1976
|
+
|
|
1977
|
+
interface Union<TRecord extends {} = any, TResult = unknown[]>
|
|
1978
|
+
extends Intersect<TRecord, TResult> {}
|
|
1979
|
+
|
|
1980
|
+
interface Having<TRecord extends {} = any, TResult = unknown[]>
|
|
1981
|
+
extends WhereWrapped<TRecord, TResult> {
|
|
1982
|
+
<K extends keyof TRecord>(
|
|
1983
|
+
column: K,
|
|
1984
|
+
operator: ComparisonOperator,
|
|
1985
|
+
value: DbColumn<TRecord[K]>
|
|
1986
|
+
): QueryBuilder<TRecord, TResult>;
|
|
1987
|
+
|
|
1988
|
+
(
|
|
1989
|
+
column: string | Raw,
|
|
1990
|
+
operator: string,
|
|
1991
|
+
value: Value | QueryBuilder | null
|
|
1992
|
+
): QueryBuilder<TRecord, TResult>;
|
|
1993
|
+
|
|
1994
|
+
(raw: Raw): QueryBuilder<TRecord, TResult>;
|
|
1995
|
+
}
|
|
1996
|
+
|
|
1997
|
+
interface HavingRange<TRecord extends {} = any, TResult = unknown[]> {
|
|
1998
|
+
<K extends keyof TRecord>(
|
|
1999
|
+
columnName: K,
|
|
2000
|
+
values: readonly DbColumn<TRecord[K]>[]
|
|
2001
|
+
): QueryBuilder<TRecord, TResult>;
|
|
2002
|
+
(columnName: string, values: readonly Value[]): QueryBuilder<
|
|
2003
|
+
TRecord,
|
|
2004
|
+
TResult
|
|
2005
|
+
>;
|
|
2006
|
+
}
|
|
2007
|
+
|
|
2008
|
+
// commons
|
|
2009
|
+
|
|
2010
|
+
interface ColumnNameQueryBuilder<
|
|
2011
|
+
TRecord extends {} = any,
|
|
2012
|
+
TResult = unknown[]
|
|
2013
|
+
> {
|
|
2014
|
+
// When all columns are known to be keys of original record,
|
|
2015
|
+
// we can extend our selection by these columns
|
|
2016
|
+
(columnName: '*'): QueryBuilder<
|
|
2017
|
+
TRecord,
|
|
2018
|
+
ArrayIfAlready<TResult, DeferredKeySelection<TRecord, string>>
|
|
2019
|
+
>;
|
|
2020
|
+
|
|
2021
|
+
<
|
|
2022
|
+
ColNameUT extends keyof ResolveTableType<TRecord>,
|
|
2023
|
+
TResult2 = DeferredKeySelection.Augment<
|
|
2024
|
+
UnwrapArrayMember<TResult>,
|
|
2025
|
+
ResolveTableType<TRecord>,
|
|
2026
|
+
ColNameUT & string
|
|
2027
|
+
>[]
|
|
2028
|
+
>(
|
|
2029
|
+
...columnNames: readonly ColNameUT[]
|
|
2030
|
+
): QueryBuilder<TRecord, TResult2>;
|
|
2031
|
+
|
|
2032
|
+
<
|
|
2033
|
+
ColNameUT extends keyof ResolveTableType<TRecord>,
|
|
2034
|
+
TResult2 = DeferredKeySelection.Augment<
|
|
2035
|
+
UnwrapArrayMember<TResult>,
|
|
2036
|
+
ResolveTableType<TRecord>,
|
|
2037
|
+
ColNameUT & string
|
|
2038
|
+
>[]
|
|
2039
|
+
>(
|
|
2040
|
+
columnNames: readonly ColNameUT[]
|
|
2041
|
+
): QueryBuilder<TRecord, TResult2>;
|
|
2042
|
+
|
|
2043
|
+
// For non-inferrable column selection, we will allow consumer to
|
|
2044
|
+
// specify result type and if not widen the result to entire record type with any omissions permitted
|
|
2045
|
+
<
|
|
2046
|
+
TResult2 = DeferredKeySelection.Augment<
|
|
2047
|
+
UnwrapArrayMember<TResult>,
|
|
2048
|
+
SafePartial<TRecord>,
|
|
2049
|
+
keyof TRecord & string
|
|
2050
|
+
>[]
|
|
2051
|
+
>(
|
|
2052
|
+
...columnNames: readonly ColumnDescriptor<TRecord, TResult>[]
|
|
2053
|
+
): QueryBuilder<TRecord, TResult2>;
|
|
2054
|
+
|
|
2055
|
+
<
|
|
2056
|
+
TResult2 = DeferredKeySelection.Augment<
|
|
2057
|
+
UnwrapArrayMember<TResult>,
|
|
2058
|
+
SafePartial<TRecord>,
|
|
2059
|
+
keyof TRecord & string
|
|
2060
|
+
>[]
|
|
2061
|
+
>(
|
|
2062
|
+
columnNames: readonly ColumnDescriptor<TRecord, TResult>[]
|
|
2063
|
+
): QueryBuilder<TRecord, TResult2>;
|
|
2064
|
+
}
|
|
2065
|
+
|
|
2066
|
+
type RawBinding = Value | QueryBuilder;
|
|
2067
|
+
|
|
2068
|
+
interface RawQueryBuilder<TRecord extends {} = any, TResult = unknown[]> {
|
|
2069
|
+
<TResult2 = TResult>(
|
|
2070
|
+
sql: string,
|
|
2071
|
+
bindings?: readonly RawBinding[] | ValueDict | RawBinding
|
|
2072
|
+
): QueryBuilder<TRecord, TResult2>;
|
|
2073
|
+
<TResult2 = TResult>(raw: Raw<TResult2>): QueryBuilder<TRecord, TResult2>;
|
|
2074
|
+
}
|
|
2075
|
+
|
|
2076
|
+
// Raw
|
|
2077
|
+
|
|
2078
|
+
interface Raw<TResult = any>
|
|
2079
|
+
extends Class_EventEmitter,
|
|
2080
|
+
ChainableInterface<ResolveResult<TResult>> {
|
|
2081
|
+
timeout(ms: number, options?: { cancel?: boolean }): Raw<TResult>;
|
|
2082
|
+
wrap<TResult2 = TResult>(before: string, after: string): Raw<TResult>;
|
|
2083
|
+
toSQL(): Sql;
|
|
2084
|
+
queryContext(context: any): Raw<TResult>;
|
|
2085
|
+
queryContext(): any;
|
|
2086
|
+
}
|
|
2087
|
+
|
|
2088
|
+
interface RawBuilder<TRecord extends {} = any, TResult = any> {
|
|
2089
|
+
<TResult2 = TResult>(value: Value): Raw<TResult2>;
|
|
2090
|
+
<TResult2 = TResult>(
|
|
2091
|
+
sql: string,
|
|
2092
|
+
...bindings: readonly RawBinding[]
|
|
2093
|
+
): Raw<TResult2>;
|
|
2094
|
+
<TResult2 = TResult>(
|
|
2095
|
+
sql: string,
|
|
2096
|
+
bindings: readonly RawBinding[] | ValueDict
|
|
2097
|
+
): Raw<TResult2>;
|
|
2098
|
+
}
|
|
2099
|
+
|
|
2100
|
+
const RefMemberTag: unique symbol;
|
|
2101
|
+
|
|
2102
|
+
interface Ref<TSrc extends string, TMapping extends {}> extends Raw<string> {
|
|
2103
|
+
// TypeScript can behave weirdly if type parameters are not
|
|
2104
|
+
// actually used in the members of type.
|
|
2105
|
+
//
|
|
2106
|
+
// See: https://github.com/knex/knex/issues/3932
|
|
2107
|
+
//
|
|
2108
|
+
// We simply need to propagate the type context so that we can extract
|
|
2109
|
+
// them later, but we just add a "phantom" property so that typescript
|
|
2110
|
+
// doesn't think that these parameters are unused
|
|
2111
|
+
//
|
|
2112
|
+
// Because unique symbol is used here, there is no way to actually
|
|
2113
|
+
// access this at runtime
|
|
2114
|
+
[RefMemberTag]: {
|
|
2115
|
+
src: TSrc;
|
|
2116
|
+
mapping: TMapping;
|
|
2117
|
+
};
|
|
2118
|
+
withSchema(schema: string): this;
|
|
2119
|
+
as<TAlias extends string>(
|
|
2120
|
+
alias: TAlias
|
|
2121
|
+
): Ref<TSrc, { [K in TAlias]: TSrc }>;
|
|
2122
|
+
}
|
|
2123
|
+
|
|
2124
|
+
interface RefBuilder {
|
|
2125
|
+
<TSrc extends string>(src: TSrc): Ref<TSrc, { [K in TSrc]: TSrc }>;
|
|
2126
|
+
}
|
|
2127
|
+
|
|
2128
|
+
interface BatchInsertBuilder<TRecord extends {} = any, TResult = number[]>
|
|
2129
|
+
extends Promise<ResolveResult<TResult>> {
|
|
2130
|
+
transacting(trx: Transaction): this;
|
|
2131
|
+
// see returning methods from QueryInterface
|
|
2132
|
+
returning(
|
|
2133
|
+
column: '*'
|
|
2134
|
+
): BatchInsertBuilder<TRecord, DeferredKeySelection<TRecord, never>[]>;
|
|
2135
|
+
returning<
|
|
2136
|
+
TKey extends StrKey<ResolveTableType<TRecord>>,
|
|
2137
|
+
TResult2 = DeferredKeySelection.Augment<
|
|
2138
|
+
UnwrapArrayMember<TResult>,
|
|
2139
|
+
ResolveTableType<TRecord>,
|
|
2140
|
+
TKey
|
|
2141
|
+
>[]
|
|
2142
|
+
>(
|
|
2143
|
+
column: TKey
|
|
2144
|
+
): BatchInsertBuilder<TRecord, TResult2>;
|
|
2145
|
+
returning<
|
|
2146
|
+
TKey extends StrKey<ResolveTableType<TRecord>>,
|
|
2147
|
+
TResult2 = DeferredKeySelection.SetSingle<
|
|
2148
|
+
DeferredKeySelection.Augment<
|
|
2149
|
+
UnwrapArrayMember<TResult>,
|
|
2150
|
+
ResolveTableType<TRecord>,
|
|
2151
|
+
TKey
|
|
2152
|
+
>,
|
|
2153
|
+
false
|
|
2154
|
+
>[]
|
|
2155
|
+
>(
|
|
2156
|
+
columns: readonly TKey[]
|
|
2157
|
+
): BatchInsertBuilder<TRecord, TResult2>;
|
|
2158
|
+
// if data with specific type passed, exclude this method
|
|
2159
|
+
returning<TResult2 = SafePartial<TRecord>[]>(
|
|
2160
|
+
column: unknown extends TRecord
|
|
2161
|
+
? string | readonly (string | Raw)[] | Raw
|
|
2162
|
+
: never
|
|
2163
|
+
): BatchInsertBuilder<TRecord, TResult2>;
|
|
2164
|
+
}
|
|
2165
|
+
|
|
2166
|
+
//
|
|
2167
|
+
// QueryBuilder
|
|
2168
|
+
//
|
|
2169
|
+
|
|
2170
|
+
type QueryCallback<TRecord extends {} = any, TResult = unknown[]> = (
|
|
2171
|
+
this: QueryBuilder<TRecord, TResult>,
|
|
2172
|
+
builder: QueryBuilder<TRecord, TResult>
|
|
2173
|
+
) => void;
|
|
2174
|
+
|
|
2175
|
+
type QueryCallbackWithArgs<TRecord extends {} = any, TResult = unknown[]> = (
|
|
2176
|
+
this: QueryBuilder<TRecord, TResult>,
|
|
2177
|
+
builder: QueryBuilder<TRecord, TResult>,
|
|
2178
|
+
...args: any[]
|
|
2179
|
+
) => void;
|
|
2180
|
+
|
|
2181
|
+
interface QueryBuilder<TRecord extends {} = any, TResult = any>
|
|
2182
|
+
extends QueryInterface<TRecord, TResult>,
|
|
2183
|
+
ChainableInterface<ResolveResult<TResult>> {
|
|
2184
|
+
client: Client;
|
|
2185
|
+
or: QueryBuilder<TRecord, TResult>;
|
|
2186
|
+
not: QueryBuilder<TRecord, TResult>;
|
|
2187
|
+
and: QueryBuilder<TRecord, TResult>;
|
|
2188
|
+
|
|
2189
|
+
// TODO: Promise?
|
|
2190
|
+
columnInfo(
|
|
2191
|
+
column: keyof DeferredKeySelection.Resolve<TRecord>
|
|
2192
|
+
): Promise<ColumnInfo>;
|
|
2193
|
+
columnInfo(): Promise<
|
|
2194
|
+
Record<keyof DeferredKeySelection.Resolve<TRecord>, ColumnInfo>
|
|
2195
|
+
>;
|
|
2196
|
+
|
|
2197
|
+
forUpdate(...tableNames: string[]): QueryBuilder<TRecord, TResult>;
|
|
2198
|
+
forUpdate(tableNames: readonly string[]): QueryBuilder<TRecord, TResult>;
|
|
2199
|
+
|
|
2200
|
+
forShare(...tableNames: string[]): QueryBuilder<TRecord, TResult>;
|
|
2201
|
+
forShare(tableNames: readonly string[]): QueryBuilder<TRecord, TResult>;
|
|
2202
|
+
|
|
2203
|
+
forNoKeyUpdate(...tableNames: string[]): QueryBuilder<TRecord, TResult>;
|
|
2204
|
+
forNoKeyUpdate(
|
|
2205
|
+
tableNames: readonly string[]
|
|
2206
|
+
): QueryBuilder<TRecord, TResult>;
|
|
2207
|
+
|
|
2208
|
+
forKeyShare(...tableNames: string[]): QueryBuilder<TRecord, TResult>;
|
|
2209
|
+
forKeyShare(tableNames: readonly string[]): QueryBuilder<TRecord, TResult>;
|
|
2210
|
+
|
|
2211
|
+
skipLocked(): QueryBuilder<TRecord, TResult>;
|
|
2212
|
+
noWait(): QueryBuilder<TRecord, TResult>;
|
|
2213
|
+
|
|
2214
|
+
toSQL(): Sql;
|
|
2215
|
+
|
|
2216
|
+
on(event: string, callback: Function): QueryBuilder<TRecord, TResult>;
|
|
2217
|
+
|
|
2218
|
+
queryContext(context: any): QueryBuilder<TRecord, TResult>;
|
|
2219
|
+
queryContext(): any;
|
|
2220
|
+
|
|
2221
|
+
clone(): QueryBuilder<TRecord, TResult>;
|
|
2222
|
+
timeout(
|
|
2223
|
+
ms: number,
|
|
2224
|
+
options?: { cancel?: boolean }
|
|
2225
|
+
): QueryBuilder<TRecord, TResult>;
|
|
2226
|
+
}
|
|
2227
|
+
|
|
2228
|
+
interface Sql {
|
|
2229
|
+
method: string;
|
|
2230
|
+
options: any;
|
|
2231
|
+
bindings: readonly Value[];
|
|
2232
|
+
sql: string;
|
|
2233
|
+
toNative(): SqlNative;
|
|
2234
|
+
}
|
|
2235
|
+
|
|
2236
|
+
interface SqlNative {
|
|
2237
|
+
bindings: readonly Value[];
|
|
2238
|
+
sql: string;
|
|
2239
|
+
}
|
|
2240
|
+
|
|
2241
|
+
//
|
|
2242
|
+
// Chainable interface
|
|
2243
|
+
//
|
|
2244
|
+
|
|
2245
|
+
type ExposedPromiseKeys = 'then' | 'catch' | 'finally';
|
|
2246
|
+
|
|
2247
|
+
interface StringTagSupport {
|
|
2248
|
+
readonly [Symbol.toStringTag]: string;
|
|
2249
|
+
}
|
|
2250
|
+
interface ChainableInterface<T = any>
|
|
2251
|
+
extends Pick<Promise<T>, keyof Promise<T> & ExposedPromiseKeys>,
|
|
2252
|
+
StringTagSupport {
|
|
2253
|
+
generateDdlCommands(): Promise<{
|
|
2254
|
+
pre: string[];
|
|
2255
|
+
sql: string[];
|
|
2256
|
+
check: string | null;
|
|
2257
|
+
post: string[];
|
|
2258
|
+
}>;
|
|
2259
|
+
toQuery(): string;
|
|
2260
|
+
options(options: Readonly<{ [key: string]: any }>): this;
|
|
2261
|
+
connection(connection: any): this;
|
|
2262
|
+
debug(enabled: boolean): this;
|
|
2263
|
+
transacting(trx: Transaction): this;
|
|
2264
|
+
stream(handler: (readable: stream.PassThrough) => any): Promise<any>;
|
|
2265
|
+
stream(
|
|
2266
|
+
options: Readonly<{ [key: string]: any }>,
|
|
2267
|
+
handler: (readable: stream.PassThrough) => any
|
|
2268
|
+
): Promise<any>;
|
|
2269
|
+
stream(
|
|
2270
|
+
options?: Readonly<{ [key: string]: any }>
|
|
2271
|
+
): stream.PassThrough & AsyncIterable<ArrayMember<T>>;
|
|
2272
|
+
pipe<T extends import("stream").Writable>(
|
|
2273
|
+
writable: T,
|
|
2274
|
+
options?: Readonly<{ [key: string]: any }>
|
|
2275
|
+
): stream.PassThrough;
|
|
2276
|
+
asCallback(callback: Function): Promise<T>;
|
|
2277
|
+
}
|
|
2278
|
+
|
|
2279
|
+
// Not all of these are possible for all drivers, notably, sqlite doesn't support any of these
|
|
2280
|
+
type IsolationLevels =
|
|
2281
|
+
| 'read uncommitted'
|
|
2282
|
+
| 'read committed'
|
|
2283
|
+
| 'snapshot'
|
|
2284
|
+
| 'repeatable read'
|
|
2285
|
+
| 'serializable';
|
|
2286
|
+
interface TransactionConfig {
|
|
2287
|
+
isolationLevel?: IsolationLevels;
|
|
2288
|
+
userParams?: Record<string, any>;
|
|
2289
|
+
doNotRejectOnRollback?: boolean;
|
|
2290
|
+
connection?: any;
|
|
2291
|
+
}
|
|
2292
|
+
|
|
2293
|
+
interface Transaction<TRecord extends {} = any, TResult = any[]>
|
|
2294
|
+
extends Knex<TRecord, TResult> {
|
|
2295
|
+
executionPromise: Promise<TResult>;
|
|
2296
|
+
isCompleted: () => boolean;
|
|
2297
|
+
|
|
2298
|
+
query<TRecord extends {} = any, TResult = void>(
|
|
2299
|
+
conn: any,
|
|
2300
|
+
sql: any,
|
|
2301
|
+
status: any,
|
|
2302
|
+
value: any
|
|
2303
|
+
): QueryBuilder<TRecord, TResult>;
|
|
2304
|
+
savepoint<T = any>(transactionScope: (trx: Transaction) => any): Promise<T>;
|
|
2305
|
+
commit(value?: any): QueryBuilder<TRecord, TResult>;
|
|
2306
|
+
rollback(error?: any): QueryBuilder<TRecord, TResult>;
|
|
2307
|
+
}
|
|
2308
|
+
|
|
2309
|
+
type TransactionProvider = () => Promise<Transaction>;
|
|
2310
|
+
|
|
2311
|
+
//
|
|
2312
|
+
// Schema builder
|
|
2313
|
+
//
|
|
2314
|
+
|
|
2315
|
+
interface SchemaBuilder extends ChainableInterface<void> {
|
|
2316
|
+
// Views
|
|
2317
|
+
createView(
|
|
2318
|
+
viewName: string,
|
|
2319
|
+
callback: (viewBuilder: ViewBuilder) => any
|
|
2320
|
+
): SchemaBuilder;
|
|
2321
|
+
createViewOrReplace(
|
|
2322
|
+
viewName: string,
|
|
2323
|
+
callback: (viewBuilder: ViewBuilder) => any
|
|
2324
|
+
): SchemaBuilder;
|
|
2325
|
+
createMaterializedView(
|
|
2326
|
+
viewName: string,
|
|
2327
|
+
callback: (viewBuilder: ViewBuilder) => any
|
|
2328
|
+
): SchemaBuilder;
|
|
2329
|
+
refreshMaterializedView(
|
|
2330
|
+
viewName: string,
|
|
2331
|
+
concurrently?: boolean
|
|
2332
|
+
): SchemaBuilder;
|
|
2333
|
+
dropView(viewName: string): SchemaBuilder;
|
|
2334
|
+
dropViewIfExists(viewName: string): SchemaBuilder;
|
|
2335
|
+
dropMaterializedView(viewName: string): SchemaBuilder;
|
|
2336
|
+
dropMaterializedViewIfExists(viewName: string): SchemaBuilder;
|
|
2337
|
+
renameView(oldViewName: string, newViewName: string): Promise<void>;
|
|
2338
|
+
view(
|
|
2339
|
+
viewName: string,
|
|
2340
|
+
callback: (viewBuilder: AlterViewBuilder) => any
|
|
2341
|
+
): Promise<void>;
|
|
2342
|
+
alterView(
|
|
2343
|
+
viewName: string,
|
|
2344
|
+
callback: (tableBuilder: AlterViewBuilder) => any
|
|
2345
|
+
): SchemaBuilder;
|
|
2346
|
+
|
|
2347
|
+
// Tables
|
|
2348
|
+
createTable(
|
|
2349
|
+
tableName: string,
|
|
2350
|
+
callback: (tableBuilder: CreateTableBuilder) => any
|
|
2351
|
+
): SchemaBuilder;
|
|
2352
|
+
createTableIfNotExists(
|
|
2353
|
+
tableName: string,
|
|
2354
|
+
callback: (tableBuilder: CreateTableBuilder) => any
|
|
2355
|
+
): SchemaBuilder;
|
|
2356
|
+
createTableLike(
|
|
2357
|
+
tableName: string,
|
|
2358
|
+
tableNameLike: string,
|
|
2359
|
+
callback?: (tableBuilder: CreateTableBuilder) => any
|
|
2360
|
+
): SchemaBuilder;
|
|
2361
|
+
alterTable(
|
|
2362
|
+
tableName: string,
|
|
2363
|
+
callback: (tableBuilder: CreateTableBuilder) => any
|
|
2364
|
+
): SchemaBuilder;
|
|
2365
|
+
renameTable(oldTableName: string, newTableName: string): Promise<void>;
|
|
2366
|
+
dropTable(tableName: string): SchemaBuilder;
|
|
2367
|
+
hasTable(tableName: string): Promise<boolean>;
|
|
2368
|
+
table(
|
|
2369
|
+
tableName: string,
|
|
2370
|
+
callback: (tableBuilder: AlterTableBuilder) => any
|
|
2371
|
+
): Promise<void>;
|
|
2372
|
+
dropTableIfExists(tableName: string): SchemaBuilder;
|
|
2373
|
+
|
|
2374
|
+
// Schema
|
|
2375
|
+
createSchema(schemaName: string): SchemaBuilder;
|
|
2376
|
+
createSchemaIfNotExists(schemaName: string): SchemaBuilder;
|
|
2377
|
+
dropSchema(schemaName: string, cascade?: boolean): SchemaBuilder;
|
|
2378
|
+
dropSchemaIfExists(schemaName: string, cascade?: boolean): SchemaBuilder;
|
|
2379
|
+
withSchema(schemaName: string): SchemaBuilder;
|
|
2380
|
+
|
|
2381
|
+
// Others
|
|
2382
|
+
hasColumn(tableName: string, columnName: string): Promise<boolean>;
|
|
2383
|
+
raw(statement: string): SchemaBuilder;
|
|
2384
|
+
queryContext(context: any): SchemaBuilder;
|
|
2385
|
+
toString(): string;
|
|
2386
|
+
toSQL(): Sql;
|
|
2387
|
+
}
|
|
2388
|
+
|
|
2389
|
+
interface TableBuilder {
|
|
2390
|
+
increments(
|
|
2391
|
+
columnName?: string,
|
|
2392
|
+
options?: { primaryKey?: boolean }
|
|
2393
|
+
): ColumnBuilder;
|
|
2394
|
+
bigIncrements(
|
|
2395
|
+
columnName?: string,
|
|
2396
|
+
options?: { primaryKey?: boolean }
|
|
2397
|
+
): ColumnBuilder;
|
|
2398
|
+
dropColumn(columnName: string): TableBuilder;
|
|
2399
|
+
dropColumns(...columnNames: string[]): TableBuilder;
|
|
2400
|
+
renameColumn(from: string, to: string): TableBuilder;
|
|
2401
|
+
integer(columnName: string, length?: number): ColumnBuilder;
|
|
2402
|
+
tinyint(columnName: string, length?: number): ColumnBuilder;
|
|
2403
|
+
smallint(columnName: string): ColumnBuilder;
|
|
2404
|
+
mediumint(columnName: string): ColumnBuilder;
|
|
2405
|
+
bigint(columnName: string): ColumnBuilder;
|
|
2406
|
+
bigInteger(columnName: string): ColumnBuilder;
|
|
2407
|
+
text(columnName: string, textType?: string): ColumnBuilder;
|
|
2408
|
+
string(columnName: string, length?: number): ColumnBuilder;
|
|
2409
|
+
float(
|
|
2410
|
+
columnName: string,
|
|
2411
|
+
precision?: number,
|
|
2412
|
+
scale?: number
|
|
2413
|
+
): ColumnBuilder;
|
|
2414
|
+
double(
|
|
2415
|
+
columnName: string,
|
|
2416
|
+
precision?: number,
|
|
2417
|
+
scale?: number
|
|
2418
|
+
): ColumnBuilder;
|
|
2419
|
+
decimal(
|
|
2420
|
+
columnName: string,
|
|
2421
|
+
precision?: number | null,
|
|
2422
|
+
scale?: number
|
|
2423
|
+
): ColumnBuilder;
|
|
2424
|
+
boolean(columnName: string): ColumnBuilder;
|
|
2425
|
+
date(columnName: string): ColumnBuilder;
|
|
2426
|
+
dateTime(
|
|
2427
|
+
columnName: string,
|
|
2428
|
+
options?: Readonly<{ useTz?: boolean; precision?: number }>
|
|
2429
|
+
): ColumnBuilder;
|
|
2430
|
+
datetime(
|
|
2431
|
+
columnName: string,
|
|
2432
|
+
options?: Readonly<{ useTz?: boolean; precision?: number }>
|
|
2433
|
+
): ColumnBuilder;
|
|
2434
|
+
time(columnName: string): ColumnBuilder;
|
|
2435
|
+
timestamp(
|
|
2436
|
+
columnName: string,
|
|
2437
|
+
options?: Readonly<{ useTz?: boolean; precision?: number }>
|
|
2438
|
+
): ColumnBuilder;
|
|
2439
|
+
/** @deprecated */
|
|
2440
|
+
timestamp(
|
|
2441
|
+
columnName: string,
|
|
2442
|
+
withoutTz?: boolean,
|
|
2443
|
+
precision?: number
|
|
2444
|
+
): ColumnBuilder;
|
|
2445
|
+
timestamps(
|
|
2446
|
+
useTimestamps?: boolean,
|
|
2447
|
+
defaultToNow?: boolean,
|
|
2448
|
+
useCamelCase?: boolean
|
|
2449
|
+
): ColumnBuilder;
|
|
2450
|
+
timestamps(
|
|
2451
|
+
options?: Readonly<{
|
|
2452
|
+
useTimestamps?: boolean;
|
|
2453
|
+
defaultToNow?: boolean;
|
|
2454
|
+
useCamelCase?: boolean;
|
|
2455
|
+
}>
|
|
2456
|
+
): void;
|
|
2457
|
+
geometry(columnName: string): ColumnBuilder;
|
|
2458
|
+
geography(columnName: string): ColumnBuilder;
|
|
2459
|
+
point(columnName: string): ColumnBuilder;
|
|
2460
|
+
binary(columnName: string, length?: number): ColumnBuilder;
|
|
2461
|
+
enum(
|
|
2462
|
+
columnName: string,
|
|
2463
|
+
values: readonly Value[] | null,
|
|
2464
|
+
options?: EnumOptions
|
|
2465
|
+
): ColumnBuilder;
|
|
2466
|
+
enu(
|
|
2467
|
+
columnName: string,
|
|
2468
|
+
values: readonly Value[] | null,
|
|
2469
|
+
options?: EnumOptions
|
|
2470
|
+
): ColumnBuilder;
|
|
2471
|
+
json(columnName: string): ColumnBuilder;
|
|
2472
|
+
jsonb(columnName: string): ColumnBuilder;
|
|
2473
|
+
uuid(
|
|
2474
|
+
columnName: string,
|
|
2475
|
+
options?: Readonly<{ useBinaryUuid?: boolean; primaryKey?: boolean }>
|
|
2476
|
+
): ColumnBuilder;
|
|
2477
|
+
comment(val: string): void;
|
|
2478
|
+
specificType(columnName: string, type: string): ColumnBuilder;
|
|
2479
|
+
primary(
|
|
2480
|
+
columnNames: readonly string[],
|
|
2481
|
+
options?: Readonly<{
|
|
2482
|
+
constraintName?: string;
|
|
2483
|
+
deferrable?: deferrableType;
|
|
2484
|
+
}>
|
|
2485
|
+
): TableBuilder;
|
|
2486
|
+
/** @deprecated */
|
|
2487
|
+
primary(
|
|
2488
|
+
columnNames: readonly string[],
|
|
2489
|
+
constraintName?: string
|
|
2490
|
+
): TableBuilder;
|
|
2491
|
+
index(
|
|
2492
|
+
columnNames: string | readonly (string | Raw)[],
|
|
2493
|
+
indexName?: string,
|
|
2494
|
+
indexType?: string
|
|
2495
|
+
): TableBuilder;
|
|
2496
|
+
index(
|
|
2497
|
+
columnNames: string | readonly (string | Raw)[],
|
|
2498
|
+
indexName?: string,
|
|
2499
|
+
options?: Readonly<{
|
|
2500
|
+
indexType?: string;
|
|
2501
|
+
storageEngineIndexType?: storageEngineIndexType;
|
|
2502
|
+
predicate?: QueryBuilder;
|
|
2503
|
+
}>
|
|
2504
|
+
): TableBuilder;
|
|
2505
|
+
setNullable(column: string): TableBuilder;
|
|
2506
|
+
dropNullable(column: string): TableBuilder;
|
|
2507
|
+
unique(
|
|
2508
|
+
columnNames: readonly (string | Raw)[],
|
|
2509
|
+
options?: Readonly<{
|
|
2510
|
+
indexName?: string;
|
|
2511
|
+
storageEngineIndexType?: string;
|
|
2512
|
+
deferrable?: deferrableType;
|
|
2513
|
+
useConstraint?: boolean;
|
|
2514
|
+
}>
|
|
2515
|
+
): TableBuilder;
|
|
2516
|
+
/** @deprecated */
|
|
2517
|
+
unique(
|
|
2518
|
+
columnNames: readonly (string | Raw)[],
|
|
2519
|
+
indexName?: string
|
|
2520
|
+
): TableBuilder;
|
|
2521
|
+
foreign(column: string, foreignKeyName?: string): ForeignConstraintBuilder;
|
|
2522
|
+
foreign(
|
|
2523
|
+
columns: readonly string[],
|
|
2524
|
+
foreignKeyName?: string
|
|
2525
|
+
): MultikeyForeignConstraintBuilder;
|
|
2526
|
+
check(
|
|
2527
|
+
checkPredicate: string,
|
|
2528
|
+
bindings?: Record<string, any>,
|
|
2529
|
+
constraintName?: string
|
|
2530
|
+
): TableBuilder;
|
|
2531
|
+
dropForeign(
|
|
2532
|
+
columnNames: string | readonly string[],
|
|
2533
|
+
foreignKeyName?: string
|
|
2534
|
+
): TableBuilder;
|
|
2535
|
+
dropUnique(
|
|
2536
|
+
columnNames: readonly (string | Raw)[],
|
|
2537
|
+
indexName?: string
|
|
2538
|
+
): TableBuilder;
|
|
2539
|
+
dropPrimary(constraintName?: string): TableBuilder;
|
|
2540
|
+
dropIndex(
|
|
2541
|
+
columnNames: string | readonly (string | Raw)[],
|
|
2542
|
+
indexName?: string
|
|
2543
|
+
): TableBuilder;
|
|
2544
|
+
dropTimestamps(useCamelCase?: boolean): TableBuilder;
|
|
2545
|
+
dropChecks(checkConstraintNames: string | string[]): TableBuilder;
|
|
2546
|
+
queryContext(context: any): TableBuilder;
|
|
2547
|
+
}
|
|
2548
|
+
|
|
2549
|
+
interface ViewBuilder<TRecord extends {} = any, TResult = any> {
|
|
2550
|
+
columns(columns: any): ViewBuilder;
|
|
2551
|
+
as(selectQuery: QueryBuilder): ViewBuilder;
|
|
2552
|
+
checkOption(): Promise<void>;
|
|
2553
|
+
localCheckOption(): Promise<void>;
|
|
2554
|
+
cascadedCheckOption(): Promise<void>;
|
|
2555
|
+
queryContext(context: any): ViewBuilder;
|
|
2556
|
+
}
|
|
2557
|
+
|
|
2558
|
+
interface CreateTableBuilder extends TableBuilder {
|
|
2559
|
+
engine(val: string): CreateTableBuilder;
|
|
2560
|
+
charset(val: string): CreateTableBuilder;
|
|
2561
|
+
collate(val: string): CreateTableBuilder;
|
|
2562
|
+
inherits(val: string): CreateTableBuilder;
|
|
2563
|
+
}
|
|
2564
|
+
|
|
2565
|
+
interface AlterTableBuilder extends TableBuilder {}
|
|
2566
|
+
|
|
2567
|
+
interface AlterColumnView extends ViewBuilder {
|
|
2568
|
+
rename(newName: string): AlterColumnView;
|
|
2569
|
+
defaultTo(defaultValue: string): AlterColumnView;
|
|
2570
|
+
}
|
|
2571
|
+
|
|
2572
|
+
interface AlterViewBuilder extends ViewBuilder {
|
|
2573
|
+
column(column: string): AlterColumnView;
|
|
2574
|
+
}
|
|
2575
|
+
|
|
2576
|
+
type deferrableType = 'not deferrable' | 'immediate' | 'deferred';
|
|
2577
|
+
type storageEngineIndexType = 'hash' | 'btree';
|
|
2578
|
+
type lengthOperator = '>' | '<' | '<=' | '>=' | '!=' | '=';
|
|
2579
|
+
|
|
2580
|
+
interface ColumnBuilder {
|
|
2581
|
+
index(indexName?: string): ColumnBuilder;
|
|
2582
|
+
primary(
|
|
2583
|
+
options?: Readonly<{
|
|
2584
|
+
constraintName?: string;
|
|
2585
|
+
deferrable?: deferrableType;
|
|
2586
|
+
}>
|
|
2587
|
+
): ColumnBuilder;
|
|
2588
|
+
/** @deprecated */
|
|
2589
|
+
primary(constraintName?: string): ColumnBuilder;
|
|
2590
|
+
|
|
2591
|
+
unique(
|
|
2592
|
+
options?: Readonly<{ indexName?: string; deferrable?: deferrableType }>
|
|
2593
|
+
): ColumnBuilder;
|
|
2594
|
+
/** @deprecated */
|
|
2595
|
+
unique(indexName?: string): ColumnBuilder;
|
|
2596
|
+
references(columnName: string): ReferencingColumnBuilder;
|
|
2597
|
+
defaultTo(value: Value | null, options?: DefaultToOptions): ColumnBuilder;
|
|
2598
|
+
unsigned(): ColumnBuilder;
|
|
2599
|
+
notNullable(): ColumnBuilder;
|
|
2600
|
+
nullable(): ColumnBuilder;
|
|
2601
|
+
comment(value: string): ColumnBuilder;
|
|
2602
|
+
alter(
|
|
2603
|
+
options?: Readonly<{ alterNullable?: boolean; alterType?: boolean }>
|
|
2604
|
+
): ColumnBuilder;
|
|
2605
|
+
queryContext(context: any): ColumnBuilder;
|
|
2606
|
+
after(columnName: string): ColumnBuilder;
|
|
2607
|
+
first(): ColumnBuilder;
|
|
2608
|
+
checkPositive(constraintName?: string): ColumnBuilder;
|
|
2609
|
+
checkNegative(constraintName?: string): ColumnBuilder;
|
|
2610
|
+
checkIn(values: string[], constraintName?: string): ColumnBuilder;
|
|
2611
|
+
checkNotIn(values: string[], constraintName?: string): ColumnBuilder;
|
|
2612
|
+
checkBetween(
|
|
2613
|
+
values: any[] | any[][],
|
|
2614
|
+
constraintName?: string
|
|
2615
|
+
): ColumnBuilder;
|
|
2616
|
+
checkLength(
|
|
2617
|
+
operator: lengthOperator,
|
|
2618
|
+
length: number,
|
|
2619
|
+
constraintName?: string
|
|
2620
|
+
): ColumnBuilder;
|
|
2621
|
+
checkRegex(regex: string, constraintName?: string): ColumnBuilder;
|
|
2622
|
+
}
|
|
2623
|
+
|
|
2624
|
+
interface ForeignConstraintBuilder {
|
|
2625
|
+
references(columnName: string): ReferencingColumnBuilder;
|
|
2626
|
+
}
|
|
2627
|
+
|
|
2628
|
+
interface MultikeyForeignConstraintBuilder {
|
|
2629
|
+
references(columnNames: readonly string[]): ReferencingColumnBuilder;
|
|
2630
|
+
}
|
|
2631
|
+
|
|
2632
|
+
interface PostgreSqlColumnBuilder extends ColumnBuilder {
|
|
2633
|
+
index(
|
|
2634
|
+
indexName?: string,
|
|
2635
|
+
options?: Readonly<{ indexType?: string; predicate?: QueryBuilder }>
|
|
2636
|
+
): ColumnBuilder;
|
|
2637
|
+
index(indexName?: string, indexType?: string): ColumnBuilder;
|
|
2638
|
+
}
|
|
2639
|
+
|
|
2640
|
+
interface SqlLiteColumnBuilder extends ColumnBuilder {
|
|
2641
|
+
index(
|
|
2642
|
+
indexName?: string,
|
|
2643
|
+
options?: Readonly<{ predicate?: QueryBuilder }>
|
|
2644
|
+
): ColumnBuilder;
|
|
2645
|
+
}
|
|
2646
|
+
|
|
2647
|
+
interface MsSqlColumnBuilder extends ColumnBuilder {
|
|
2648
|
+
index(
|
|
2649
|
+
indexName?: string,
|
|
2650
|
+
options?: Readonly<{ predicate?: QueryBuilder }>
|
|
2651
|
+
): ColumnBuilder;
|
|
2652
|
+
}
|
|
2653
|
+
|
|
2654
|
+
interface MySqlColumnBuilder extends ColumnBuilder {
|
|
2655
|
+
index(
|
|
2656
|
+
indexName?: string,
|
|
2657
|
+
options?: Readonly<{
|
|
2658
|
+
indexType?: string;
|
|
2659
|
+
storageEngineIndexType?: storageEngineIndexType;
|
|
2660
|
+
}>
|
|
2661
|
+
): ColumnBuilder;
|
|
2662
|
+
}
|
|
2663
|
+
|
|
2664
|
+
// patched ColumnBuilder methods to return ReferencingColumnBuilder with new methods
|
|
2665
|
+
// relies on ColumnBuilder returning only ColumnBuilder
|
|
2666
|
+
type ReferencingColumnBuilder = {
|
|
2667
|
+
[K in keyof ColumnBuilder]: (
|
|
2668
|
+
...args: Parameters<ColumnBuilder[K]>
|
|
2669
|
+
) => ReferencingColumnBuilder;
|
|
2670
|
+
} & {
|
|
2671
|
+
inTable(tableName: string): ReferencingColumnBuilder;
|
|
2672
|
+
deferrable(type: deferrableType): ReferencingColumnBuilder;
|
|
2673
|
+
withKeyName(keyName: string): ReferencingColumnBuilder;
|
|
2674
|
+
onDelete(command: string): ReferencingColumnBuilder;
|
|
2675
|
+
onUpdate(command: string): ReferencingColumnBuilder;
|
|
2676
|
+
};
|
|
2677
|
+
|
|
2678
|
+
interface AlterColumnBuilder extends ColumnBuilder {}
|
|
2679
|
+
|
|
2680
|
+
interface MySqlAlterColumnBuilder extends AlterColumnBuilder {
|
|
2681
|
+
first(): AlterColumnBuilder;
|
|
2682
|
+
after(columnName: string): AlterColumnBuilder;
|
|
2683
|
+
}
|
|
2684
|
+
|
|
2685
|
+
//
|
|
2686
|
+
// Configurations
|
|
2687
|
+
//
|
|
2688
|
+
|
|
2689
|
+
interface ColumnInfo {
|
|
2690
|
+
defaultValue: Value;
|
|
2691
|
+
type: string;
|
|
2692
|
+
maxLength: number;
|
|
2693
|
+
nullable: boolean;
|
|
2694
|
+
}
|
|
2695
|
+
|
|
2696
|
+
interface Config<SV extends {} = any> {
|
|
2697
|
+
debug?: boolean;
|
|
2698
|
+
client?: string | typeof Client;
|
|
2699
|
+
dialect?: string;
|
|
2700
|
+
jsonbSupport?: boolean;
|
|
2701
|
+
version?: string;
|
|
2702
|
+
connection?: string | StaticConnectionConfig | ConnectionConfigProvider;
|
|
2703
|
+
pool?: PoolConfig;
|
|
2704
|
+
migrations?: MigratorConfig;
|
|
2705
|
+
postProcessResponse?: (result: any, queryContext: any) => any;
|
|
2706
|
+
wrapIdentifier?: (
|
|
2707
|
+
value: string,
|
|
2708
|
+
origImpl: (value: string) => string,
|
|
2709
|
+
queryContext: any
|
|
2710
|
+
) => string;
|
|
2711
|
+
seeds?: SeederConfig<SV>;
|
|
2712
|
+
acquireConnectionTimeout?: number;
|
|
2713
|
+
useNullAsDefault?: boolean;
|
|
2714
|
+
searchPath?: string | readonly string[];
|
|
2715
|
+
asyncStackTraces?: boolean;
|
|
2716
|
+
log?: Logger;
|
|
2717
|
+
}
|
|
2718
|
+
|
|
2719
|
+
type StaticConnectionConfig =
|
|
2720
|
+
| ConnectionConfig
|
|
2721
|
+
| MariaSqlConnectionConfig
|
|
2722
|
+
| MySqlConnectionConfig
|
|
2723
|
+
| MySql2ConnectionConfig
|
|
2724
|
+
| MsSqlConnectionConfig
|
|
2725
|
+
| OracleDbConnectionConfig
|
|
2726
|
+
| PgConnectionConfig
|
|
2727
|
+
| RedshiftConnectionConfig
|
|
2728
|
+
| Sqlite3ConnectionConfig
|
|
2729
|
+
| SocketConnectionConfig;
|
|
2730
|
+
|
|
2731
|
+
type ConnectionConfigProvider =
|
|
2732
|
+
| SyncConnectionConfigProvider
|
|
2733
|
+
| AsyncConnectionConfigProvider;
|
|
2734
|
+
type SyncConnectionConfigProvider = () => StaticConnectionConfig;
|
|
2735
|
+
type AsyncConnectionConfigProvider = () => Promise<StaticConnectionConfig>;
|
|
2736
|
+
|
|
2737
|
+
interface ConnectionConfig {
|
|
2738
|
+
host: string;
|
|
2739
|
+
user: string;
|
|
2740
|
+
password: string;
|
|
2741
|
+
database: string;
|
|
2742
|
+
domain?: string;
|
|
2743
|
+
instanceName?: string;
|
|
2744
|
+
debug?: boolean;
|
|
2745
|
+
requestTimeout?: number;
|
|
2746
|
+
}
|
|
2747
|
+
|
|
2748
|
+
type MsSqlAuthenticationTypeOptions =
|
|
2749
|
+
| 'default'
|
|
2750
|
+
| 'ntlm'
|
|
2751
|
+
| 'azure-active-directory-password'
|
|
2752
|
+
| 'azure-active-directory-access-token'
|
|
2753
|
+
| 'azure-active-directory-msi-vm'
|
|
2754
|
+
| 'azure-active-directory-msi-app-service'
|
|
2755
|
+
| 'azure-active-directory-service-principal-secret';
|
|
2756
|
+
|
|
2757
|
+
interface MsSqlDefaultAuthenticationConfig extends MsSqlConnectionConfigBase {
|
|
2758
|
+
type?: 'default' | never;
|
|
2759
|
+
}
|
|
2760
|
+
|
|
2761
|
+
interface MsSqlAzureActiveDirectoryMsiAppServiceAuthenticationConfig
|
|
2762
|
+
extends MsSqlConnectionConfigBase {
|
|
2763
|
+
type: 'azure-active-directory-msi-app-service';
|
|
2764
|
+
/**
|
|
2765
|
+
* If you user want to connect to an Azure app service using a specific client account
|
|
2766
|
+
* they need to provide `clientId` asscoiate to their created idnetity.
|
|
2767
|
+
*
|
|
2768
|
+
* This is optional for retrieve token from azure web app service
|
|
2769
|
+
*/
|
|
2770
|
+
clientId?: string;
|
|
2771
|
+
/**
|
|
2772
|
+
* A msi app service environment need to provide `msiEndpoint` for retriving the accesstoken.
|
|
2773
|
+
*/
|
|
2774
|
+
msiEndpoint?: string;
|
|
2775
|
+
/**
|
|
2776
|
+
* A msi app service environment need to provide `msiSecret` for retriving the accesstoken.
|
|
2777
|
+
*/
|
|
2778
|
+
msiSecret?: string;
|
|
2779
|
+
}
|
|
2780
|
+
|
|
2781
|
+
interface MsSqlAzureActiveDirectoryMsiVmAuthenticationConfig
|
|
2782
|
+
extends MsSqlConnectionConfigBase {
|
|
2783
|
+
type: 'azure-active-directory-msi-vm';
|
|
2784
|
+
/**
|
|
2785
|
+
* If you user want to connect to an Azure app service using a specific client account
|
|
2786
|
+
* they need to provide `clientId` asscoiate to their created idnetity.
|
|
2787
|
+
*
|
|
2788
|
+
* This is optional for retrieve token from azure web app service
|
|
2789
|
+
*/
|
|
2790
|
+
clientId?: string;
|
|
2791
|
+
/**
|
|
2792
|
+
* A user need to provide `msiEndpoint` for retriving the accesstoken.
|
|
2793
|
+
*/
|
|
2794
|
+
msiEndpoint?: string;
|
|
2795
|
+
}
|
|
2796
|
+
|
|
2797
|
+
interface MsSqlAzureActiveDirectoryAccessTokenAuthenticationConfig
|
|
2798
|
+
extends MsSqlConnectionConfigBase {
|
|
2799
|
+
type: 'azure-active-directory-access-token';
|
|
2800
|
+
/**
|
|
2801
|
+
* A user-provided access token
|
|
2802
|
+
*/
|
|
2803
|
+
token: string;
|
|
2804
|
+
}
|
|
2805
|
+
interface MsSqlAzureActiveDirectoryPasswordAuthenticationConfig
|
|
2806
|
+
extends MsSqlConnectionConfigBase {
|
|
2807
|
+
type: 'azure-active-directory-password';
|
|
2808
|
+
/**
|
|
2809
|
+
* Optional parameter for specific Azure tenant ID
|
|
2810
|
+
*/
|
|
2811
|
+
domain: string;
|
|
2812
|
+
userName: string;
|
|
2813
|
+
password: string;
|
|
2814
|
+
}
|
|
2815
|
+
|
|
2816
|
+
interface MsSqlAzureActiveDirectoryServicePrincipalSecretConfig
|
|
2817
|
+
extends MsSqlConnectionConfigBase {
|
|
2818
|
+
type: 'azure-active-directory-service-principal-secret';
|
|
2819
|
+
/**
|
|
2820
|
+
* Application (`client`) ID from your registered Azure application
|
|
2821
|
+
*/
|
|
2822
|
+
clientId: string;
|
|
2823
|
+
/**
|
|
2824
|
+
* The created `client secret` for this registered Azure application
|
|
2825
|
+
*/
|
|
2826
|
+
clientSecret: string;
|
|
2827
|
+
/**
|
|
2828
|
+
* Directory (`tenant`) ID from your registered Azure application
|
|
2829
|
+
*/
|
|
2830
|
+
tenantId: string;
|
|
2831
|
+
}
|
|
2832
|
+
|
|
2833
|
+
interface MsSqlNtlmAuthenticationConfig extends MsSqlConnectionConfigBase {
|
|
2834
|
+
type: 'ntlm';
|
|
2835
|
+
/**
|
|
2836
|
+
* Once you set domain for ntlm authentication type, driver will connect to SQL Server using domain login.
|
|
2837
|
+
*
|
|
2838
|
+
* This is necessary for forming a connection using ntlm type
|
|
2839
|
+
*/
|
|
2840
|
+
domain: string;
|
|
2841
|
+
userName: string;
|
|
2842
|
+
password: string;
|
|
2843
|
+
}
|
|
2844
|
+
|
|
2845
|
+
type MsSqlConnectionConfig =
|
|
2846
|
+
| MsSqlDefaultAuthenticationConfig
|
|
2847
|
+
| MsSqlNtlmAuthenticationConfig
|
|
2848
|
+
| MsSqlAzureActiveDirectoryAccessTokenAuthenticationConfig
|
|
2849
|
+
| MsSqlAzureActiveDirectoryMsiAppServiceAuthenticationConfig
|
|
2850
|
+
| MsSqlAzureActiveDirectoryMsiVmAuthenticationConfig
|
|
2851
|
+
| MsSqlAzureActiveDirectoryPasswordAuthenticationConfig
|
|
2852
|
+
| MsSqlAzureActiveDirectoryServicePrincipalSecretConfig;
|
|
2853
|
+
|
|
2854
|
+
// Config object for tedious: see http://tediousjs.github.io/tedious/api-connection.html
|
|
2855
|
+
interface MsSqlConnectionConfigBase {
|
|
2856
|
+
type?: MsSqlAuthenticationTypeOptions;
|
|
2857
|
+
|
|
2858
|
+
driver?: string;
|
|
2859
|
+
userName?: string; // equivalent to knex "user"
|
|
2860
|
+
password?: string;
|
|
2861
|
+
server: string; // equivalent to knex "host"
|
|
2862
|
+
port?: number;
|
|
2863
|
+
domain?: string;
|
|
2864
|
+
database: string;
|
|
2865
|
+
connectionTimeout?: number;
|
|
2866
|
+
requestTimeout?: number;
|
|
2867
|
+
stream?: boolean;
|
|
2868
|
+
parseJSON?: boolean;
|
|
2869
|
+
expirationChecker?(): boolean;
|
|
2870
|
+
options?: Readonly<{
|
|
2871
|
+
encrypt?: boolean;
|
|
2872
|
+
instanceName?: string;
|
|
2873
|
+
useUTC?: boolean;
|
|
2874
|
+
tdsVersion?: string;
|
|
2875
|
+
appName?: string;
|
|
2876
|
+
abortTransactionOnError?: boolean;
|
|
2877
|
+
trustedConnection?: boolean;
|
|
2878
|
+
enableArithAbort?: boolean;
|
|
2879
|
+
isolationLevel?:
|
|
2880
|
+
| 'READ_UNCOMMITTED'
|
|
2881
|
+
| 'READ_COMMITTED'
|
|
2882
|
+
| 'REPEATABLE_READ'
|
|
2883
|
+
| 'SERIALIZABLE'
|
|
2884
|
+
| 'SNAPSHOT';
|
|
2885
|
+
maxRetriesOnTransientErrors?: number;
|
|
2886
|
+
multiSubnetFailover?: boolean;
|
|
2887
|
+
packetSize?: number;
|
|
2888
|
+
trustServerCertificate?: boolean;
|
|
2889
|
+
mapBinding?: (value: any) => ({ value: any, type: any } | undefined);
|
|
2890
|
+
}>;
|
|
2891
|
+
pool?: Readonly<{
|
|
2892
|
+
min?: number;
|
|
2893
|
+
max?: number;
|
|
2894
|
+
idleTimeoutMillis?: number;
|
|
2895
|
+
maxWaitingClients?: number;
|
|
2896
|
+
testOnBorrow?: boolean;
|
|
2897
|
+
acquireTimeoutMillis?: number;
|
|
2898
|
+
fifo?: boolean;
|
|
2899
|
+
priorityRange?: number;
|
|
2900
|
+
autostart?: boolean;
|
|
2901
|
+
evictionRunIntervalMillis?: number;
|
|
2902
|
+
numTestsPerRun?: number;
|
|
2903
|
+
softIdleTimeoutMillis?: number;
|
|
2904
|
+
Promise?: any;
|
|
2905
|
+
}>;
|
|
2906
|
+
}
|
|
2907
|
+
|
|
2908
|
+
// Config object for mariasql: https://github.com/mscdex/node-mariasql#client-methods
|
|
2909
|
+
interface MariaSqlConnectionConfig {
|
|
2910
|
+
user?: string;
|
|
2911
|
+
password?: string;
|
|
2912
|
+
host?: string;
|
|
2913
|
+
port?: number;
|
|
2914
|
+
unixSocket?: string;
|
|
2915
|
+
protocol?: string;
|
|
2916
|
+
db?: string;
|
|
2917
|
+
keepQueries?: boolean;
|
|
2918
|
+
multiStatements?: boolean;
|
|
2919
|
+
connTimeout?: number;
|
|
2920
|
+
pingInterval?: number;
|
|
2921
|
+
secureAuth?: boolean;
|
|
2922
|
+
compress?: boolean;
|
|
2923
|
+
ssl?: boolean | MariaSslConfiguration;
|
|
2924
|
+
local_infile?: boolean;
|
|
2925
|
+
read_default_file?: string;
|
|
2926
|
+
read_default_group?: string;
|
|
2927
|
+
charset?: string;
|
|
2928
|
+
streamHWM?: number;
|
|
2929
|
+
expirationChecker?(): boolean;
|
|
2930
|
+
}
|
|
2931
|
+
|
|
2932
|
+
interface MariaSslConfiguration {
|
|
2933
|
+
key?: string;
|
|
2934
|
+
cert?: string;
|
|
2935
|
+
ca?: string;
|
|
2936
|
+
capath?: string;
|
|
2937
|
+
cipher?: string;
|
|
2938
|
+
rejectUnauthorized?: boolean;
|
|
2939
|
+
expirationChecker?(): boolean;
|
|
2940
|
+
}
|
|
2941
|
+
|
|
2942
|
+
// Config object for mysql: https://github.com/mysqljs/mysql#connection-options
|
|
2943
|
+
interface MySqlConnectionConfig {
|
|
2944
|
+
host?: string;
|
|
2945
|
+
port?: number;
|
|
2946
|
+
localAddress?: string;
|
|
2947
|
+
socketPath?: string;
|
|
2948
|
+
user?: string;
|
|
2949
|
+
password?: string;
|
|
2950
|
+
database?: string;
|
|
2951
|
+
charset?: string;
|
|
2952
|
+
timezone?: string;
|
|
2953
|
+
connectTimeout?: number;
|
|
2954
|
+
stringifyObjects?: boolean;
|
|
2955
|
+
insecureAuth?: boolean;
|
|
2956
|
+
typeCast?: any;
|
|
2957
|
+
queryFormat?: (query: string, values: any) => string;
|
|
2958
|
+
supportBigNumbers?: boolean;
|
|
2959
|
+
bigNumberStrings?: boolean;
|
|
2960
|
+
dateStrings?: boolean;
|
|
2961
|
+
debug?: boolean;
|
|
2962
|
+
trace?: boolean;
|
|
2963
|
+
multipleStatements?: boolean;
|
|
2964
|
+
flags?: string;
|
|
2965
|
+
ssl?: string | MariaSslConfiguration;
|
|
2966
|
+
decimalNumbers?: boolean;
|
|
2967
|
+
expirationChecker?(): boolean;
|
|
2968
|
+
}
|
|
2969
|
+
|
|
2970
|
+
// Config object for mysql2: https://github.com/sidorares/node-mysql2/blob/master/lib/connection_config.js
|
|
2971
|
+
// Some options for connection pooling and MySQL server API are excluded.
|
|
2972
|
+
interface MySql2ConnectionConfig extends MySqlConnectionConfig {
|
|
2973
|
+
authPlugins?: {
|
|
2974
|
+
[pluginName: string]: (pluginMetadata: any) => (pluginData: any) => any;
|
|
2975
|
+
};
|
|
2976
|
+
authSwitchHandler?: (data: any, callback: () => void) => any;
|
|
2977
|
+
charsetNumber?: number;
|
|
2978
|
+
compress?: boolean;
|
|
2979
|
+
connectAttributes?: { [attrNames: string]: any };
|
|
2980
|
+
enableKeepAlive?: boolean;
|
|
2981
|
+
keepAliveInitialDelay?: number;
|
|
2982
|
+
maxPreparedStatements?: number;
|
|
2983
|
+
namedPlaceholders?: boolean;
|
|
2984
|
+
nestTables?: boolean | string;
|
|
2985
|
+
passwordSha1?: string;
|
|
2986
|
+
rowsAsArray?: boolean;
|
|
2987
|
+
stream?: boolean | ((opts: any) => import('stream').Stream) | import('stream').Stream;
|
|
2988
|
+
uri?: string;
|
|
2989
|
+
}
|
|
2990
|
+
|
|
2991
|
+
interface OracleDbConnectionConfig {
|
|
2992
|
+
host: string;
|
|
2993
|
+
user: string;
|
|
2994
|
+
password?: string;
|
|
2995
|
+
database?: string;
|
|
2996
|
+
domain?: string;
|
|
2997
|
+
instanceName?: string;
|
|
2998
|
+
debug?: boolean;
|
|
2999
|
+
requestTimeout?: number;
|
|
3000
|
+
connectString?: string;
|
|
3001
|
+
expirationChecker?(): boolean;
|
|
3002
|
+
}
|
|
3003
|
+
|
|
3004
|
+
// Config object for pg: https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/pg/index.d.ts
|
|
3005
|
+
interface PgConnectionConfig {
|
|
3006
|
+
user?: string;
|
|
3007
|
+
database?: string;
|
|
3008
|
+
password?: string | (() => string | Promise<string>);
|
|
3009
|
+
port?: number;
|
|
3010
|
+
host?: string;
|
|
3011
|
+
connectionString?: string;
|
|
3012
|
+
keepAlive?: boolean;
|
|
3013
|
+
stream?: stream.Duplex;
|
|
3014
|
+
statement_timeout?: false | number;
|
|
3015
|
+
parseInputDatesAsUTC?: boolean;
|
|
3016
|
+
ssl?: boolean/* | ConnectionOptions */;
|
|
3017
|
+
query_timeout?: number;
|
|
3018
|
+
keepAliveInitialDelayMillis?: number;
|
|
3019
|
+
idle_in_transaction_session_timeout?: number;
|
|
3020
|
+
application_name?: string;
|
|
3021
|
+
connectionTimeoutMillis?: number;
|
|
3022
|
+
types?: PgCustomTypesConfig;
|
|
3023
|
+
options?: string;
|
|
3024
|
+
}
|
|
3025
|
+
|
|
3026
|
+
type PgGetTypeParser = (oid: number, format: string) => any;
|
|
3027
|
+
|
|
3028
|
+
interface PgCustomTypesConfig {
|
|
3029
|
+
getTypeParser: PgGetTypeParser;
|
|
3030
|
+
}
|
|
3031
|
+
|
|
3032
|
+
type RedshiftConnectionConfig = PgConnectionConfig;
|
|
3033
|
+
|
|
3034
|
+
/** Used with SQLite3 adapter */
|
|
3035
|
+
interface Sqlite3ConnectionConfig {
|
|
3036
|
+
filename: string;
|
|
3037
|
+
flags?: string[];
|
|
3038
|
+
debug?: boolean;
|
|
3039
|
+
expirationChecker?(): boolean;
|
|
3040
|
+
}
|
|
3041
|
+
|
|
3042
|
+
interface SocketConnectionConfig {
|
|
3043
|
+
socketPath: string;
|
|
3044
|
+
user: string;
|
|
3045
|
+
password: string;
|
|
3046
|
+
database: string;
|
|
3047
|
+
debug?: boolean;
|
|
3048
|
+
expirationChecker?(): boolean;
|
|
3049
|
+
}
|
|
3050
|
+
|
|
3051
|
+
interface PoolConfig {
|
|
3052
|
+
name?: string;
|
|
3053
|
+
afterCreate?: Function;
|
|
3054
|
+
min?: number;
|
|
3055
|
+
max?: number;
|
|
3056
|
+
refreshIdle?: boolean;
|
|
3057
|
+
idleTimeoutMillis?: number;
|
|
3058
|
+
reapIntervalMillis?: number;
|
|
3059
|
+
returnToHead?: boolean;
|
|
3060
|
+
priorityRange?: number;
|
|
3061
|
+
log?: (message: string, logLevel: string) => void;
|
|
3062
|
+
|
|
3063
|
+
// tarn configs
|
|
3064
|
+
propagateCreateError?: boolean;
|
|
3065
|
+
createRetryIntervalMillis?: number;
|
|
3066
|
+
createTimeoutMillis?: number;
|
|
3067
|
+
destroyTimeoutMillis?: number;
|
|
3068
|
+
acquireTimeoutMillis?: number;
|
|
3069
|
+
}
|
|
3070
|
+
|
|
3071
|
+
type LogFn = (message: any) => void;
|
|
3072
|
+
|
|
3073
|
+
interface Logger {
|
|
3074
|
+
warn?: LogFn;
|
|
3075
|
+
error?: LogFn;
|
|
3076
|
+
debug?: LogFn;
|
|
3077
|
+
inspectionDepth?: number;
|
|
3078
|
+
enableColors?: boolean;
|
|
3079
|
+
deprecate?: (method: string, alternative: string) => void;
|
|
3080
|
+
}
|
|
3081
|
+
|
|
3082
|
+
interface Migration {
|
|
3083
|
+
up: (knex: Knex) => PromiseLike<any>;
|
|
3084
|
+
down?: (knex: Knex) => PromiseLike<any>;
|
|
3085
|
+
}
|
|
3086
|
+
|
|
3087
|
+
interface MigrationSource<TMigrationSpec> {
|
|
3088
|
+
getMigrations(loadExtensions: readonly string[]): Promise<TMigrationSpec[]>;
|
|
3089
|
+
getMigrationName(migration: TMigrationSpec): string;
|
|
3090
|
+
getMigration(migration: TMigrationSpec): Promise<Migration>;
|
|
3091
|
+
}
|
|
3092
|
+
|
|
3093
|
+
interface MigratorConfig {
|
|
3094
|
+
database?: string;
|
|
3095
|
+
directory?: string | readonly string[];
|
|
3096
|
+
extension?: string;
|
|
3097
|
+
stub?: string;
|
|
3098
|
+
tableName?: string;
|
|
3099
|
+
schemaName?: string;
|
|
3100
|
+
disableTransactions?: boolean;
|
|
3101
|
+
disableMigrationsListValidation?: boolean;
|
|
3102
|
+
sortDirsSeparately?: boolean;
|
|
3103
|
+
loadExtensions?: readonly string[];
|
|
3104
|
+
migrationSource?: MigrationSource<unknown>;
|
|
3105
|
+
name?: string;
|
|
3106
|
+
}
|
|
3107
|
+
|
|
3108
|
+
interface Migrator {
|
|
3109
|
+
make(name: string, config?: MigratorConfig): Promise<string>;
|
|
3110
|
+
latest(config?: MigratorConfig): Promise<any>;
|
|
3111
|
+
rollback(config?: MigratorConfig, all?: boolean): Promise<any>;
|
|
3112
|
+
status(config?: MigratorConfig): Promise<number>;
|
|
3113
|
+
currentVersion(config?: MigratorConfig): Promise<string>;
|
|
3114
|
+
list(config?: MigratorConfig): Promise<any>;
|
|
3115
|
+
up(config?: MigratorConfig): Promise<any>;
|
|
3116
|
+
down(config?: MigratorConfig): Promise<any>;
|
|
3117
|
+
forceFreeMigrationsLock(config?: MigratorConfig): Promise<any>;
|
|
3118
|
+
}
|
|
3119
|
+
|
|
3120
|
+
interface Seed {
|
|
3121
|
+
seed: (knex: Knex) => PromiseLike<void>;
|
|
3122
|
+
}
|
|
3123
|
+
|
|
3124
|
+
interface SeedSource<TSeedSpec> {
|
|
3125
|
+
getSeeds(config: SeederConfig): Promise<TSeedSpec[]>;
|
|
3126
|
+
getSeed(seed: TSeedSpec): Promise<Seed>;
|
|
3127
|
+
}
|
|
3128
|
+
|
|
3129
|
+
interface SeederConfig<V extends {} = any> {
|
|
3130
|
+
extension?: string;
|
|
3131
|
+
directory?: string | readonly string[];
|
|
3132
|
+
loadExtensions?: readonly string[];
|
|
3133
|
+
specific?: string;
|
|
3134
|
+
timestampFilenamePrefix?: boolean;
|
|
3135
|
+
recursive?: boolean;
|
|
3136
|
+
sortDirsSeparately?: boolean;
|
|
3137
|
+
stub?: string;
|
|
3138
|
+
variables?: V;
|
|
3139
|
+
seedSource?: SeedSource<unknown>;
|
|
3140
|
+
}
|
|
3141
|
+
|
|
3142
|
+
class Seeder {
|
|
3143
|
+
constructor(knex: Knex);
|
|
3144
|
+
setConfig(config: SeederConfig): SeederConfig;
|
|
3145
|
+
run(config?: SeederConfig): Promise<[string[]]>;
|
|
3146
|
+
make(name: string, config?: SeederConfig): Promise<string>;
|
|
3147
|
+
}
|
|
3148
|
+
|
|
3149
|
+
interface FunctionHelper {
|
|
3150
|
+
now(precision?: number): Raw;
|
|
3151
|
+
uuidToBin(uuid: string, ordered?: boolean): Class_Buffer;
|
|
3152
|
+
binToUuid(bin: Class_Buffer, ordered?: boolean): string;
|
|
3153
|
+
}
|
|
3154
|
+
|
|
3155
|
+
interface EnumOptions {
|
|
3156
|
+
useNative: boolean;
|
|
3157
|
+
existingType?: boolean;
|
|
3158
|
+
schemaName?: string;
|
|
3159
|
+
enumName: string;
|
|
3160
|
+
}
|
|
3161
|
+
|
|
3162
|
+
interface DefaultToOptions {
|
|
3163
|
+
// only supported by mssql driver
|
|
3164
|
+
constraintName?: string;
|
|
3165
|
+
}
|
|
3166
|
+
|
|
3167
|
+
class Client extends events.EventEmitter {
|
|
3168
|
+
constructor(config: Config);
|
|
3169
|
+
config: Config;
|
|
3170
|
+
dialect: string;
|
|
3171
|
+
driverName: string;
|
|
3172
|
+
connectionSettings: object;
|
|
3173
|
+
|
|
3174
|
+
acquireRawConnection(): Promise<any>;
|
|
3175
|
+
destroyRawConnection(connection: any): Promise<void>;
|
|
3176
|
+
validateConnection(connection: any): Promise<boolean>;
|
|
3177
|
+
logger: Logger;
|
|
3178
|
+
version?: string;
|
|
3179
|
+
connectionConfigProvider: any;
|
|
3180
|
+
connectionConfigExpirationChecker: null | (() => boolean);
|
|
3181
|
+
valueForUndefined: any;
|
|
3182
|
+
formatter(builder: any): any;
|
|
3183
|
+
queryBuilder(): QueryBuilder;
|
|
3184
|
+
queryCompiler(builder: any): any;
|
|
3185
|
+
schemaBuilder(): SchemaBuilder;
|
|
3186
|
+
schemaCompiler(builder: SchemaBuilder): any;
|
|
3187
|
+
tableBuilder(
|
|
3188
|
+
type: any,
|
|
3189
|
+
tableName: any,
|
|
3190
|
+
tableNameLike: any,
|
|
3191
|
+
fn: any
|
|
3192
|
+
): TableBuilder;
|
|
3193
|
+
tableCompiler(tableBuilder: any): any;
|
|
3194
|
+
columnBuilder(tableBuilder: any, type: any, args: any): ColumnBuilder;
|
|
3195
|
+
columnCompiler(tableBuilder: any, columnBuilder: any): any;
|
|
3196
|
+
runner(builder: any): any;
|
|
3197
|
+
transaction(container: any, config: any, outerTx: any): Transaction;
|
|
3198
|
+
raw(...args: any[]): any;
|
|
3199
|
+
ref(...args: any[]): Ref<any, any>;
|
|
3200
|
+
query(connection: any, obj: any): any;
|
|
3201
|
+
stream(connection: any, obj: any, stream: any, options: any): any;
|
|
3202
|
+
prepBindings(bindings: any): any;
|
|
3203
|
+
positionBindings(sql: any): any;
|
|
3204
|
+
postProcessResponse(resp: any, queryContext: any): any;
|
|
3205
|
+
wrapIdentifier(value: any, queryContext: any): any;
|
|
3206
|
+
customWrapIdentifier(value: any, origImpl: any, queryContext: any): any;
|
|
3207
|
+
wrapIdentifierImpl(value: any): string;
|
|
3208
|
+
initializeDriver(): void;
|
|
3209
|
+
driver: any;
|
|
3210
|
+
poolDefaults(): {
|
|
3211
|
+
min: number;
|
|
3212
|
+
max: number;
|
|
3213
|
+
propagateCreateError: boolean;
|
|
3214
|
+
};
|
|
3215
|
+
getPoolSettings(poolConfig: any): any;
|
|
3216
|
+
initializePool(config?: {}): void;
|
|
3217
|
+
pool: TarnPool<any> | undefined;
|
|
3218
|
+
acquireConnection(): any;
|
|
3219
|
+
releaseConnection(connection: any): any;
|
|
3220
|
+
destroy(callback: any): any;
|
|
3221
|
+
database(): any;
|
|
3222
|
+
canCancelQuery: boolean;
|
|
3223
|
+
assertCanCancelQuery(): void;
|
|
3224
|
+
cancelQuery(): void;
|
|
3225
|
+
}
|
|
3226
|
+
}
|
|
3227
|
+
|
|
3228
|
+
export default knex;
|