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
|
@@ -1,277 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/// <reference lib="es2015" />
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.Driver = void 0;
|
|
5
|
-
const util = require("util");
|
|
6
|
-
const shared = require("./_shared");
|
|
7
|
-
const DDL = require("./_ddl-sql");
|
|
8
|
-
const Sync = require("../../../sql-ddl-sync/index");
|
|
9
|
-
const Query_1 = require("../../../sql-query/Query");
|
|
10
|
-
const utils = require("./_utils");
|
|
11
|
-
const Utilities = require("../../Utilities");
|
|
12
|
-
const postgres_1 = require("../DB/postgres");
|
|
13
|
-
exports.Driver = function (config, connection, opts) {
|
|
14
|
-
this.dialect = 'postgresql';
|
|
15
|
-
this.opts = opts || {};
|
|
16
|
-
this.customTypes = {};
|
|
17
|
-
Object.defineProperty(this, 'db', {
|
|
18
|
-
value: connection || new postgres_1.default(config),
|
|
19
|
-
writable: false
|
|
20
|
-
});
|
|
21
|
-
Object.defineProperty(this, 'sqlDriver', {
|
|
22
|
-
value: this.db,
|
|
23
|
-
writable: false
|
|
24
|
-
});
|
|
25
|
-
Object.defineProperty(this, 'config', {
|
|
26
|
-
value: this.db.config,
|
|
27
|
-
writable: false
|
|
28
|
-
});
|
|
29
|
-
if (!this.config.timezone)
|
|
30
|
-
this.config.timezone = "local";
|
|
31
|
-
Object.defineProperty(this, 'ddlSync', {
|
|
32
|
-
value: Sync.dialect(this.dialect),
|
|
33
|
-
writable: false
|
|
34
|
-
});
|
|
35
|
-
Object.defineProperty(this, 'query', {
|
|
36
|
-
value: new Query_1.Query({ dialect: this.dialect, timezone: this.config.timezone }),
|
|
37
|
-
writable: false
|
|
38
|
-
});
|
|
39
|
-
utils.getKnexInstance(this);
|
|
40
|
-
this.aggregate_functions = [
|
|
41
|
-
"ABS", "CEIL", "FLOOR", "ROUND",
|
|
42
|
-
"AVG", "MIN", "MAX",
|
|
43
|
-
"LOG", "EXP", "POWER",
|
|
44
|
-
"ACOS", "ASIN", "ATAN", "COS", "SIN", "TAN",
|
|
45
|
-
"RANDOM", "RADIANS", "DEGREES",
|
|
46
|
-
"SUM", "COUNT",
|
|
47
|
-
"DISTINCT"
|
|
48
|
-
];
|
|
49
|
-
};
|
|
50
|
-
util.extend(exports.Driver.prototype, shared, DDL);
|
|
51
|
-
exports.Driver.prototype.ping = function (cb) {
|
|
52
|
-
this.execSimpleQuery("SELECT * FROM pg_stat_activity LIMIT 1", function () {
|
|
53
|
-
return cb === null || cb === void 0 ? void 0 : cb();
|
|
54
|
-
});
|
|
55
|
-
return this;
|
|
56
|
-
};
|
|
57
|
-
exports.Driver.prototype.on = function (ev, cb) {
|
|
58
|
-
if (ev == "error") {
|
|
59
|
-
this.db.eventor.on("error", cb);
|
|
60
|
-
this.db.eventor.on("unhandledError", cb);
|
|
61
|
-
}
|
|
62
|
-
return this;
|
|
63
|
-
};
|
|
64
|
-
exports.Driver.prototype.connect = function (cb) {
|
|
65
|
-
const syncResponse = Utilities.catchBlocking(() => {
|
|
66
|
-
return this.db.connect();
|
|
67
|
-
});
|
|
68
|
-
Utilities.takeAwayResult(syncResponse, { callback: cb });
|
|
69
|
-
return syncResponse.result;
|
|
70
|
-
};
|
|
71
|
-
exports.Driver.prototype.reconnect = function (cb) {
|
|
72
|
-
const connOpts = this.config.href || this.config;
|
|
73
|
-
this.db = new postgres_1.default(connOpts);
|
|
74
|
-
const syncResponse = Utilities.catchBlocking(() => {
|
|
75
|
-
return this.connect();
|
|
76
|
-
});
|
|
77
|
-
if (typeof cb === 'function')
|
|
78
|
-
cb(null, syncResponse.result);
|
|
79
|
-
return syncResponse.result;
|
|
80
|
-
};
|
|
81
|
-
exports.Driver.prototype.close = function (cb) {
|
|
82
|
-
const errResults = Utilities.catchBlocking(() => this.db.close());
|
|
83
|
-
Utilities.takeAwayResult(errResults, { no_throw: !!cb, callback: cb });
|
|
84
|
-
return errResults.result;
|
|
85
|
-
};
|
|
86
|
-
exports.Driver.prototype.getQuery = function () {
|
|
87
|
-
return this.query;
|
|
88
|
-
};
|
|
89
|
-
exports.Driver.prototype.execSimpleQuery = function (query, cb) {
|
|
90
|
-
if (this.opts.debug) {
|
|
91
|
-
require("../../Debug").sql('postgresql', query);
|
|
92
|
-
}
|
|
93
|
-
return this.db.query(query, cb);
|
|
94
|
-
};
|
|
95
|
-
exports.Driver.prototype.find = function (selectFields, table, conditions, opts) {
|
|
96
|
-
const { from_tuple, pure_table, alias } = Utilities.parseTableInputForSelect(table);
|
|
97
|
-
const ctx = {
|
|
98
|
-
table,
|
|
99
|
-
fromTuple: from_tuple,
|
|
100
|
-
selectFields,
|
|
101
|
-
selectVirtualFields: opts.selectVirtualFields || []
|
|
102
|
-
};
|
|
103
|
-
let q = this.query.select();
|
|
104
|
-
q = typeof (opts === null || opts === void 0 ? void 0 : opts.generateSqlSelect) === 'function' ? (opts === null || opts === void 0 ? void 0 : opts.generateSqlSelect.call(this, ctx, q)) || q : Utilities.DEFAULT_GENERATE_SQL_QUERY_SELECT.call(this, ctx, q);
|
|
105
|
-
if (opts.offset) {
|
|
106
|
-
q.offset(opts.offset);
|
|
107
|
-
}
|
|
108
|
-
if (typeof opts.limit == "number") {
|
|
109
|
-
q.limit(opts.limit);
|
|
110
|
-
}
|
|
111
|
-
if (opts.order) {
|
|
112
|
-
for (let i = 0; i < opts.order.length; i++) {
|
|
113
|
-
q.order(opts.order[i][0], opts.order[i][1]);
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
utils.buildBaseConditionsToQuery.apply(this, [q, pure_table, conditions, opts.topConditions]);
|
|
117
|
-
utils.buildOrderToQuery.apply(this, [q, opts.order]);
|
|
118
|
-
utils.buildMergeToQuery.apply(this, [q, opts.merge, conditions]);
|
|
119
|
-
utils.buildExistsToQuery.apply(this, [q, alias, opts.exists]);
|
|
120
|
-
return this.execSimpleQuery(q.build());
|
|
121
|
-
};
|
|
122
|
-
exports.Driver.prototype.count = function (table, conditions, opts, cb) {
|
|
123
|
-
const { from_tuple, pure_table, alias } = Utilities.parseTableInputForSelect(table);
|
|
124
|
-
const q = this.query.select().from(from_tuple).count(null, 'c');
|
|
125
|
-
utils.buildBaseConditionsToQuery.apply(this, [q, pure_table, conditions]);
|
|
126
|
-
utils.buildMergeToQuery.apply(this, [q, opts.merge, conditions]);
|
|
127
|
-
utils.buildExistsToQuery.apply(this, [q, alias, opts.exists]);
|
|
128
|
-
return this.execSimpleQuery(q.build(), cb);
|
|
129
|
-
};
|
|
130
|
-
exports.Driver.prototype.insert = function (table, data, keyProperties, cb) {
|
|
131
|
-
const q = this.query.insert().into(table).set(data).build();
|
|
132
|
-
const syncResponse = Utilities.catchBlocking(() => {
|
|
133
|
-
const results = this.execSimpleQuery(q + " RETURNING *");
|
|
134
|
-
const ids = {};
|
|
135
|
-
if (keyProperties) {
|
|
136
|
-
for (let i = 0; i < keyProperties.length; i++) {
|
|
137
|
-
const prop = keyProperties[i];
|
|
138
|
-
// Zero is a valid value for an ID column
|
|
139
|
-
ids[prop.name] = results[0][prop.mapsTo] !== undefined ? results[0][prop.mapsTo] : null;
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
return ids;
|
|
143
|
-
});
|
|
144
|
-
Utilities.takeAwayResult(syncResponse, { callback: cb });
|
|
145
|
-
return syncResponse.result;
|
|
146
|
-
};
|
|
147
|
-
exports.Driver.prototype.update = function (table, changes, conditions, cb) {
|
|
148
|
-
const q = this.query.update().into(table).set(changes).where(conditions).build();
|
|
149
|
-
return this.execSimpleQuery(q, cb);
|
|
150
|
-
};
|
|
151
|
-
exports.Driver.prototype.remove = function (table, conditions, cb) {
|
|
152
|
-
const q = this.query.remove().from(table).where(conditions).build();
|
|
153
|
-
return this.execSimpleQuery(q, cb);
|
|
154
|
-
};
|
|
155
|
-
exports.Driver.prototype.clear = function (table, cb) {
|
|
156
|
-
const q = "TRUNCATE TABLE " + this.query.escapeId(table);
|
|
157
|
-
return this.execSimpleQuery(q, cb);
|
|
158
|
-
};
|
|
159
|
-
exports.Driver.prototype.valueToProperty = function (value, property) {
|
|
160
|
-
let customType, v;
|
|
161
|
-
switch (property.type) {
|
|
162
|
-
case "object":
|
|
163
|
-
if (typeof value == "object" && !Buffer.isBuffer(value)) {
|
|
164
|
-
break;
|
|
165
|
-
}
|
|
166
|
-
try {
|
|
167
|
-
value = JSON.parse(value);
|
|
168
|
-
}
|
|
169
|
-
catch (e) {
|
|
170
|
-
value = null;
|
|
171
|
-
}
|
|
172
|
-
break;
|
|
173
|
-
case "binary": {
|
|
174
|
-
// compat with standard behavior of `JSON.stringify`/`JSON.parse`
|
|
175
|
-
if (value && value.type === 'Buffer' && Array.isArray(value.data)) {
|
|
176
|
-
value = Buffer.from(value.data);
|
|
177
|
-
}
|
|
178
|
-
break;
|
|
179
|
-
}
|
|
180
|
-
case "point":
|
|
181
|
-
if (typeof value == "string") {
|
|
182
|
-
const m = value.match(/\((\-?[\d\.]+)[\s,]+(\-?[\d\.]+)\)/);
|
|
183
|
-
if (m) {
|
|
184
|
-
value = { x: parseFloat(m[1]), y: parseFloat(m[2]) };
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
break;
|
|
188
|
-
case "date":
|
|
189
|
-
if ((util.isNumber(value) || util.isString(value)))
|
|
190
|
-
value = new Date(value);
|
|
191
|
-
if (util.isDate(value) && this.config.timezone && this.config.timezone != 'local') {
|
|
192
|
-
const tz = convertTimezone(this.config.timezone);
|
|
193
|
-
// shift local to UTC
|
|
194
|
-
value.setTime(value.getTime() - (value.getTimezoneOffset() * 60000));
|
|
195
|
-
if (tz !== false) {
|
|
196
|
-
// shift UTC to timezone
|
|
197
|
-
value.setTime(value.getTime() - (tz * 60000));
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
break;
|
|
201
|
-
case "number":
|
|
202
|
-
if (typeof value == 'string') {
|
|
203
|
-
switch (value.trim()) {
|
|
204
|
-
case 'Infinity':
|
|
205
|
-
case '-Infinity':
|
|
206
|
-
case 'NaN':
|
|
207
|
-
value = Number(value);
|
|
208
|
-
break;
|
|
209
|
-
default:
|
|
210
|
-
v = parseFloat(value);
|
|
211
|
-
if (Number.isFinite(v)) {
|
|
212
|
-
value = v;
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
break;
|
|
217
|
-
case "integer":
|
|
218
|
-
if (typeof value == 'string') {
|
|
219
|
-
v = parseInt(value);
|
|
220
|
-
if (Number.isFinite(v)) {
|
|
221
|
-
value = v;
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
break;
|
|
225
|
-
default:
|
|
226
|
-
customType = this.customTypes[property.type];
|
|
227
|
-
if (customType && 'valueToProperty' in customType) {
|
|
228
|
-
value = customType.valueToProperty(value, property);
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
return value;
|
|
232
|
-
};
|
|
233
|
-
exports.Driver.prototype.propertyToValue = function (value, property) {
|
|
234
|
-
let customType;
|
|
235
|
-
switch (property.type) {
|
|
236
|
-
case "object":
|
|
237
|
-
if (value !== null) {
|
|
238
|
-
if (!Buffer.isBuffer(value))
|
|
239
|
-
value = JSON.stringify(value).replace(/\\/g, '\\\\');
|
|
240
|
-
}
|
|
241
|
-
break;
|
|
242
|
-
case "date":
|
|
243
|
-
if ((util.isNumber(value) || util.isString(value)))
|
|
244
|
-
value = new Date(value);
|
|
245
|
-
if (util.isDate(value) && this.config.timezone && this.config.timezone != 'local') {
|
|
246
|
-
var tz = convertTimezone(this.config.timezone);
|
|
247
|
-
// shift local to UTC
|
|
248
|
-
value.setTime(value.getTime() + (value.getTimezoneOffset() * 60000));
|
|
249
|
-
if (tz !== false) {
|
|
250
|
-
// shift UTC to timezone
|
|
251
|
-
value.setTime(value.getTime() + (tz * 60000));
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
break;
|
|
255
|
-
case "point":
|
|
256
|
-
return function () { return 'POINT(' + value.x + ', ' + value.y + ')'; };
|
|
257
|
-
default:
|
|
258
|
-
customType = this.customTypes[property.type];
|
|
259
|
-
if (customType && 'propertyToValue' in customType) {
|
|
260
|
-
value = customType.propertyToValue(value);
|
|
261
|
-
}
|
|
262
|
-
}
|
|
263
|
-
return value;
|
|
264
|
-
};
|
|
265
|
-
Object.defineProperty(exports.Driver.prototype, "isSql", {
|
|
266
|
-
value: true
|
|
267
|
-
});
|
|
268
|
-
function convertTimezone(tz) {
|
|
269
|
-
if (tz == "Z") {
|
|
270
|
-
return 0;
|
|
271
|
-
}
|
|
272
|
-
var m = tz.match(/([\+\-\s])(\d\d):?(\d\d)?/);
|
|
273
|
-
if (m) {
|
|
274
|
-
return (m[1] == '-' ? -1 : 1) * (parseInt(m[2], 10) + ((m[3] ? parseInt(m[3], 10) : 0) / 60)) * 60;
|
|
275
|
-
}
|
|
276
|
-
return false;
|
|
277
|
-
}
|
|
@@ -1,267 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Driver = void 0;
|
|
4
|
-
const util = require("util");
|
|
5
|
-
const sqlite3_1 = require("../DB/sqlite3");
|
|
6
|
-
const shared = require("./_shared");
|
|
7
|
-
const DDL = require("./_ddl-sql");
|
|
8
|
-
const Sync = require("../../../sql-ddl-sync/index");
|
|
9
|
-
const utils = require("./_utils");
|
|
10
|
-
const Utilities = require("../../Utilities");
|
|
11
|
-
const Query_1 = require("../../../sql-query/Query");
|
|
12
|
-
const _dml_helpers_1 = require("./_dml-helpers");
|
|
13
|
-
exports.Driver = function (config, connection, opts) {
|
|
14
|
-
this.dialect = 'sqlite';
|
|
15
|
-
this.opts = opts || {};
|
|
16
|
-
this.customTypes = {};
|
|
17
|
-
Object.defineProperty(this, 'db', {
|
|
18
|
-
value: connection || new sqlite3_1.Database(config),
|
|
19
|
-
writable: false
|
|
20
|
-
});
|
|
21
|
-
Object.defineProperty(this, 'sqlDriver', {
|
|
22
|
-
value: this.db,
|
|
23
|
-
writable: false
|
|
24
|
-
});
|
|
25
|
-
Object.defineProperty(this, 'config', {
|
|
26
|
-
value: this.db.config,
|
|
27
|
-
writable: false
|
|
28
|
-
});
|
|
29
|
-
if (!this.config.timezone)
|
|
30
|
-
this.config.timezone = "local";
|
|
31
|
-
Object.defineProperty(this, 'ddlSync', {
|
|
32
|
-
value: Sync.dialect(this.dialect),
|
|
33
|
-
writable: false
|
|
34
|
-
});
|
|
35
|
-
Object.defineProperty(this, 'query', {
|
|
36
|
-
value: new Query_1.Query({ dialect: this.dialect, timezone: this.config.timezone }),
|
|
37
|
-
writable: false
|
|
38
|
-
});
|
|
39
|
-
utils.getKnexInstance(this);
|
|
40
|
-
this.aggregate_functions = ["ABS", "ROUND",
|
|
41
|
-
"AVG", "MIN", "MAX",
|
|
42
|
-
"RANDOM",
|
|
43
|
-
"SUM", "COUNT",
|
|
44
|
-
"DISTINCT"];
|
|
45
|
-
};
|
|
46
|
-
util.extend(exports.Driver.prototype, shared, DDL);
|
|
47
|
-
exports.Driver.prototype.ping = function (cb) {
|
|
48
|
-
Utilities.takeAwayResult({ error: null }, { callback: cb, use_tick: true });
|
|
49
|
-
return this;
|
|
50
|
-
};
|
|
51
|
-
exports.Driver.prototype.on = function (ev, cb) {
|
|
52
|
-
if (ev == "error") {
|
|
53
|
-
this.db.eventor.on("error", cb);
|
|
54
|
-
}
|
|
55
|
-
return this;
|
|
56
|
-
};
|
|
57
|
-
exports.Driver.prototype.connect = function (cb) {
|
|
58
|
-
const errResults = Utilities.catchBlocking(() => this.db.connect());
|
|
59
|
-
Utilities.takeAwayResult(errResults, { no_throw: !!cb, callback: cb });
|
|
60
|
-
return errResults.result;
|
|
61
|
-
};
|
|
62
|
-
exports.Driver.prototype.close = function (cb) {
|
|
63
|
-
const errResults = Utilities.catchBlocking(() => this.db.close());
|
|
64
|
-
Utilities.takeAwayResult(errResults, { no_throw: !!cb, callback: cb });
|
|
65
|
-
return errResults.result;
|
|
66
|
-
};
|
|
67
|
-
exports.Driver.prototype.getQuery = function () {
|
|
68
|
-
return this.query;
|
|
69
|
-
};
|
|
70
|
-
exports.Driver.prototype.execSimpleQuery = function (query, cb) {
|
|
71
|
-
if (this.opts.debug) {
|
|
72
|
-
require("../../Debug").sql('sqlite', query);
|
|
73
|
-
}
|
|
74
|
-
return this.db.all(query, cb);
|
|
75
|
-
};
|
|
76
|
-
exports.Driver.prototype.find = function (selectFields, table, conditions, opts) {
|
|
77
|
-
const { from_tuple, pure_table, alias } = Utilities.parseTableInputForSelect(table);
|
|
78
|
-
const __pointTypeMapsTo = opts.__pointTypeMapsTo || [];
|
|
79
|
-
const ctx = {
|
|
80
|
-
table,
|
|
81
|
-
fromTuple: from_tuple,
|
|
82
|
-
selectFields,
|
|
83
|
-
selectVirtualFields: opts.selectVirtualFields || []
|
|
84
|
-
};
|
|
85
|
-
let q = this.query.select();
|
|
86
|
-
q = typeof (opts === null || opts === void 0 ? void 0 : opts.generateSqlSelect) === 'function' ? (opts === null || opts === void 0 ? void 0 : opts.generateSqlSelect.call(this, ctx, q)) || q : Utilities.DEFAULT_GENERATE_SQL_QUERY_SELECT.call(this, ctx, q);
|
|
87
|
-
if (opts.offset) {
|
|
88
|
-
q.offset(opts.offset);
|
|
89
|
-
}
|
|
90
|
-
if (typeof opts.limit == "number") {
|
|
91
|
-
q.limit(opts.limit);
|
|
92
|
-
}
|
|
93
|
-
else if (opts.offset) {
|
|
94
|
-
// OFFSET cannot be used without LIMIT so we use the biggest INTEGER number possible
|
|
95
|
-
q.limit('9223372036854775807');
|
|
96
|
-
}
|
|
97
|
-
utils.buildBaseConditionsToQuery.apply(this, [q, pure_table, conditions, opts.topConditions]);
|
|
98
|
-
utils.buildOrderToQuery.apply(this, [q, opts.order]);
|
|
99
|
-
utils.buildMergeToQuery.apply(this, [q, opts.merge]);
|
|
100
|
-
utils.buildExistsToQuery.apply(this, [q, alias, opts.exists]);
|
|
101
|
-
const results = this.execSimpleQuery(q.build());
|
|
102
|
-
if (__pointTypeMapsTo.length > 0 && Array.isArray(results)) {
|
|
103
|
-
results.forEach(item => {
|
|
104
|
-
__pointTypeMapsTo.forEach(field => {
|
|
105
|
-
item[field] = (0, _dml_helpers_1.safeParseJson)((0, _dml_helpers_1.unwrapQuote)(item[field]));
|
|
106
|
-
});
|
|
107
|
-
});
|
|
108
|
-
}
|
|
109
|
-
return results;
|
|
110
|
-
};
|
|
111
|
-
exports.Driver.prototype.count = function (table, conditions, opts, cb) {
|
|
112
|
-
const { from_tuple, pure_table, alias } = Utilities.parseTableInputForSelect(table);
|
|
113
|
-
const q = this.query.select()
|
|
114
|
-
.from(from_tuple)
|
|
115
|
-
.count(null, 'c');
|
|
116
|
-
utils.buildBaseConditionsToQuery.apply(this, [q, pure_table, conditions]);
|
|
117
|
-
utils.buildMergeToQuery.apply(this, [q, opts.merge, conditions]);
|
|
118
|
-
utils.buildExistsToQuery.apply(this, [q, alias, opts.exists]);
|
|
119
|
-
return this.execSimpleQuery(q.build(), cb);
|
|
120
|
-
};
|
|
121
|
-
exports.Driver.prototype.insert = function (table, data, keyProperties, cb) {
|
|
122
|
-
var q = this.query.insert()
|
|
123
|
-
.into(table)
|
|
124
|
-
.set(data)
|
|
125
|
-
.build();
|
|
126
|
-
const syncResponse = Utilities.catchBlocking(() => {
|
|
127
|
-
const info = this.execSimpleQuery(q);
|
|
128
|
-
if (!keyProperties)
|
|
129
|
-
return null;
|
|
130
|
-
var ids = {}, prop;
|
|
131
|
-
if (keyProperties.length == 1 && keyProperties[0].type == 'serial') {
|
|
132
|
-
ids[keyProperties[0].name] = info.insertId;
|
|
133
|
-
}
|
|
134
|
-
else {
|
|
135
|
-
for (let i = 0; i < keyProperties.length; i++) {
|
|
136
|
-
prop = keyProperties[i];
|
|
137
|
-
// Zero is a valid value for an ID column
|
|
138
|
-
ids[prop.name] = data[prop.mapsTo] !== undefined ? data[prop.mapsTo] : null;
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
return ids;
|
|
142
|
-
});
|
|
143
|
-
Utilities.takeAwayResult(syncResponse, { callback: cb });
|
|
144
|
-
return syncResponse.result;
|
|
145
|
-
};
|
|
146
|
-
exports.Driver.prototype.update = function (table, changes, conditions, cb) {
|
|
147
|
-
var q = this.query.update()
|
|
148
|
-
.into(table)
|
|
149
|
-
.set(changes)
|
|
150
|
-
.where(conditions)
|
|
151
|
-
.build();
|
|
152
|
-
return this.execSimpleQuery(q, cb);
|
|
153
|
-
};
|
|
154
|
-
exports.Driver.prototype.remove = function (table, conditions, cb) {
|
|
155
|
-
var q = this.query.remove()
|
|
156
|
-
.from(table)
|
|
157
|
-
.where(conditions)
|
|
158
|
-
.build();
|
|
159
|
-
return this.execSimpleQuery(q, cb);
|
|
160
|
-
};
|
|
161
|
-
exports.Driver.prototype.clear = function (table, cb) {
|
|
162
|
-
const syncResponse = Utilities.catchBlocking(() => {
|
|
163
|
-
this.execQuery(this.query.remove()
|
|
164
|
-
.from(table)
|
|
165
|
-
.build());
|
|
166
|
-
this.execQuery(this.query.remove()
|
|
167
|
-
.from(table)
|
|
168
|
-
.where({ name: 'sqlite_sequence' })
|
|
169
|
-
.build());
|
|
170
|
-
});
|
|
171
|
-
Utilities.takeAwayResult(syncResponse, { callback: cb });
|
|
172
|
-
return syncResponse.result;
|
|
173
|
-
};
|
|
174
|
-
exports.Driver.prototype.valueToProperty = function (value, property) {
|
|
175
|
-
var v, customType;
|
|
176
|
-
switch (property.type) {
|
|
177
|
-
case "boolean":
|
|
178
|
-
value = !!value;
|
|
179
|
-
break;
|
|
180
|
-
case "object":
|
|
181
|
-
if (typeof value == "object" && !Buffer.isBuffer(value)) {
|
|
182
|
-
break;
|
|
183
|
-
}
|
|
184
|
-
try {
|
|
185
|
-
value = JSON.parse(value);
|
|
186
|
-
}
|
|
187
|
-
catch (e) {
|
|
188
|
-
value = null;
|
|
189
|
-
}
|
|
190
|
-
break;
|
|
191
|
-
case "binary": {
|
|
192
|
-
// compat with standard behavior of `JSON.stringify`/`JSON.parse`
|
|
193
|
-
if (value && value.type === 'Buffer' && Array.isArray(value.data)) {
|
|
194
|
-
value = Buffer.from(value.data);
|
|
195
|
-
}
|
|
196
|
-
break;
|
|
197
|
-
}
|
|
198
|
-
case "number":
|
|
199
|
-
if (typeof value == 'string') {
|
|
200
|
-
switch (value.trim()) {
|
|
201
|
-
case 'Infinity':
|
|
202
|
-
case '-Infinity':
|
|
203
|
-
case 'NaN':
|
|
204
|
-
value = Number(value);
|
|
205
|
-
break;
|
|
206
|
-
default:
|
|
207
|
-
v = parseFloat(value);
|
|
208
|
-
if (Number.isFinite(v)) {
|
|
209
|
-
value = v;
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
break;
|
|
214
|
-
case "integer":
|
|
215
|
-
if (typeof value == 'string') {
|
|
216
|
-
v = parseInt(value);
|
|
217
|
-
if (Number.isFinite(v)) {
|
|
218
|
-
value = v;
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
break;
|
|
222
|
-
case "date":
|
|
223
|
-
if (util.isNumber(value) || util.isString(value))
|
|
224
|
-
value = new Date(value);
|
|
225
|
-
break;
|
|
226
|
-
default:
|
|
227
|
-
customType = this.customTypes[property.type];
|
|
228
|
-
if (customType && 'valueToProperty' in customType) {
|
|
229
|
-
value = customType.valueToProperty(value, property);
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
return value;
|
|
233
|
-
};
|
|
234
|
-
exports.Driver.prototype.propertyToValue = function (value, property) {
|
|
235
|
-
switch (property.type) {
|
|
236
|
-
case "boolean":
|
|
237
|
-
value = (value) ? 1 : 0;
|
|
238
|
-
break;
|
|
239
|
-
case "object":
|
|
240
|
-
if (value !== null) {
|
|
241
|
-
value = JSON.stringify(value);
|
|
242
|
-
}
|
|
243
|
-
break;
|
|
244
|
-
case "date":
|
|
245
|
-
if (util.isNumber(value) || util.isString(value))
|
|
246
|
-
value = new Date(value);
|
|
247
|
-
break;
|
|
248
|
-
default:
|
|
249
|
-
const customType = this.customTypes[property.type];
|
|
250
|
-
if (customType && 'propertyToValue' in customType) {
|
|
251
|
-
value = customType.propertyToValue(value);
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
return value;
|
|
255
|
-
};
|
|
256
|
-
Object.defineProperty(exports.Driver.prototype, "isSql", {
|
|
257
|
-
value: true
|
|
258
|
-
});
|
|
259
|
-
function convertTimezone(tz) {
|
|
260
|
-
if (tz == "Z")
|
|
261
|
-
return 0;
|
|
262
|
-
var m = tz.match(/([\+\-\s])(\d\d):?(\d\d)?/);
|
|
263
|
-
if (m) {
|
|
264
|
-
return (m[1] == '-' ? -1 : 1) * (parseInt(m[2], 10) + ((m[3] ? parseInt(m[3], 10) : 0) / 60)) * 60;
|
|
265
|
-
}
|
|
266
|
-
return false;
|
|
267
|
-
}
|
package/lib/orm/Error.d.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { FxOrmError } from "./Typo/Error";
|
|
2
|
-
export default class ORMError extends Error {
|
|
3
|
-
static codes: FxOrmError.PredefineErrorCodes;
|
|
4
|
-
name: string;
|
|
5
|
-
message: string;
|
|
6
|
-
code: number | string;
|
|
7
|
-
literalCode: string;
|
|
8
|
-
[k: string]: any;
|
|
9
|
-
constructor(message: string, code?: keyof FxOrmError.PredefineErrorCodes, extras?: any);
|
|
10
|
-
toString(): string;
|
|
11
|
-
}
|
package/lib/orm/Error.js
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const codes = {
|
|
4
|
-
QUERY_ERROR: 1,
|
|
5
|
-
NOT_FOUND: 2,
|
|
6
|
-
NOT_DEFINED: 3,
|
|
7
|
-
NO_SUPPORT: 4,
|
|
8
|
-
MISSING_CALLBACK: 5,
|
|
9
|
-
PARAM_MISMATCH: 6,
|
|
10
|
-
CONNECTION_LOST: 10,
|
|
11
|
-
BAD_MODEL: 15
|
|
12
|
-
};
|
|
13
|
-
class ORMError extends Error {
|
|
14
|
-
constructor(message, code, extras) {
|
|
15
|
-
super();
|
|
16
|
-
this.name = 'ORMError';
|
|
17
|
-
this.message = '';
|
|
18
|
-
this.code = 0;
|
|
19
|
-
this.literalCode = '';
|
|
20
|
-
Error.call(this);
|
|
21
|
-
Error.captureStackTrace(this, this.constructor);
|
|
22
|
-
this.message = message;
|
|
23
|
-
if (code) {
|
|
24
|
-
this.code = codes[code];
|
|
25
|
-
this.literalCode = code;
|
|
26
|
-
if (!this.code) {
|
|
27
|
-
throw new Error("Invalid error code: " + code);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
if (extras) {
|
|
31
|
-
for (let k in extras) {
|
|
32
|
-
this[k] = extras[k];
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
toString() {
|
|
37
|
-
return '[ORMError ' + this.literalCode + ': ' + this.message + ']';
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
ORMError.codes = codes;
|
|
41
|
-
exports.default = ORMError;
|
package/lib/orm/Helpers.d.ts
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { FxDbDriverNS, IDbDriver } from "../db-driver/index";
|
|
2
|
-
import { FxOrmNS } from './Typo/ORM';
|
|
3
|
-
import { FxOrmInstance } from './Typo/instance';
|
|
4
|
-
import { FxOrmAssociation } from './Typo/assoc';
|
|
5
|
-
import { FxOrmModel } from './Typo/model';
|
|
6
|
-
import { FxOrmHook } from './Typo/hook';
|
|
7
|
-
import { FxOrmProperty } from "./Typo/property";
|
|
8
|
-
export declare function buildDbDriver(opts: string | FxDbDriverNS.DBConnectionConfig): FxOrmNS.ORMLike | IDbDriver;
|
|
9
|
-
export declare function pickProperties<T extends FxOrmModel.Model = FxOrmModel.Model>(m: T, picker: ((p: FxOrmProperty.NormalizedProperty, k: string, m: T) => boolean)): Record<string, FxOrmProperty.NormalizedProperty>;
|
|
10
|
-
export declare function getManyAssociationItemFromInstanceByExtname(instance: FxOrmInstance.Instance, extend_name: string): FxOrmAssociation.InstanceAssociationItem_HasMany;
|
|
11
|
-
export declare function getOneAssociationItemFromInstanceByExtname(instance: FxOrmInstance.Instance, extend_name: string): FxOrmAssociation.InstanceAssociationItem_HasOne;
|
|
12
|
-
export declare function getExtendsToAssociationItemFromInstanceByExtname(instance: FxOrmInstance.Instance, extend_name: string): FxOrmAssociation.InstanceAssociationItem_ExtendTos;
|
|
13
|
-
export declare function getAssociationItemFromInstanceByExtname(reltype: string, inst: FxOrmInstance.Instance, extend_name: string): FxOrmAssociation.InstanceAssociationItem;
|
|
14
|
-
export declare function getManyAssociationItemFromInstanceByAssocModel(instance: FxOrmInstance.Instance, assoc_model: FxOrmModel.Model): FxOrmAssociation.InstanceAssociationItem_HasMany;
|
|
15
|
-
export declare function getOneAssociationItemFromInstanceByAssocModel(instance: FxOrmInstance.Instance, assoc_model: FxOrmModel.Model): FxOrmAssociation.InstanceAssociationItem_HasOne;
|
|
16
|
-
export declare function getExtendsToAssociationItemFromInstanceByAssocModel(instance: FxOrmInstance.Instance, assoc_model: FxOrmModel.Model): FxOrmAssociation.InstanceAssociationItem_ExtendTos;
|
|
17
|
-
export declare function getAssociationItemFromInstanceByAssocModel(reltype: string, inst: FxOrmInstance.Instance, assoc_model: FxOrmModel.Model): FxOrmAssociation.InstanceAssociationItem;
|
|
18
|
-
export declare function getManyAssociationItemFromModel(ext_name: string, _model: FxOrmModel.Model): FxOrmAssociation.InstanceAssociationItem_HasMany;
|
|
19
|
-
export declare function getOneAssociationItemFromModel(ext_name: string, _model: FxOrmModel.Model): FxOrmAssociation.InstanceAssociationItem_HasOne;
|
|
20
|
-
export declare function getExtendsToAssociationItemFromModel(ext_name: string, _model: FxOrmModel.Model): FxOrmAssociation.InstanceAssociationItem_ExtendTos;
|
|
21
|
-
export declare function getAssociationItemFromModel(reltype: string, extend_name: string, _model: FxOrmModel.Model): FxOrmAssociation.InstanceAssociationItem;
|
|
22
|
-
export declare function tryGetAssociationItemFromModel(extend_name: string, _model: FxOrmModel.Model): FxOrmAssociation.InstanceAssociationItem;
|
|
23
|
-
export declare function prependHook(hooks: FxOrmModel.Hooks, hookName: keyof FxOrmModel.Hooks, preLogic: FxOrmHook.HookActionCallback | FxOrmHook.HookResultCallback): void;
|
|
24
|
-
export declare function preReplaceHook(m: FxOrmModel.Model, opts: FxOrmModel.ModelDefineOptions, hookName: keyof FxOrmModel.Hooks, cb: (this: FxOrmInstance.Instance, inst: FxOrmInstance.Instance) => void): void;
|
|
25
|
-
export declare const hookTrigger: FxOrmHook.HookTrigger<any, any>;
|
|
26
|
-
export declare const hookWait: FxOrmHook.HookWait<FxOrmInstance.Instance<Record<string, FxOrmInstance.FieldRuntimeType>, Record<string, (...args: any) => any>>, any>;
|
|
27
|
-
export declare function selectArgs(args: ArrayLike<any>, callback: {
|
|
28
|
-
(arg_type: "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function", arg: any, idx: number): void;
|
|
29
|
-
}): void;
|
|
30
|
-
export declare function parseDriverUidAndTableNameFromUID(uid: string): {
|
|
31
|
-
driver_uid: string;
|
|
32
|
-
table: string;
|
|
33
|
-
driver_table_uid: string;
|
|
34
|
-
};
|
|
35
|
-
export declare function valueOrComputeFunction<T = Exclude<any, Function>>(input: T | ((...args: any[]) => T), args?: any[], thisArg?: any): T;
|