@uql/core 1.0.12 → 3.1.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/CHANGELOG.md +254 -0
- package/LICENSE.md +2 -2
- package/dist/browser/http/bus.d.ts +3 -0
- package/dist/browser/http/bus.js +14 -0
- package/dist/browser/http/http.d.ts +6 -0
- package/dist/browser/http/http.js +45 -0
- package/dist/browser/http/index.d.ts +2 -0
- package/dist/browser/http/index.js +3 -0
- package/dist/browser/index.d.ts +4 -0
- package/dist/browser/index.js +5 -0
- package/dist/browser/options.d.ts +4 -0
- package/dist/browser/options.js +14 -0
- package/dist/browser/querier/genericClientRepository.d.ts +17 -0
- package/dist/browser/querier/genericClientRepository.js +39 -0
- package/dist/browser/querier/httpQuerier.d.ts +20 -0
- package/dist/browser/querier/httpQuerier.js +71 -0
- package/dist/browser/querier/index.d.ts +3 -0
- package/dist/browser/querier/index.js +4 -0
- package/dist/browser/querier/querier.util.d.ts +2 -0
- package/dist/browser/querier/querier.util.js +17 -0
- package/dist/browser/type/clientQuerier.d.ts +16 -0
- package/dist/browser/type/clientQuerier.js +2 -0
- package/dist/browser/type/clientQuerierPool.d.ts +4 -0
- package/dist/browser/type/clientQuerierPool.js +2 -0
- package/dist/browser/type/clientRepository.d.ts +13 -0
- package/dist/browser/type/clientRepository.js +2 -0
- package/dist/browser/type/index.d.ts +4 -0
- package/dist/browser/type/index.js +5 -0
- package/dist/browser/type/request.d.ts +28 -0
- package/dist/browser/type/request.js +2 -0
- package/dist/browser/uql-browser.min.js +2150 -0
- package/dist/browser/uql-browser.min.js.map +1 -0
- package/dist/dialect/abstractDialect.d.ts +16 -0
- package/dist/dialect/abstractDialect.js +28 -0
- package/dist/dialect/abstractSqlDialect.d.ts +47 -0
- package/dist/dialect/abstractSqlDialect.js +650 -0
- package/dist/dialect/index.d.ts +3 -0
- package/dist/dialect/index.js +4 -0
- package/dist/dialect/queryContext.d.ts +48 -0
- package/dist/dialect/queryContext.js +65 -0
- package/{entity → dist/entity}/decorator/definition.d.ts +3 -3
- package/dist/entity/decorator/definition.js +214 -0
- package/{entity → dist/entity}/decorator/entity.d.ts +1 -1
- package/dist/entity/decorator/entity.js +7 -0
- package/{entity → dist/entity}/decorator/field.d.ts +1 -1
- package/dist/entity/decorator/field.js +8 -0
- package/{entity → dist/entity}/decorator/id.d.ts +1 -1
- package/dist/entity/decorator/id.js +8 -0
- package/dist/entity/decorator/index.d.ts +5 -0
- package/dist/entity/decorator/index.js +6 -0
- package/{entity → dist/entity}/decorator/relation.d.ts +1 -1
- package/dist/entity/decorator/relation.js +20 -0
- package/dist/entity/index.d.ts +1 -0
- package/dist/entity/index.js +2 -0
- package/dist/express/index.d.ts +2 -0
- package/dist/express/index.js +3 -0
- package/dist/express/querierMiddleware.d.ts +26 -0
- package/dist/express/querierMiddleware.js +190 -0
- package/dist/express/query.util.d.ts +2 -0
- package/dist/express/query.util.js +19 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +10 -0
- package/dist/maria/index.d.ts +3 -0
- package/dist/maria/index.js +4 -0
- package/dist/maria/mariaDialect.d.ts +8 -0
- package/dist/maria/mariaDialect.js +38 -0
- package/dist/maria/mariaQuerierPool.test.d.ts +5 -0
- package/dist/maria/mariaQuerierPool.test.js +19 -0
- package/dist/maria/mariadbQuerier.d.ts +17 -0
- package/dist/maria/mariadbQuerier.js +39 -0
- package/dist/maria/mariadbQuerier.test.d.ts +4 -0
- package/dist/maria/mariadbQuerier.test.js +19 -0
- package/dist/maria/mariadbQuerierPool.d.ts +10 -0
- package/dist/maria/mariadbQuerierPool.js +17 -0
- package/dist/migrate/cli.d.ts +2 -0
- package/dist/migrate/cli.js +254 -0
- package/dist/migrate/generator/index.d.ts +4 -0
- package/dist/migrate/generator/index.js +5 -0
- package/dist/migrate/generator/mongoSchemaGenerator.d.ts +12 -0
- package/dist/migrate/generator/mongoSchemaGenerator.js +100 -0
- package/dist/migrate/generator/mysqlSchemaGenerator.d.ts +14 -0
- package/dist/migrate/generator/mysqlSchemaGenerator.js +81 -0
- package/dist/migrate/generator/postgresSchemaGenerator.d.ts +18 -0
- package/dist/migrate/generator/postgresSchemaGenerator.js +111 -0
- package/dist/migrate/generator/sqliteSchemaGenerator.d.ts +14 -0
- package/dist/migrate/generator/sqliteSchemaGenerator.js +68 -0
- package/dist/migrate/index.d.ts +12 -0
- package/dist/migrate/index.js +17 -0
- package/dist/migrate/introspection/index.d.ts +4 -0
- package/dist/migrate/introspection/index.js +5 -0
- package/dist/migrate/introspection/mongoIntrospector.d.ts +8 -0
- package/dist/migrate/introspection/mongoIntrospector.js +46 -0
- package/dist/migrate/introspection/mysqlIntrospector.d.ts +25 -0
- package/dist/migrate/introspection/mysqlIntrospector.js +220 -0
- package/dist/migrate/introspection/postgresIntrospector.d.ts +21 -0
- package/dist/migrate/introspection/postgresIntrospector.js +269 -0
- package/dist/migrate/introspection/sqliteIntrospector.d.ts +23 -0
- package/dist/migrate/introspection/sqliteIntrospector.js +212 -0
- package/dist/migrate/migrator-mongo.test.d.ts +1 -0
- package/dist/migrate/migrator-mongo.test.js +54 -0
- package/dist/migrate/migrator.d.ts +133 -0
- package/dist/migrate/migrator.js +600 -0
- package/dist/migrate/migrator.test.d.ts +1 -0
- package/dist/migrate/migrator.test.js +106 -0
- package/dist/migrate/schemaGenerator.d.ts +78 -0
- package/dist/migrate/schemaGenerator.js +363 -0
- package/dist/migrate/storage/databaseStorage.d.ts +24 -0
- package/dist/migrate/storage/databaseStorage.js +77 -0
- package/dist/migrate/storage/index.d.ts +2 -0
- package/dist/migrate/storage/index.js +3 -0
- package/dist/migrate/storage/jsonStorage.d.ts +15 -0
- package/dist/migrate/storage/jsonStorage.js +51 -0
- package/dist/migrate/type.d.ts +1 -0
- package/dist/migrate/type.js +2 -0
- package/dist/mongo/index.d.ts +3 -0
- package/dist/mongo/index.js +4 -0
- package/dist/mongo/mongoDialect.d.ts +34 -0
- package/dist/mongo/mongoDialect.js +163 -0
- package/dist/mongo/mongodbQuerier.d.ts +28 -0
- package/dist/mongo/mongodbQuerier.js +204 -0
- package/dist/mongo/mongodbQuerier.test.d.ts +1 -0
- package/dist/mongo/mongodbQuerier.test.js +36 -0
- package/dist/mongo/mongodbQuerierPool.d.ts +10 -0
- package/dist/mongo/mongodbQuerierPool.js +20 -0
- package/dist/mongo/mongodbQuerierPool.test.d.ts +1 -0
- package/dist/mongo/mongodbQuerierPool.test.js +21 -0
- package/dist/mysql/index.d.ts +3 -0
- package/dist/mysql/index.js +4 -0
- package/dist/mysql/mysql2Querier.d.ts +17 -0
- package/dist/mysql/mysql2Querier.js +43 -0
- package/dist/mysql/mysql2Querier.test.d.ts +4 -0
- package/dist/mysql/mysql2Querier.test.js +16 -0
- package/dist/mysql/mysql2QuerierPool.d.ts +10 -0
- package/dist/mysql/mysql2QuerierPool.js +17 -0
- package/dist/mysql/mysql2QuerierPool.test.d.ts +5 -0
- package/dist/mysql/mysql2QuerierPool.test.js +16 -0
- package/dist/mysql/mysqlDialect.d.ts +5 -0
- package/dist/mysql/mysqlDialect.js +15 -0
- package/dist/namingStrategy/defaultNamingStrategy.d.ts +9 -0
- package/dist/namingStrategy/defaultNamingStrategy.js +15 -0
- package/dist/namingStrategy/index.d.ts +2 -0
- package/dist/namingStrategy/index.js +3 -0
- package/dist/namingStrategy/snakeCaseNamingStrategy.d.ts +8 -0
- package/dist/namingStrategy/snakeCaseNamingStrategy.js +14 -0
- package/{options.d.ts → dist/options.d.ts} +1 -1
- package/dist/options.js +14 -0
- package/dist/package.json +131 -0
- package/dist/postgres/index.d.ts +3 -0
- package/dist/postgres/index.js +4 -0
- package/dist/postgres/pgQuerier.d.ts +17 -0
- package/dist/postgres/pgQuerier.js +39 -0
- package/dist/postgres/pgQuerier.test.d.ts +4 -0
- package/dist/postgres/pgQuerier.test.js +20 -0
- package/dist/postgres/pgQuerierPool.d.ts +10 -0
- package/dist/postgres/pgQuerierPool.js +17 -0
- package/dist/postgres/pgQuerierPool.test.d.ts +5 -0
- package/dist/postgres/pgQuerierPool.test.js +23 -0
- package/dist/postgres/postgresDialect.d.ts +13 -0
- package/dist/postgres/postgresDialect.js +110 -0
- package/dist/querier/abstractQuerier-test.d.ts +45 -0
- package/dist/querier/abstractQuerier-test.js +461 -0
- package/dist/querier/abstractQuerier.d.ts +50 -0
- package/dist/querier/abstractQuerier.js +278 -0
- package/dist/querier/abstractQuerierPool-test.d.ts +9 -0
- package/dist/querier/abstractQuerierPool-test.js +18 -0
- package/dist/querier/abstractQuerierPool.d.ts +14 -0
- package/dist/querier/abstractQuerierPool.js +9 -0
- package/dist/querier/abstractSqlQuerier-test.d.ts +9 -0
- package/dist/querier/abstractSqlQuerier-test.js +16 -0
- package/dist/querier/abstractSqlQuerier.d.ts +28 -0
- package/dist/querier/abstractSqlQuerier.js +133 -0
- package/dist/querier/decorator/index.d.ts +3 -0
- package/dist/querier/decorator/index.js +4 -0
- package/dist/querier/decorator/injectQuerier.d.ts +3 -0
- package/dist/querier/decorator/injectQuerier.js +33 -0
- package/dist/querier/decorator/serialized.d.ts +6 -0
- package/dist/querier/decorator/serialized.js +14 -0
- package/{querier → dist/querier}/decorator/transactional.d.ts +1 -1
- package/dist/querier/decorator/transactional.js +48 -0
- package/dist/querier/index.d.ts +4 -0
- package/dist/querier/index.js +5 -0
- package/dist/repository/genericRepository.d.ts +20 -0
- package/dist/repository/genericRepository.js +51 -0
- package/dist/repository/index.d.ts +1 -0
- package/dist/repository/index.js +2 -0
- package/dist/sqlite/index.d.ts +3 -0
- package/dist/sqlite/index.js +4 -0
- package/dist/sqlite/sqliteDialect.d.ts +10 -0
- package/dist/sqlite/sqliteDialect.js +48 -0
- package/dist/sqlite/sqliteQuerier.d.ts +15 -0
- package/dist/sqlite/sqliteQuerier.js +33 -0
- package/dist/sqlite/sqliteQuerier.test.d.ts +5 -0
- package/dist/sqlite/sqliteQuerier.test.js +19 -0
- package/dist/sqlite/sqliteQuerierPool.d.ts +14 -0
- package/dist/sqlite/sqliteQuerierPool.js +34 -0
- package/dist/sqlite/sqliteQuerierPool.test.d.ts +5 -0
- package/dist/sqlite/sqliteQuerierPool.test.js +10 -0
- package/dist/test/entityMock.d.ts +164 -0
- package/dist/test/entityMock.js +554 -0
- package/dist/test/index.d.ts +3 -0
- package/dist/test/index.js +4 -0
- package/dist/test/it.util.d.ts +4 -0
- package/dist/test/it.util.js +55 -0
- package/dist/test/spec.util.d.ts +14 -0
- package/dist/test/spec.util.js +50 -0
- package/{type → dist/type}/entity.d.ts +97 -4
- package/dist/type/entity.js +5 -0
- package/dist/type/index.d.ts +9 -0
- package/dist/type/index.js +10 -0
- package/dist/type/migration.d.ts +213 -0
- package/dist/type/migration.js +2 -0
- package/dist/type/namingStrategy.d.ts +17 -0
- package/dist/type/namingStrategy.js +2 -0
- package/dist/type/querier.d.ts +96 -0
- package/dist/type/querier.js +11 -0
- package/{type → dist/type}/querierPool.d.ts +7 -3
- package/dist/type/querierPool.js +2 -0
- package/{type → dist/type}/query.d.ts +170 -108
- package/dist/type/query.js +9 -0
- package/{type → dist/type}/repository.d.ts +42 -35
- package/dist/type/repository.js +2 -0
- package/{type → dist/type}/universalQuerier.d.ts +50 -28
- package/dist/type/universalQuerier.js +2 -0
- package/dist/type/utility.d.ts +13 -0
- package/dist/type/utility.js +2 -0
- package/dist/util/dialect.util.d.ts +12 -0
- package/dist/util/dialect.util.js +93 -0
- package/dist/util/index.d.ts +5 -0
- package/dist/util/index.js +6 -0
- package/dist/util/object.util.d.ts +7 -0
- package/dist/util/object.util.js +19 -0
- package/dist/util/raw.d.ts +8 -0
- package/dist/util/raw.js +11 -0
- package/dist/util/sql.util.d.ts +13 -0
- package/dist/util/sql.util.js +78 -0
- package/{util → dist/util}/string.util.d.ts +1 -0
- package/dist/util/string.util.js +34 -0
- package/package.json +85 -17
- package/src/@types/index.d.ts +1 -0
- package/src/@types/jest.d.ts +6 -0
- package/src/browser/http/bus.spec.ts +22 -0
- package/src/browser/http/bus.ts +17 -0
- package/src/browser/http/http.spec.ts +70 -0
- package/src/browser/http/http.ts +55 -0
- package/src/browser/http/index.ts +2 -0
- package/src/browser/index.ts +4 -0
- package/src/browser/options.spec.ts +37 -0
- package/src/browser/options.ts +18 -0
- package/src/browser/querier/genericClientRepository.spec.ts +105 -0
- package/src/browser/querier/genericClientRepository.ts +49 -0
- package/src/browser/querier/httpQuerier.ts +82 -0
- package/src/browser/querier/index.ts +3 -0
- package/src/browser/querier/querier.util.spec.ts +35 -0
- package/src/browser/querier/querier.util.ts +18 -0
- package/src/browser/type/clientQuerier.ts +45 -0
- package/src/browser/type/clientQuerierPool.ts +5 -0
- package/src/browser/type/clientRepository.ts +22 -0
- package/src/browser/type/index.ts +4 -0
- package/src/browser/type/request.ts +25 -0
- package/src/dialect/abstractDialect.ts +28 -0
- package/src/dialect/abstractSqlDialect-spec.ts +1309 -0
- package/src/dialect/abstractSqlDialect.ts +805 -0
- package/src/dialect/index.ts +3 -0
- package/src/dialect/namingStrategy.spec.ts +52 -0
- package/src/dialect/queryContext.ts +69 -0
- package/src/entity/decorator/definition.spec.ts +736 -0
- package/src/entity/decorator/definition.ts +265 -0
- package/src/entity/decorator/entity.ts +8 -0
- package/src/entity/decorator/field.ts +9 -0
- package/src/entity/decorator/id.ts +9 -0
- package/src/entity/decorator/index.ts +5 -0
- package/src/entity/decorator/relation.spec.ts +41 -0
- package/src/entity/decorator/relation.ts +34 -0
- package/src/entity/index.ts +1 -0
- package/src/express/@types/express.d.ts +8 -0
- package/src/express/@types/index.d.ts +1 -0
- package/src/express/index.ts +2 -0
- package/src/express/querierMiddleware.ts +217 -0
- package/src/express/query.util.spec.ts +40 -0
- package/src/express/query.util.ts +21 -0
- package/src/index.ts +9 -0
- package/src/maria/index.ts +3 -0
- package/src/maria/mariaDialect.spec.ts +207 -0
- package/src/maria/mariaDialect.ts +42 -0
- package/src/maria/mariaQuerierPool.test.ts +23 -0
- package/src/maria/mariadbQuerier.test.ts +23 -0
- package/src/maria/mariadbQuerier.ts +45 -0
- package/src/maria/mariadbQuerierPool.ts +21 -0
- package/src/migrate/cli.ts +301 -0
- package/src/migrate/generator/index.ts +4 -0
- package/src/migrate/generator/mongoSchemaGenerator.spec.ts +112 -0
- package/src/migrate/generator/mongoSchemaGenerator.ts +115 -0
- package/src/migrate/generator/mysqlSchemaGenerator.spec.ts +34 -0
- package/src/migrate/generator/mysqlSchemaGenerator.ts +92 -0
- package/src/migrate/generator/postgresSchemaGenerator.spec.ts +44 -0
- package/src/migrate/generator/postgresSchemaGenerator.ts +127 -0
- package/src/migrate/generator/sqliteSchemaGenerator.spec.ts +33 -0
- package/src/migrate/generator/sqliteSchemaGenerator.ts +81 -0
- package/src/migrate/index.ts +41 -0
- package/src/migrate/introspection/index.ts +4 -0
- package/src/migrate/introspection/mongoIntrospector.spec.ts +75 -0
- package/src/migrate/introspection/mongoIntrospector.ts +47 -0
- package/src/migrate/introspection/mysqlIntrospector.spec.ts +113 -0
- package/src/migrate/introspection/mysqlIntrospector.ts +278 -0
- package/src/migrate/introspection/postgresIntrospector.spec.ts +112 -0
- package/src/migrate/introspection/postgresIntrospector.ts +329 -0
- package/src/migrate/introspection/sqliteIntrospector.spec.ts +112 -0
- package/src/migrate/introspection/sqliteIntrospector.ts +296 -0
- package/src/migrate/migrator-mongo.test.ts +54 -0
- package/src/migrate/migrator.spec.ts +255 -0
- package/src/migrate/migrator.test.ts +94 -0
- package/src/migrate/migrator.ts +719 -0
- package/src/migrate/namingStrategy.spec.ts +22 -0
- package/src/migrate/schemaGenerator-advanced.spec.ts +138 -0
- package/src/migrate/schemaGenerator.spec.ts +190 -0
- package/src/migrate/schemaGenerator.ts +478 -0
- package/src/migrate/storage/databaseStorage.spec.ts +69 -0
- package/src/migrate/storage/databaseStorage.ts +100 -0
- package/src/migrate/storage/index.ts +2 -0
- package/src/migrate/storage/jsonStorage.ts +58 -0
- package/src/migrate/type.ts +1 -0
- package/src/mongo/index.ts +3 -0
- package/src/mongo/mongoDialect.spec.ts +251 -0
- package/src/mongo/mongoDialect.ts +238 -0
- package/src/mongo/mongodbQuerier.test.ts +45 -0
- package/src/mongo/mongodbQuerier.ts +256 -0
- package/src/mongo/mongodbQuerierPool.test.ts +25 -0
- package/src/mongo/mongodbQuerierPool.ts +24 -0
- package/src/mysql/index.ts +3 -0
- package/src/mysql/mysql2Querier.test.ts +20 -0
- package/src/mysql/mysql2Querier.ts +49 -0
- package/src/mysql/mysql2QuerierPool.test.ts +20 -0
- package/src/mysql/mysql2QuerierPool.ts +21 -0
- package/src/mysql/mysqlDialect.spec.ts +20 -0
- package/src/mysql/mysqlDialect.ts +16 -0
- package/src/namingStrategy/defaultNamingStrategy.ts +18 -0
- package/src/namingStrategy/index.spec.ts +36 -0
- package/src/namingStrategy/index.ts +2 -0
- package/src/namingStrategy/snakeCaseNamingStrategy.ts +15 -0
- package/src/options.spec.ts +41 -0
- package/src/options.ts +18 -0
- package/src/postgres/index.ts +3 -0
- package/src/postgres/manual-types.d.ts +4 -0
- package/src/postgres/pgQuerier.test.ts +25 -0
- package/src/postgres/pgQuerier.ts +45 -0
- package/src/postgres/pgQuerierPool.test.ts +28 -0
- package/src/postgres/pgQuerierPool.ts +21 -0
- package/src/postgres/postgresDialect.spec.ts +428 -0
- package/src/postgres/postgresDialect.ts +144 -0
- package/src/querier/abstractQuerier-test.ts +584 -0
- package/src/querier/abstractQuerier.ts +353 -0
- package/src/querier/abstractQuerierPool-test.ts +20 -0
- package/src/querier/abstractQuerierPool.ts +18 -0
- package/src/querier/abstractSqlQuerier-spec.ts +979 -0
- package/src/querier/abstractSqlQuerier-test.ts +21 -0
- package/src/querier/abstractSqlQuerier.ts +138 -0
- package/src/querier/decorator/index.ts +3 -0
- package/src/querier/decorator/injectQuerier.spec.ts +74 -0
- package/src/querier/decorator/injectQuerier.ts +45 -0
- package/src/querier/decorator/serialized.spec.ts +98 -0
- package/src/querier/decorator/serialized.ts +13 -0
- package/src/querier/decorator/transactional.spec.ts +240 -0
- package/src/querier/decorator/transactional.ts +56 -0
- package/src/querier/index.ts +4 -0
- package/src/repository/genericRepository.spec.ts +111 -0
- package/src/repository/genericRepository.ts +74 -0
- package/src/repository/index.ts +1 -0
- package/src/sqlite/index.ts +3 -0
- package/src/sqlite/manual-types.d.ts +4 -0
- package/src/sqlite/sqliteDialect.spec.ts +155 -0
- package/src/sqlite/sqliteDialect.ts +76 -0
- package/src/sqlite/sqliteQuerier.spec.ts +36 -0
- package/src/sqlite/sqliteQuerier.test.ts +21 -0
- package/src/sqlite/sqliteQuerier.ts +37 -0
- package/src/sqlite/sqliteQuerierPool.test.ts +12 -0
- package/src/sqlite/sqliteQuerierPool.ts +38 -0
- package/src/test/entityMock.ts +375 -0
- package/src/test/index.ts +3 -0
- package/src/test/it.util.ts +69 -0
- package/src/test/spec.util.ts +57 -0
- package/src/type/entity.ts +218 -0
- package/src/type/index.ts +9 -0
- package/src/type/migration.ts +241 -0
- package/src/type/namingStrategy.ts +17 -0
- package/src/type/querier.ts +143 -0
- package/src/type/querierPool.ts +26 -0
- package/src/type/query.ts +506 -0
- package/src/type/repository.ts +142 -0
- package/src/type/universalQuerier.ts +133 -0
- package/src/type/utility.ts +21 -0
- package/src/util/dialect.util-extra.spec.ts +96 -0
- package/src/util/dialect.util.spec.ts +23 -0
- package/src/util/dialect.util.ts +134 -0
- package/src/util/index.ts +5 -0
- package/src/util/object.util.spec.ts +29 -0
- package/src/util/object.util.ts +27 -0
- package/src/util/raw.ts +11 -0
- package/src/util/sql.util-extra.spec.ts +17 -0
- package/src/util/sql.util.spec.ts +208 -0
- package/src/util/sql.util.ts +104 -0
- package/src/util/string.util.spec.ts +46 -0
- package/src/util/string.util.ts +35 -0
- package/tsconfig.build.json +5 -0
- package/tsconfig.json +8 -0
- package/README.md +0 -177
- package/dialect/abstractSqlDialect.d.ts +0 -30
- package/dialect/abstractSqlDialect.js +0 -365
- package/dialect/index.d.ts +0 -4
- package/dialect/index.js +0 -8
- package/dialect/mysqlDialect.d.ts +0 -6
- package/dialect/mysqlDialect.js +0 -21
- package/dialect/postgresDialect.d.ts +0 -8
- package/dialect/postgresDialect.js +0 -44
- package/dialect/sqliteDialect.d.ts +0 -4
- package/dialect/sqliteDialect.js +0 -11
- package/entity/decorator/definition.js +0 -223
- package/entity/decorator/entity.js +0 -11
- package/entity/decorator/field.js +0 -12
- package/entity/decorator/id.js +0 -12
- package/entity/decorator/index.d.ts +0 -5
- package/entity/decorator/index.js +0 -12
- package/entity/decorator/relation.js +0 -27
- package/entity/index.d.ts +0 -1
- package/entity/index.js +0 -5
- package/index.d.ts +0 -1
- package/index.js +0 -5
- package/options.js +0 -20
- package/querier/abstractQuerier.d.ts +0 -30
- package/querier/abstractQuerier.js +0 -230
- package/querier/abstractSqlQuerier.d.ts +0 -27
- package/querier/abstractSqlQuerier.js +0 -88
- package/querier/decorator/index.d.ts +0 -2
- package/querier/decorator/index.js +0 -6
- package/querier/decorator/injectQuerier.d.ts +0 -3
- package/querier/decorator/injectQuerier.js +0 -39
- package/querier/decorator/transactional.js +0 -52
- package/querier/index.d.ts +0 -3
- package/querier/index.js +0 -7
- package/repository/genericRepository.d.ts +0 -19
- package/repository/genericRepository.js +0 -52
- package/repository/index.d.ts +0 -1
- package/repository/index.js +0 -5
- package/type/entity.js +0 -5
- package/type/index.d.ts +0 -7
- package/type/index.js +0 -11
- package/type/querier.d.ts +0 -53
- package/type/querier.js +0 -3
- package/type/querierPool.js +0 -3
- package/type/query.js +0 -13
- package/type/repository.js +0 -3
- package/type/universalQuerier.js +0 -3
- package/type/utility.d.ts +0 -12
- package/type/utility.js +0 -3
- package/util/dialect.util.d.ts +0 -17
- package/util/dialect.util.js +0 -114
- package/util/index.d.ts +0 -5
- package/util/index.js +0 -9
- package/util/object.util.d.ts +0 -3
- package/util/object.util.js +0 -22
- package/util/raw.d.ts +0 -2
- package/util/raw.js +0 -9
- package/util/sql.util.d.ts +0 -2
- package/util/sql.util.js +0 -55
- package/util/string.util.js +0 -20
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
import { expect, it } from 'bun:test';
|
|
2
|
+
import type { Item, ItemAdjustment, Storehouse } from '../test/index.js';
|
|
3
|
+
import type { QuerySortMap } from '../type/index.js';
|
|
4
|
+
import { escapeSqlId, flatObject, obtainAttrsPaths, unflatObjects } from './sql.util.js';
|
|
5
|
+
|
|
6
|
+
it('flatObject', () => {
|
|
7
|
+
expect(flatObject(undefined)).toEqual({});
|
|
8
|
+
expect(flatObject(null)).toEqual({});
|
|
9
|
+
expect(flatObject({})).toEqual({});
|
|
10
|
+
const sort: QuerySortMap<Item> = {
|
|
11
|
+
name: 1,
|
|
12
|
+
measureUnit: { name: -1, category: { creator: { profile: { picture: 1 } } } },
|
|
13
|
+
};
|
|
14
|
+
expect(flatObject(sort)).toEqual<Record<string, number>>({
|
|
15
|
+
name: 1,
|
|
16
|
+
'measureUnit.name': -1,
|
|
17
|
+
'measureUnit.category.creator.profile.picture': 1,
|
|
18
|
+
});
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it('unflatObjects - empty', () => {
|
|
22
|
+
const res1 = unflatObjects(undefined);
|
|
23
|
+
expect(res1).toBe(undefined);
|
|
24
|
+
const res2 = unflatObjects([]);
|
|
25
|
+
expect(res2).toEqual([]);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it('unflatObjects', () => {
|
|
29
|
+
const source: Storehouse[] = [
|
|
30
|
+
{
|
|
31
|
+
id: 1,
|
|
32
|
+
name: 'Auxiliar',
|
|
33
|
+
address: null,
|
|
34
|
+
description: null,
|
|
35
|
+
createdAt: 1,
|
|
36
|
+
updatedAt: null,
|
|
37
|
+
creatorId: 1,
|
|
38
|
+
companyId: 1,
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
id: 2,
|
|
42
|
+
name: 'Principal',
|
|
43
|
+
address: null,
|
|
44
|
+
description: null,
|
|
45
|
+
createdAt: 1,
|
|
46
|
+
updatedAt: 1578759519913,
|
|
47
|
+
creatorId: 1,
|
|
48
|
+
companyId: 1,
|
|
49
|
+
},
|
|
50
|
+
];
|
|
51
|
+
const result = unflatObjects(source);
|
|
52
|
+
const expected: Storehouse[] = [
|
|
53
|
+
{
|
|
54
|
+
id: 1,
|
|
55
|
+
name: 'Auxiliar',
|
|
56
|
+
address: null,
|
|
57
|
+
description: null,
|
|
58
|
+
createdAt: 1,
|
|
59
|
+
updatedAt: null,
|
|
60
|
+
creatorId: 1,
|
|
61
|
+
companyId: 1,
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
id: 2,
|
|
65
|
+
name: 'Principal',
|
|
66
|
+
address: null,
|
|
67
|
+
description: null,
|
|
68
|
+
createdAt: 1,
|
|
69
|
+
updatedAt: 1578759519913,
|
|
70
|
+
creatorId: 1,
|
|
71
|
+
companyId: 1,
|
|
72
|
+
},
|
|
73
|
+
];
|
|
74
|
+
expect(result).toEqual(expected);
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
it('unflatObjects deep', () => {
|
|
78
|
+
const source = [
|
|
79
|
+
{
|
|
80
|
+
id: 9,
|
|
81
|
+
buyPrice: 1000,
|
|
82
|
+
number: 10,
|
|
83
|
+
'item.id': 1,
|
|
84
|
+
'item.name': 'Arepa de Yuca y Queso x 6',
|
|
85
|
+
'item.createdAt': 1,
|
|
86
|
+
'item.buyLedgerAccount': 1,
|
|
87
|
+
'item.saleLedgerAccount': 1,
|
|
88
|
+
'item.tax': 1,
|
|
89
|
+
'item.companyId': 1,
|
|
90
|
+
'item.measureUnit': 1,
|
|
91
|
+
'item.inventoryable': 1,
|
|
92
|
+
'item.buyLedgerAccount.id': 1,
|
|
93
|
+
'item.buyLedgerAccount.name': 'Ventas',
|
|
94
|
+
'item.saleLedgerAccount.id': 1,
|
|
95
|
+
'item.saleLedgerAccount.name': 'Ventas',
|
|
96
|
+
'item.tax.id': 1,
|
|
97
|
+
'item.tax.name': 'IVA 0%',
|
|
98
|
+
'item.tax.percentage': 0,
|
|
99
|
+
'item.tax.category.pk': '1',
|
|
100
|
+
'item.tax.category.name': 'Impuestos',
|
|
101
|
+
'item.tax.category.description': 'Nacionales',
|
|
102
|
+
'item.measureUnit.id': 1,
|
|
103
|
+
'item.measureUnit.name': 'Unidad',
|
|
104
|
+
'item.creatorId': null as string,
|
|
105
|
+
'item.creator.id': null as string,
|
|
106
|
+
'item.creator.name': null as string,
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
id: 15,
|
|
110
|
+
buyPrice: 2000,
|
|
111
|
+
number: 20,
|
|
112
|
+
'item.id': 2,
|
|
113
|
+
'item.name': 'Pony Malta 2 litros',
|
|
114
|
+
'item.createdAt': 1,
|
|
115
|
+
'item.companyId': 1,
|
|
116
|
+
'item.creatorId': 5,
|
|
117
|
+
'item.creator.id': 5,
|
|
118
|
+
'item.creator.name': 'Roshi Master',
|
|
119
|
+
},
|
|
120
|
+
];
|
|
121
|
+
const result = unflatObjects(source as Item[]);
|
|
122
|
+
const expected: ItemAdjustment[] = [
|
|
123
|
+
{
|
|
124
|
+
id: 9,
|
|
125
|
+
buyPrice: 1000,
|
|
126
|
+
number: 10,
|
|
127
|
+
item: {
|
|
128
|
+
id: 1,
|
|
129
|
+
name: 'Arepa de Yuca y Queso x 6',
|
|
130
|
+
createdAt: 1,
|
|
131
|
+
buyLedgerAccount: {
|
|
132
|
+
id: 1,
|
|
133
|
+
name: 'Ventas',
|
|
134
|
+
},
|
|
135
|
+
saleLedgerAccount: {
|
|
136
|
+
id: 1,
|
|
137
|
+
name: 'Ventas',
|
|
138
|
+
},
|
|
139
|
+
tax: {
|
|
140
|
+
id: 1,
|
|
141
|
+
name: 'IVA 0%',
|
|
142
|
+
percentage: 0,
|
|
143
|
+
category: {
|
|
144
|
+
pk: '1',
|
|
145
|
+
name: 'Impuestos',
|
|
146
|
+
description: 'Nacionales',
|
|
147
|
+
},
|
|
148
|
+
},
|
|
149
|
+
companyId: 1,
|
|
150
|
+
measureUnit: {
|
|
151
|
+
id: 1,
|
|
152
|
+
name: 'Unidad',
|
|
153
|
+
},
|
|
154
|
+
inventoryable: 1 as any as boolean,
|
|
155
|
+
},
|
|
156
|
+
},
|
|
157
|
+
{
|
|
158
|
+
id: 15,
|
|
159
|
+
buyPrice: 2000,
|
|
160
|
+
number: 20,
|
|
161
|
+
item: {
|
|
162
|
+
id: 2,
|
|
163
|
+
name: 'Pony Malta 2 litros',
|
|
164
|
+
createdAt: 1,
|
|
165
|
+
companyId: 1,
|
|
166
|
+
creatorId: 5,
|
|
167
|
+
creator: {
|
|
168
|
+
id: 5,
|
|
169
|
+
name: 'Roshi Master',
|
|
170
|
+
},
|
|
171
|
+
},
|
|
172
|
+
},
|
|
173
|
+
];
|
|
174
|
+
expect(result).toEqual(expected);
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
it('obtainAttrsPaths - empty', () => {
|
|
178
|
+
const res1 = obtainAttrsPaths(undefined);
|
|
179
|
+
expect(res1).toEqual({});
|
|
180
|
+
const res2 = obtainAttrsPaths({});
|
|
181
|
+
expect(res2).toEqual({});
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
it('obtainAttrsPaths - object', () => {
|
|
185
|
+
const res1 = obtainAttrsPaths({
|
|
186
|
+
'prop1.a.b': 1,
|
|
187
|
+
'prop2.c.d': 2,
|
|
188
|
+
});
|
|
189
|
+
console.log('***** res1', res1);
|
|
190
|
+
expect(res1).toEqual({
|
|
191
|
+
'prop1.a.b': ['prop1', 'a', 'b'],
|
|
192
|
+
'prop2.c.d': ['prop2', 'c', 'd'],
|
|
193
|
+
});
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
it('escapeSqlId', () => {
|
|
197
|
+
expect(escapeSqlId('table')).toBe('`table`');
|
|
198
|
+
expect(escapeSqlId('table', '"')).toBe('"table"');
|
|
199
|
+
expect(escapeSqlId('table', '`')).toBe('`table`');
|
|
200
|
+
expect(escapeSqlId('my"table', '"')).toBe('"my""table"');
|
|
201
|
+
expect(escapeSqlId('my`table', '`')).toBe('`my``table`');
|
|
202
|
+
expect(escapeSqlId('schema.table')).toBe('`schema`.`table`');
|
|
203
|
+
expect(escapeSqlId('schema.table', '"')).toBe('"schema"."table"');
|
|
204
|
+
expect(escapeSqlId('schema.table', '"', true)).toBe('"schema.table"');
|
|
205
|
+
expect(escapeSqlId('table', '`', false, true)).toBe('`table`.');
|
|
206
|
+
expect(escapeSqlId('')).toBe('');
|
|
207
|
+
expect(escapeSqlId(undefined)).toBe('');
|
|
208
|
+
});
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import type { FieldValue, Key } from '../type/index.js';
|
|
2
|
+
import { getKeys, hasKeys } from './object.util.js';
|
|
3
|
+
|
|
4
|
+
export function flatObject<E>(obj: E, pre?: string): E {
|
|
5
|
+
return getKeys(obj).reduce(
|
|
6
|
+
(acc, key) => flatObjectEntry(acc, key, obj[key as Key<E>], typeof obj[key as Key<E>] === 'object' ? '' : pre),
|
|
7
|
+
{} as E,
|
|
8
|
+
);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
function flatObjectEntry<E>(map: E, key: string, val: any, pre?: string): E {
|
|
12
|
+
const prefix = pre ? `${pre}.${key}` : key;
|
|
13
|
+
return typeof val === 'object'
|
|
14
|
+
? getKeys(val).reduce((acc, prop) => flatObjectEntry(acc, prop, val[prop], prefix), map)
|
|
15
|
+
: { ...map, [prefix]: val };
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function unflatObjects<T>(objects: T[]): T[] {
|
|
19
|
+
if (!Array.isArray(objects) || !objects.length) {
|
|
20
|
+
return objects;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const attrsPaths = obtainAttrsPaths(objects[0]);
|
|
24
|
+
|
|
25
|
+
if (!hasKeys(attrsPaths)) {
|
|
26
|
+
return objects;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return objects.map((row) => {
|
|
30
|
+
const dto = {} as T;
|
|
31
|
+
|
|
32
|
+
for (const col in row) {
|
|
33
|
+
if (row[col] === null) {
|
|
34
|
+
continue;
|
|
35
|
+
}
|
|
36
|
+
const attrPath = attrsPaths[col];
|
|
37
|
+
if (attrPath) {
|
|
38
|
+
const target = attrPath.slice(0, -1).reduce(
|
|
39
|
+
(acc, key) => {
|
|
40
|
+
if (typeof acc[key as Key<T>] !== 'object') {
|
|
41
|
+
acc[key as Key<T>] = {} as FieldValue<T>;
|
|
42
|
+
}
|
|
43
|
+
return acc[key as Key<T>];
|
|
44
|
+
},
|
|
45
|
+
dto as Record<string, any>,
|
|
46
|
+
);
|
|
47
|
+
target[attrPath[attrPath.length - 1]] = row[col];
|
|
48
|
+
} else {
|
|
49
|
+
dto[col] = row[col];
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return dto;
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export function obtainAttrsPaths<T>(row: T) {
|
|
58
|
+
return getKeys(row).reduce(
|
|
59
|
+
(acc, col) => {
|
|
60
|
+
// Support both dot notation (legacy) and underscore notation (new)
|
|
61
|
+
if (col.includes('.')) {
|
|
62
|
+
acc[col] = col.split('.');
|
|
63
|
+
} else if (col.includes('_') && col !== col.toUpperCase()) {
|
|
64
|
+
// Convert underscore to dot notation for nested paths
|
|
65
|
+
// Skip all-uppercase (like UPPER_CASE constants)
|
|
66
|
+
acc[col] = col.split('_');
|
|
67
|
+
}
|
|
68
|
+
return acc;
|
|
69
|
+
},
|
|
70
|
+
{} as { [k: string]: string[] },
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Escape a SQL identifier (table name, column name, etc.)
|
|
76
|
+
* @param val the identifier to escape
|
|
77
|
+
* @param escapeIdChar the escape character to use (e.g. ` or ")
|
|
78
|
+
* @param forbidQualified whether to forbid qualified identifiers (containing dots)
|
|
79
|
+
* @param addDot whether to add a dot suffix
|
|
80
|
+
*/
|
|
81
|
+
export function escapeSqlId(
|
|
82
|
+
val: string,
|
|
83
|
+
escapeIdChar: '`' | '"' = '`',
|
|
84
|
+
forbidQualified?: boolean,
|
|
85
|
+
addDot?: boolean,
|
|
86
|
+
): string {
|
|
87
|
+
if (!val) {
|
|
88
|
+
return '';
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
if (!forbidQualified && val.includes('.')) {
|
|
92
|
+
const result = val
|
|
93
|
+
.split('.')
|
|
94
|
+
.map((it) => escapeSqlId(it, escapeIdChar, true))
|
|
95
|
+
.join('.');
|
|
96
|
+
return addDot ? result + '.' : result;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
const escaped = escapeIdChar + val.replace(new RegExp(escapeIdChar, 'g'), escapeIdChar + escapeIdChar) + escapeIdChar;
|
|
100
|
+
|
|
101
|
+
const suffix = addDot ? '.' : '';
|
|
102
|
+
|
|
103
|
+
return escaped + suffix;
|
|
104
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { expect, it } from 'bun:test';
|
|
2
|
+
import { kebabCase, lowerFirst, snakeCase, upperFirst } from './string.util.js';
|
|
3
|
+
|
|
4
|
+
it('kebabCase', () => {
|
|
5
|
+
const res1 = kebabCase('SomeWordsAndMore');
|
|
6
|
+
expect(res1).toBe('some-words-and-more');
|
|
7
|
+
const res2 = kebabCase('someWordsAndMore');
|
|
8
|
+
expect(res2).toBe('some-words-and-more');
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
it('upperFirst', () => {
|
|
12
|
+
const res1 = upperFirst('id');
|
|
13
|
+
expect(res1).toBe('Id');
|
|
14
|
+
const res2 = upperFirst('Id');
|
|
15
|
+
expect(res2).toBe('Id');
|
|
16
|
+
const res3 = upperFirst('idSomething');
|
|
17
|
+
expect(res3).toBe('IdSomething');
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
it('lowerFirst', () => {
|
|
21
|
+
const res1 = lowerFirst('id');
|
|
22
|
+
expect(res1).toBe('id');
|
|
23
|
+
const res2 = lowerFirst('Id');
|
|
24
|
+
expect(res2).toBe('id');
|
|
25
|
+
const res3 = lowerFirst('IdSomething');
|
|
26
|
+
expect(res3).toBe('idSomething');
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it('snakeCase', () => {
|
|
30
|
+
const res1 = snakeCase('SomeWordsAndMore');
|
|
31
|
+
expect(res1).toBe('some_words_and_more');
|
|
32
|
+
const res2 = snakeCase('someWordsAndMore');
|
|
33
|
+
expect(res2).toBe('some_words_and_more');
|
|
34
|
+
const res3 = snakeCase('simple');
|
|
35
|
+
expect(res3).toBe('simple');
|
|
36
|
+
const res4 = snakeCase('ID');
|
|
37
|
+
expect(res4).toBe('i_d');
|
|
38
|
+
const res5 = snakeCase('already_snake');
|
|
39
|
+
expect(res5).toBe('already_snake');
|
|
40
|
+
const res6 = snakeCase('');
|
|
41
|
+
expect(res6).toBe('');
|
|
42
|
+
const res7 = snakeCase(undefined);
|
|
43
|
+
expect(res7).toBe(undefined);
|
|
44
|
+
const res8 = snakeCase(null);
|
|
45
|
+
expect(res8).toBe(null);
|
|
46
|
+
});
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export function kebabCase(val: string): string {
|
|
2
|
+
let resp = val.charAt(0).toLowerCase();
|
|
3
|
+
for (let i = 1; i < val.length; ++i) {
|
|
4
|
+
resp += val[i] === val[i].toUpperCase() ? '-' + val[i].toLowerCase() : val[i];
|
|
5
|
+
}
|
|
6
|
+
return resp;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export function upperFirst(text: string): string {
|
|
10
|
+
return text[0].toUpperCase() + text.slice(1);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function lowerFirst(text: string): string {
|
|
14
|
+
return text[0].toLowerCase() + text.slice(1);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function snakeCase(val: string): string {
|
|
18
|
+
if (val === undefined || val === null) {
|
|
19
|
+
return val;
|
|
20
|
+
}
|
|
21
|
+
if (!val) {
|
|
22
|
+
return '';
|
|
23
|
+
}
|
|
24
|
+
let resp = val.charAt(0).toLowerCase();
|
|
25
|
+
for (let i = 1; i < val.length; ++i) {
|
|
26
|
+
const char = val[i];
|
|
27
|
+
const charLower = char.toLowerCase();
|
|
28
|
+
if (char !== charLower && char === char.toUpperCase()) {
|
|
29
|
+
resp += '_' + charLower;
|
|
30
|
+
} else {
|
|
31
|
+
resp += char;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return resp;
|
|
35
|
+
}
|
package/tsconfig.json
ADDED
package/README.md
DELETED
|
@@ -1,177 +0,0 @@
|
|
|
1
|
-
# [uql](https://nukak.org) · [](https://github.com/rogerpadilla/uql/blob/main/LICENSE) [](https://github.com/rogerpadilla/uql) [](https://coveralls.io/r/rogerpadilla/uql?branch=main) [](https://badge.fury.io/js/%40uql%2Fcore)
|
|
2
|
-
|
|
3
|
-
## Quick Start
|
|
4
|
-
|
|
5
|
-
`uql` is a flexible and efficient `ORM`, with declarative `JSON` syntax and really smart type-safety.
|
|
6
|
-
|
|
7
|
-
The `uql` queries can be safely written in the frontend (browser/mobile) and sent to the backend; or only use `uql` in the backend, or even in a mobile app with an embedded database (like `sqlite`).
|
|
8
|
-
|
|
9
|
-
### <a name="features"></a> Features
|
|
10
|
-
|
|
11
|
-
- `JSON` (serializable) syntax for all the [queries](https://nukak.org/docs/querying-logical-operators).
|
|
12
|
-
- uses the power of `TypeScript` to get smart type-safety [everywhere](https://nukak.org/docs/api-repository).
|
|
13
|
-
- the generated queries are [performant](https://nukak.org/docs/querying-retrieve-relations), safe, and human-readable.
|
|
14
|
-
- `$project`, `$filter`, `$sort`, `$limit` works at [multiple levels](https://nukak.org/docs/querying-retrieve-relations) (including deep relations and their fields).
|
|
15
|
-
- [declarative](https://nukak.org/docs/transactions-declarative) and [imperative](https://nukak.org/docs/transactions-imperative) `transactions`.
|
|
16
|
-
- [soft-delete](https://nukak.org/docs/entities-soft-delete), [virtual fields](https://nukak.org/docs/entities-virtual-fields), [repositories](https://nukak.org/docs/api-repository), `connection pooling`.
|
|
17
|
-
- transparent support for [inheritance](https://nukak.org/docs/entities-advanced) between entities.
|
|
18
|
-
- supports `Postgres`, `MySQL`, `MariaDB`, `SQLite`, `MongoDB`.
|
|
19
|
-
|
|
20
|
-
### <a name="installation"></a> Installation
|
|
21
|
-
|
|
22
|
-
1. Install the core package:
|
|
23
|
-
|
|
24
|
-
```sh
|
|
25
|
-
npm install @uql/core --save
|
|
26
|
-
```
|
|
27
|
-
|
|
28
|
-
or
|
|
29
|
-
|
|
30
|
-
```sh
|
|
31
|
-
yarn add @uql/core
|
|
32
|
-
```
|
|
33
|
-
|
|
34
|
-
2. Install one of the specific packages according to your database:
|
|
35
|
-
|
|
36
|
-
| Database | Package |
|
|
37
|
-
| ------------ | --------------- |
|
|
38
|
-
| `MySQL` | `@uql/mysql` |
|
|
39
|
-
| `PostgreSQL` | `@uql/postgres` |
|
|
40
|
-
| `MariaDB` | `@uql/maria` |
|
|
41
|
-
| `MongoDB` | `@uql/mongo` |
|
|
42
|
-
| `SQLite` | `@uql/sqlite` |
|
|
43
|
-
|
|
44
|
-
E.g. for `PostgreSQL`
|
|
45
|
-
|
|
46
|
-
```sh
|
|
47
|
-
npm install @uql/postgres --save
|
|
48
|
-
```
|
|
49
|
-
|
|
50
|
-
or with _yarn_
|
|
51
|
-
|
|
52
|
-
```sh
|
|
53
|
-
yarn add @uql/postgres
|
|
54
|
-
```
|
|
55
|
-
|
|
56
|
-
3. Additionally, your `tsconfig.json` may need the following flags:
|
|
57
|
-
|
|
58
|
-
```json
|
|
59
|
-
"target": "es2020",
|
|
60
|
-
"experimentalDecorators": true,
|
|
61
|
-
"emitDecoratorMetadata": true
|
|
62
|
-
```
|
|
63
|
-
|
|
64
|
-
### <a name="configuration"></a> Configuration
|
|
65
|
-
|
|
66
|
-
A default querier-pool can be set in any of the bootstrap files of your app (e.g. in the `server.ts`).
|
|
67
|
-
|
|
68
|
-
```ts
|
|
69
|
-
import { setQuerierPool } from '@uql/core';
|
|
70
|
-
import { PgQuerierPool } from '@uql/postgres';
|
|
71
|
-
|
|
72
|
-
const querierPool = new PgQuerierPool(
|
|
73
|
-
{
|
|
74
|
-
host: 'localhost',
|
|
75
|
-
user: 'theUser',
|
|
76
|
-
password: 'thePassword',
|
|
77
|
-
database: 'theDatabase',
|
|
78
|
-
},
|
|
79
|
-
// a logger can optionally be passed so the SQL queries are logged
|
|
80
|
-
console.log
|
|
81
|
-
);
|
|
82
|
-
|
|
83
|
-
setQuerierPool(querierPool);
|
|
84
|
-
```
|
|
85
|
-
|
|
86
|
-
### <a name="definition-of-entities"></a> Definition of Entities
|
|
87
|
-
|
|
88
|
-
Take any dump class (aka DTO) and annotate it with the decorators from `'@uql/core/entity'`.
|
|
89
|
-
|
|
90
|
-
```ts
|
|
91
|
-
import { v4 as uuidv4 } from 'uuid';
|
|
92
|
-
import { Field, ManyToOne, Id, OneToMany, Entity, OneToOne, ManyToMany } from '@uql/core/entity';
|
|
93
|
-
|
|
94
|
-
@Entity()
|
|
95
|
-
export class Profile {
|
|
96
|
-
/**
|
|
97
|
-
* primary-key.
|
|
98
|
-
* the `onInsert` callback can be used to specify a custom mechanism for auto-generating
|
|
99
|
-
* the default value of a field when inserting a new record.
|
|
100
|
-
*/
|
|
101
|
-
@Id({ onInsert: uuidv4 })
|
|
102
|
-
id?: string;
|
|
103
|
-
@Field()
|
|
104
|
-
picture?: string;
|
|
105
|
-
/**
|
|
106
|
-
* foreign-keys are really simple to specify.
|
|
107
|
-
*/
|
|
108
|
-
@Field({ reference: () => User })
|
|
109
|
-
creatorId?: string;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
@Entity()
|
|
113
|
-
export class User {
|
|
114
|
-
@Id({ onInsert: uuidv4 })
|
|
115
|
-
id?: string;
|
|
116
|
-
@Field()
|
|
117
|
-
name?: string;
|
|
118
|
-
@Field()
|
|
119
|
-
email?: string;
|
|
120
|
-
@Field()
|
|
121
|
-
password?: string;
|
|
122
|
-
/**
|
|
123
|
-
* `mappedBy` can be a callback or a string (callback is useful for auto-refactoring).
|
|
124
|
-
*/
|
|
125
|
-
@OneToOne({ entity: () => Profile, mappedBy: (profile) => profile.creatorId, cascade: true })
|
|
126
|
-
profile?: Profile;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
@Entity()
|
|
130
|
-
export class MeasureUnitCategory {
|
|
131
|
-
@Id({ onInsert: uuidv4 })
|
|
132
|
-
id?: string;
|
|
133
|
-
@Field()
|
|
134
|
-
name?: string;
|
|
135
|
-
@OneToMany({ entity: () => MeasureUnit, mappedBy: (measureUnit) => measureUnit.category })
|
|
136
|
-
measureUnits?: MeasureUnit[];
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
@Entity()
|
|
140
|
-
export class MeasureUnit {
|
|
141
|
-
@Id({ onInsert: uuidv4 })
|
|
142
|
-
id?: string;
|
|
143
|
-
@Field()
|
|
144
|
-
name?: string;
|
|
145
|
-
@Field({ reference: () => MeasureUnitCategory })
|
|
146
|
-
categoryId?: string;
|
|
147
|
-
@ManyToOne({ cascade: 'persist' })
|
|
148
|
-
category?: MeasureUnitCategory;
|
|
149
|
-
}
|
|
150
|
-
```
|
|
151
|
-
|
|
152
|
-
### <a name="query-data"></a> Query the data
|
|
153
|
-
|
|
154
|
-
```ts
|
|
155
|
-
import { getQuerier } from '@uql/core';
|
|
156
|
-
import { User } from './entity';
|
|
157
|
-
|
|
158
|
-
const querier = await getQuerier();
|
|
159
|
-
|
|
160
|
-
const id = await this.querier.insertOne(User, {
|
|
161
|
-
email: 'lorem@example.com',
|
|
162
|
-
profile: { picture: 'ipsum.jpg' },
|
|
163
|
-
});
|
|
164
|
-
|
|
165
|
-
const users = await querier.findMany(User, {
|
|
166
|
-
$project: { id: true, email: true, profile: ['picture'] },
|
|
167
|
-
$filter: { email: { $iendsWith: '@google.com' } },
|
|
168
|
-
$sort: { createdAt: -1 },
|
|
169
|
-
$limit: 100,
|
|
170
|
-
});
|
|
171
|
-
|
|
172
|
-
await querier.release();
|
|
173
|
-
```
|
|
174
|
-
|
|
175
|
-
---
|
|
176
|
-
|
|
177
|
-
See more in https://nukak.org :high_brightness:
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { QueryFilter, Query, Scalar, QueryFilterFieldOperatorMap, QuerySort, QueryPager, FieldKey, QueryProject, Type, QueryCriteria, QueryOptions, QueryDialect, QueryFilterOptions, QueryComparisonOptions, QueryFilterMap, QuerySearch, QueryProjectOptions } from '../type';
|
|
2
|
-
export declare abstract class AbstractSqlDialect implements QueryDialect {
|
|
3
|
-
readonly escapeIdChar: '`' | '"';
|
|
4
|
-
readonly beginTransactionCommand: string;
|
|
5
|
-
readonly escapeIdRegex: RegExp;
|
|
6
|
-
constructor(escapeIdChar: '`' | '"', beginTransactionCommand: string);
|
|
7
|
-
criteria<E>(entity: Type<E>, qm: Query<E>, opts?: QueryOptions): string;
|
|
8
|
-
projectFields<E>(entity: Type<E>, project: QueryProject<E>, opts?: QueryProjectOptions): string;
|
|
9
|
-
projectRelations<E>(entity: Type<E>, project?: QueryProject<E>, { prefix }?: {
|
|
10
|
-
prefix?: string;
|
|
11
|
-
}): {
|
|
12
|
-
fields: string;
|
|
13
|
-
tables: string;
|
|
14
|
-
};
|
|
15
|
-
select<E>(entity: Type<E>, qm: Query<E>, opts?: QueryOptions): string;
|
|
16
|
-
where<E>(entity: Type<E>, filter?: QueryFilter<E>, opts?: QueryFilterOptions): string;
|
|
17
|
-
compare<E, K extends keyof QueryFilterMap<E>>(entity: Type<E>, key: K, val: QueryFilterMap<E>[K], opts?: QueryComparisonOptions): string;
|
|
18
|
-
compareFieldOperator<E, K extends keyof QueryFilterFieldOperatorMap<E>>(entity: Type<E>, key: FieldKey<E>, op: K, val: QueryFilterFieldOperatorMap<E>[K], opts?: QueryOptions): string;
|
|
19
|
-
getComparisonKey<E>(entity: Type<E>, key: FieldKey<E>, { prefix }?: QueryOptions): Scalar;
|
|
20
|
-
group<E>(entity: Type<E>, fields: readonly FieldKey<E>[], opts?: QueryOptions): string;
|
|
21
|
-
sort<E>(entity: Type<E>, sort: QuerySort<E>, { prefix }?: QueryOptions): string;
|
|
22
|
-
pager(opts: QueryPager): string;
|
|
23
|
-
count<E>(entity: Type<E>, qm: QuerySearch<E>, opts?: QueryOptions): string;
|
|
24
|
-
find<E>(entity: Type<E>, qm: Query<E>, opts?: QueryOptions): string;
|
|
25
|
-
insert<E>(entity: Type<E>, payload: E | E[]): string;
|
|
26
|
-
update<E>(entity: Type<E>, qm: QueryCriteria<E>, payload: E, opts?: QueryOptions): string;
|
|
27
|
-
delete<E>(entity: Type<E>, qm: QueryCriteria<E>, opts?: QueryOptions): string;
|
|
28
|
-
escapeId(val: string, forbidQualified?: boolean, addDot?: boolean): string;
|
|
29
|
-
escape(value: any): Scalar;
|
|
30
|
-
}
|