fib-orm 1.4.2 → 2.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/License +1 -1
- package/README.md +53 -0
- package/lib/cli/commands/ddlFrom.d.ts +2 -0
- package/lib/cli/commands/ddlFrom.js +75 -0
- package/lib/cli/commands/dumpModel.d.ts +2 -0
- package/lib/cli/commands/dumpModel.js +107 -0
- package/lib/cli/commands/escape.d.ts +2 -0
- package/lib/cli/commands/escape.js +69 -0
- package/lib/cli/commands/spinner.d.ts +2 -0
- package/lib/cli/commands/spinner.js +37 -0
- package/lib/cli/commands/upgrade.d.ts +2 -0
- package/lib/cli/commands/upgrade.js +66 -0
- package/lib/cli/helpers/ddl.d.ts +17 -0
- package/lib/cli/helpers/ddl.js +55 -0
- package/lib/cli/helpers/package.d.ts +25 -0
- package/lib/cli/helpers/package.js +56 -0
- package/lib/cli/index.d.ts +2 -0
- package/lib/cli/index.js +19 -0
- package/lib/codepoints-map.json +762 -0
- package/lib/db-driver/Typo.d.ts +111 -0
- package/lib/db-driver/Typo.js +2 -0
- package/lib/db-driver/built-ins/base.class.d.ts +91 -0
- package/lib/db-driver/built-ins/base.class.js +187 -0
- package/lib/db-driver/built-ins/driver-dm.d.ts +17 -0
- package/lib/db-driver/built-ins/driver-dm.js +54 -0
- package/lib/db-driver/built-ins/driver-mongodb.d.ts +23 -0
- package/lib/db-driver/built-ins/driver-mongodb.js +47 -0
- package/lib/db-driver/built-ins/driver-mysql.d.ts +17 -0
- package/lib/db-driver/built-ins/driver-mysql.js +38 -0
- package/lib/db-driver/built-ins/driver-postgresql.d.ts +21 -0
- package/lib/db-driver/built-ins/driver-postgresql.js +77 -0
- package/lib/db-driver/built-ins/driver-redis.d.ts +11 -0
- package/lib/db-driver/built-ins/driver-redis.js +36 -0
- package/lib/db-driver/built-ins/driver-sqlite.d.ts +16 -0
- package/lib/db-driver/built-ins/driver-sqlite.js +35 -0
- package/lib/db-driver/index.d.ts +3 -0
- package/lib/db-driver/index.js +5 -0
- package/lib/db-driver/utils.d.ts +14 -0
- package/lib/db-driver/utils.js +187 -0
- package/lib/knex/deps/tarn/dist/PendingOperation.d.ts +12 -0
- package/lib/knex/deps/tarn/dist/PendingOperation.js +48 -0
- package/lib/knex/deps/tarn/dist/Pool.d.ts +97 -0
- package/lib/knex/deps/tarn/dist/Pool.js +516 -0
- package/lib/knex/deps/tarn/dist/PromiseInspection.d.ts +16 -0
- package/lib/knex/deps/tarn/dist/PromiseInspection.js +21 -0
- package/lib/knex/deps/tarn/dist/Resource.d.ts +9 -0
- package/lib/knex/deps/tarn/dist/Resource.js +19 -0
- package/lib/knex/deps/tarn/dist/TimeoutError.d.ts +2 -0
- package/lib/knex/deps/tarn/dist/TimeoutError.js +5 -0
- package/lib/knex/deps/tarn/dist/tarn.d.ts +3 -0
- package/lib/knex/deps/tarn/dist/tarn.js +10 -0
- package/lib/knex/deps/tarn/dist/utils.d.ts +14 -0
- package/lib/knex/deps/tarn/dist/utils.js +60 -0
- package/lib/knex/knex.d.ts +2 -0
- package/lib/knex/knex.js +4 -0
- package/lib/knex/sandbox.d.ts +4 -0
- package/lib/knex/sandbox.js +23 -0
- package/lib/orm/Adapters.d.ts +3 -0
- package/lib/orm/Adapters.js +44 -0
- package/lib/orm/AggregateFunctions.d.ts +3 -0
- package/lib/orm/AggregateFunctions.js +177 -0
- package/lib/orm/Associations/Extend.d.ts +22 -0
- package/lib/orm/Associations/Extend.js +274 -0
- package/lib/orm/Associations/Many.d.ts +16 -0
- package/lib/orm/Associations/Many.js +569 -0
- package/lib/orm/Associations/One.d.ts +16 -0
- package/lib/orm/Associations/One.js +310 -0
- package/lib/orm/Associations/_utils.d.ts +14 -0
- package/lib/orm/Associations/_utils.js +53 -0
- package/lib/orm/ChainFind.d.ts +3 -0
- package/lib/orm/ChainFind.js +328 -0
- package/lib/orm/ChainInstance.d.ts +6 -0
- package/lib/orm/ChainInstance.js +74 -0
- package/lib/orm/Debug.d.ts +2 -0
- package/lib/orm/Debug.js +17 -0
- package/lib/orm/Drivers/DB/base.d.ts +2 -0
- package/lib/orm/Drivers/DB/base.js +4 -0
- package/lib/orm/Drivers/DB/dm.d.ts +9 -0
- package/lib/orm/Drivers/DB/dm.js +24 -0
- package/lib/orm/Drivers/DB/mysql.d.ts +9 -0
- package/lib/orm/Drivers/DB/mysql.js +24 -0
- package/lib/orm/Drivers/DB/postgres.d.ts +9 -0
- package/lib/orm/Drivers/DB/postgres.js +23 -0
- package/lib/orm/Drivers/DB/sqlite3.d.ts +14 -0
- package/lib/orm/Drivers/DB/sqlite3.js +40 -0
- package/lib/orm/Drivers/DML/_ddl-sql.d.ts +3 -0
- package/lib/orm/Drivers/DML/_ddl-sql.js +52 -0
- package/lib/orm/Drivers/DML/_dml-helpers.d.ts +19 -0
- package/lib/orm/Drivers/DML/_dml-helpers.js +51 -0
- package/lib/orm/Drivers/DML/_shared.d.ts +9 -0
- package/lib/orm/Drivers/DML/_shared.js +39 -0
- package/lib/orm/Drivers/DML/_utils.d.ts +8 -0
- package/lib/orm/Drivers/DML/_utils.js +67 -0
- package/lib/orm/Drivers/DML/constants.d.ts +3 -0
- package/lib/orm/Drivers/DML/constants.js +3 -0
- package/lib/orm/Drivers/DML/dm.d.ts +2 -0
- package/lib/orm/Drivers/DML/dm.js +294 -0
- package/lib/orm/Drivers/DML/index.d.ts +4 -0
- package/lib/orm/Drivers/DML/index.js +7 -0
- package/lib/orm/Drivers/DML/mysql.d.ts +2 -0
- package/lib/orm/Drivers/DML/mysql.js +252 -0
- package/lib/orm/Drivers/DML/postgres.d.ts +2 -0
- package/lib/orm/Drivers/DML/postgres.js +277 -0
- package/lib/orm/Drivers/DML/sqlite.d.ts +2 -0
- package/lib/orm/Drivers/DML/sqlite.js +267 -0
- package/lib/orm/Error.d.ts +11 -0
- package/lib/orm/Error.js +41 -0
- package/lib/orm/Helpers.d.ts +35 -0
- package/lib/orm/Helpers.js +234 -0
- package/lib/orm/Hook.d.ts +13 -0
- package/lib/orm/Hook.js +100 -0
- package/lib/orm/Instance.d.ts +2 -0
- package/lib/orm/Instance.js +698 -0
- package/lib/orm/LazyLoad.d.ts +4 -0
- package/lib/orm/LazyLoad.js +76 -0
- package/lib/orm/Model.d.ts +6 -0
- package/lib/orm/Model.js +974 -0
- package/lib/orm/ORM.d.ts +37 -0
- package/lib/orm/ORM.js +242 -0
- package/lib/orm/Patch/fib-cache.d.ts +39 -0
- package/lib/orm/Patch/fib-cache.js +2 -0
- package/lib/orm/Patch/plugin.d.ts +4 -0
- package/lib/orm/Patch/plugin.js +14 -0
- package/lib/orm/Property.d.ts +9 -0
- package/lib/orm/Property.js +71 -0
- package/lib/orm/Settings.d.ts +42 -0
- package/lib/orm/Settings.js +120 -0
- package/lib/orm/Singleton.d.ts +5 -0
- package/lib/orm/Singleton.js +73 -0
- package/lib/orm/Typo/Adapter.d.ts +5 -0
- package/lib/orm/Typo/Adapter.js +2 -0
- package/lib/orm/Typo/DMLDriver.d.ts +209 -0
- package/lib/orm/Typo/DMLDriver.js +2 -0
- package/lib/orm/Typo/Db.d.ts +35 -0
- package/lib/orm/Typo/Db.js +2 -0
- package/lib/orm/Typo/Error.d.ts +29 -0
- package/lib/orm/Typo/Error.js +2 -0
- package/lib/orm/Typo/ORM.d.ts +231 -0
- package/lib/orm/Typo/ORM.js +4 -0
- package/lib/orm/Typo/Validators.d.ts +31 -0
- package/lib/orm/Typo/Validators.js +3 -0
- package/lib/orm/Typo/_common.d.ts +37 -0
- package/lib/orm/Typo/_common.js +2 -0
- package/lib/orm/Typo/assoc.d.ts +221 -0
- package/lib/orm/Typo/assoc.js +2 -0
- package/lib/orm/Typo/hook.d.ts +42 -0
- package/lib/orm/Typo/hook.js +2 -0
- package/lib/orm/Typo/instance.d.ts +156 -0
- package/lib/orm/Typo/instance.js +2 -0
- package/lib/orm/Typo/model.d.ts +311 -0
- package/lib/orm/Typo/model.js +7 -0
- package/lib/orm/Typo/patch.d.ts +31 -0
- package/lib/orm/Typo/patch.js +2 -0
- package/lib/orm/Typo/property.d.ts +57 -0
- package/lib/orm/Typo/property.js +2 -0
- package/lib/orm/Typo/query.d.ts +216 -0
- package/lib/orm/Typo/query.js +2 -0
- package/lib/orm/Typo/settings.d.ts +35 -0
- package/lib/orm/Typo/settings.js +6 -0
- package/lib/orm/Typo/synchronous.d.ts +47 -0
- package/lib/orm/Typo/synchronous.js +2 -0
- package/lib/orm/Utilities.d.ts +178 -0
- package/lib/orm/Utilities.js +975 -0
- package/lib/orm/Validators.d.ts +33 -0
- package/lib/orm/Validators.js +101 -0
- package/lib/orm/Where/common.d.ts +1 -0
- package/lib/orm/Where/common.js +7 -0
- package/lib/orm/Where/filterDate.d.ts +11 -0
- package/lib/orm/Where/filterDate.js +58 -0
- package/lib/orm/index.d.ts +67 -0
- package/lib/orm/index.js +158 -0
- package/lib/orm-core/callback.d.ts +12 -0
- package/lib/orm-core/callback.js +2 -0
- package/lib/orm-core/dialect.d.ts +80 -0
- package/lib/orm-core/dialect.js +2 -0
- package/lib/orm-core/error.d.ts +16 -0
- package/lib/orm-core/error.js +29 -0
- package/lib/orm-core/index.d.ts +6 -0
- package/lib/orm-core/index.js +7 -0
- package/lib/orm-core/sync.d.ts +12 -0
- package/lib/orm-core/sync.js +2 -0
- package/lib/orm-core/utils.d.ts +1 -0
- package/lib/orm-core/utils.js +6 -0
- package/lib/orm-property/Property.d.ts +78 -0
- package/lib/orm-property/Property.js +2 -0
- package/lib/orm-property/Utils.d.ts +9 -0
- package/lib/orm-property/Utils.js +13 -0
- package/lib/orm-property/customTypes.d.ts +2 -0
- package/lib/orm-property/customTypes.js +13 -0
- package/lib/orm-property/index.d.ts +10 -0
- package/lib/orm-property/index.js +23 -0
- package/lib/orm-property/transformer.d.ts +5 -0
- package/lib/orm-property/transformer.js +10 -0
- package/lib/orm-property/transformers/dm.d.ts +29 -0
- package/lib/orm-property/transformers/dm.js +238 -0
- package/lib/orm-property/transformers/index.d.ts +4 -0
- package/lib/orm-property/transformers/index.js +6 -0
- package/lib/orm-property/transformers/mysql.d.ts +101 -0
- package/lib/orm-property/transformers/mysql.js +262 -0
- package/lib/orm-property/transformers/postgresql.d.ts +54 -0
- package/lib/orm-property/transformers/postgresql.js +190 -0
- package/lib/orm-property/transformers/sqlite.d.ts +19 -0
- package/lib/orm-property/transformers/sqlite.js +172 -0
- package/lib/sql-ddl-sync/Dialects/dm.d.ts +39 -0
- package/lib/sql-ddl-sync/Dialects/dm.js +297 -0
- package/lib/sql-ddl-sync/Dialects/index.d.ts +6 -0
- package/lib/sql-ddl-sync/Dialects/index.js +8 -0
- package/lib/sql-ddl-sync/Dialects/mysql.d.ts +38 -0
- package/lib/sql-ddl-sync/Dialects/mysql.js +241 -0
- package/lib/sql-ddl-sync/Dialects/postgresql.d.ts +39 -0
- package/lib/sql-ddl-sync/Dialects/postgresql.js +287 -0
- package/lib/sql-ddl-sync/Dialects/sqlite.d.ts +43 -0
- package/lib/sql-ddl-sync/Dialects/sqlite.js +257 -0
- package/lib/sql-ddl-sync/SQL.d.ts +12 -0
- package/lib/sql-ddl-sync/SQL.js +108 -0
- package/lib/sql-ddl-sync/Typo/Collection.d.ts +13 -0
- package/lib/sql-ddl-sync/Typo/Collection.js +2 -0
- package/lib/sql-ddl-sync/Typo/DbIndex.d.ts +13 -0
- package/lib/sql-ddl-sync/Typo/DbIndex.js +2 -0
- package/lib/sql-ddl-sync/Typo/Dialect.d.ts +81 -0
- package/lib/sql-ddl-sync/Typo/Dialect.js +2 -0
- package/lib/sql-ddl-sync/Typo/Driver.d.ts +53 -0
- package/lib/sql-ddl-sync/Typo/Driver.js +2 -0
- package/lib/sql-ddl-sync/Typo/Query.d.ts +7 -0
- package/lib/sql-ddl-sync/Typo/Query.js +2 -0
- package/lib/sql-ddl-sync/Typo/SQL.d.ts +31 -0
- package/lib/sql-ddl-sync/Typo/SQL.js +2 -0
- package/lib/sql-ddl-sync/Typo/_common.d.ts +29 -0
- package/lib/sql-ddl-sync/Typo/_common.js +2 -0
- package/lib/sql-ddl-sync/Utils.d.ts +39 -0
- package/lib/sql-ddl-sync/Utils.js +217 -0
- package/lib/sql-ddl-sync/index.d.ts +87 -0
- package/lib/sql-ddl-sync/index.js +372 -0
- package/lib/sql-query/Comparators.d.ts +3 -0
- package/lib/sql-query/Comparators.js +95 -0
- package/lib/sql-query/Create.d.ts +35 -0
- package/lib/sql-query/Create.js +78 -0
- package/lib/sql-query/Dialects/dm.d.ts +3 -0
- package/lib/sql-query/Dialects/dm.js +75 -0
- package/lib/sql-query/Dialects/index.d.ts +10 -0
- package/lib/sql-query/Dialects/index.js +13 -0
- package/lib/sql-query/Dialects/mssql.d.ts +3 -0
- package/lib/sql-query/Dialects/mssql.js +74 -0
- package/lib/sql-query/Dialects/mysql.d.ts +3 -0
- package/lib/sql-query/Dialects/mysql.js +101 -0
- package/lib/sql-query/Dialects/postgresql.d.ts +3 -0
- package/lib/sql-query/Dialects/postgresql.js +77 -0
- package/lib/sql-query/Dialects/sqlite.d.ts +3 -0
- package/lib/sql-query/Dialects/sqlite.js +62 -0
- package/lib/sql-query/Helpers.d.ts +37 -0
- package/lib/sql-query/Helpers.js +260 -0
- package/lib/sql-query/Insert.d.ts +12 -0
- package/lib/sql-query/Insert.js +34 -0
- package/lib/sql-query/Query.d.ts +28 -0
- package/lib/sql-query/Query.js +120 -0
- package/lib/sql-query/Remove.d.ts +16 -0
- package/lib/sql-query/Remove.js +94 -0
- package/lib/sql-query/Select.d.ts +62 -0
- package/lib/sql-query/Select.js +534 -0
- package/lib/sql-query/Set.d.ts +4 -0
- package/lib/sql-query/Set.js +16 -0
- package/lib/sql-query/Typo/Aggregation.d.ts +32 -0
- package/lib/sql-query/Typo/Aggregation.js +2 -0
- package/lib/sql-query/Typo/Comparators.d.ts +140 -0
- package/lib/sql-query/Typo/Comparators.js +2 -0
- package/lib/sql-query/Typo/Dialect.d.ts +39 -0
- package/lib/sql-query/Typo/Dialect.js +2 -0
- package/lib/sql-query/Typo/Field.d.ts +8 -0
- package/lib/sql-query/Typo/Field.js +2 -0
- package/lib/sql-query/Typo/Helper.d.ts +4 -0
- package/lib/sql-query/Typo/Helper.js +2 -0
- package/lib/sql-query/Typo/Query-ChainBuilder.d.ts +80 -0
- package/lib/sql-query/Typo/Query-ChainBuilder.js +2 -0
- package/lib/sql-query/Typo/Query.d.ts +34 -0
- package/lib/sql-query/Typo/Query.js +17 -0
- package/lib/sql-query/Typo/Sql.d.ts +143 -0
- package/lib/sql-query/Typo/Sql.js +2 -0
- package/lib/sql-query/Typo/SubQuery.d.ts +39 -0
- package/lib/sql-query/Typo/SubQuery.js +2 -0
- package/lib/sql-query/Typo/index.d.ts +9 -0
- package/lib/sql-query/Typo/index.js +2 -0
- package/lib/sql-query/Update.d.ts +15 -0
- package/lib/sql-query/Update.js +39 -0
- package/lib/sql-query/Where.d.ts +4 -0
- package/lib/sql-query/Where.js +280 -0
- package/package.json +71 -36
- package/.travis.yml +0 -14
- package/@types/index.d.ts +0 -254
- package/@types/orm_mirror/orm.d.ts +0 -275
- package/@types/orm_mirror/sql-query.d.ts +0 -79
- package/Readme.md +0 -843
- package/lib/index.js +0 -13
- package/lib/modules/mysql.js +0 -35
- package/lib/modules/sqlite3.js +0 -27
- package/lib/patch.js +0 -271
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { FxOrmSqlDDLSync__Collection } from "./Typo/Collection";
|
|
2
|
+
import { FxOrmSqlDDLSync__DbIndex } from "./Typo/DbIndex";
|
|
3
|
+
import { FxOrmSqlDDLSync__Dialect } from "./Typo/Dialect";
|
|
4
|
+
import { FxOrmSqlDDLSync__Driver } from "./Typo/Driver";
|
|
5
|
+
import { FxOrmSqlDDLSync } from "./Typo/_common";
|
|
6
|
+
import { FxOrmCoreCallbackNS } from '../orm-core/index';
|
|
7
|
+
import "./Dialects";
|
|
8
|
+
import { IProperty } from '../orm-property/index';
|
|
9
|
+
import { IDbDriver } from "../db-driver/index";
|
|
10
|
+
export declare function dialect(name: FxOrmSqlDDLSync__Dialect.DialectType | 'psql'): typeof import("./Dialects/mysql") | typeof import("./Dialects/sqlite");
|
|
11
|
+
export declare class Sync<T extends IDbDriver.ISQLConn = IDbDriver.ISQLConn> {
|
|
12
|
+
strategy: FxOrmSqlDDLSync.SyncCollectionOptions['strategy'];
|
|
13
|
+
/**
|
|
14
|
+
* @description total changes count in this time `Sync`
|
|
15
|
+
* @deprecated
|
|
16
|
+
*/
|
|
17
|
+
total_changes: number;
|
|
18
|
+
readonly collections: FxOrmSqlDDLSync__Collection.Collection[];
|
|
19
|
+
readonly dbdriver: IDbDriver.ITypedDriver<T>;
|
|
20
|
+
readonly Dialect: FxOrmSqlDDLSync__Dialect.Dialect<T>;
|
|
21
|
+
/**
|
|
22
|
+
* @description customTypes
|
|
23
|
+
*/
|
|
24
|
+
readonly types: Record<string, FxOrmSqlDDLSync__Driver.CustomPropertyType<T>>;
|
|
25
|
+
private suppressColumnDrop;
|
|
26
|
+
private debug;
|
|
27
|
+
constructor(options: FxOrmSqlDDLSync.SyncOptions<T>);
|
|
28
|
+
[sync_method: string]: any;
|
|
29
|
+
defineCollection(collection_name: string, properties: FxOrmSqlDDLSync__Collection.Collection['properties'], options?: {
|
|
30
|
+
comment: FxOrmSqlDDLSync__Collection.Collection['comment'];
|
|
31
|
+
}): this;
|
|
32
|
+
findCollection(collection_name: string): FxOrmSqlDDLSync__Collection.Collection;
|
|
33
|
+
defineType(type: string, proto: FxOrmSqlDDLSync__Driver.CustomPropertyType<T>): this;
|
|
34
|
+
/**
|
|
35
|
+
* @description
|
|
36
|
+
* create collection in db if it doesn't exist, then sync all columns for it.
|
|
37
|
+
*
|
|
38
|
+
* @param collection collection relation to create
|
|
39
|
+
*/
|
|
40
|
+
createCollection<T = any>(collection: FxOrmSqlDDLSync__Collection.Collection): T;
|
|
41
|
+
/**
|
|
42
|
+
* @description
|
|
43
|
+
* compare/diff properties between definition ones and the real ones,
|
|
44
|
+
* then sync column in definition but missing in the real
|
|
45
|
+
*
|
|
46
|
+
* @param collection collection properties user provided
|
|
47
|
+
* @param opts
|
|
48
|
+
* - opts.columns: properties from user(default from db)
|
|
49
|
+
* - opts.strategy: (default soft) strategy when conflict between local and remote db, see details below
|
|
50
|
+
*
|
|
51
|
+
* @strategy
|
|
52
|
+
* - 'soft': no change
|
|
53
|
+
* - 'mixed': add missing columns, but never change existed column in db
|
|
54
|
+
* - 'hard': modify existed columns in db
|
|
55
|
+
*/
|
|
56
|
+
syncCollection(_collection: string | FxOrmSqlDDLSync__Collection.Collection, opts?: FxOrmSqlDDLSync.SyncCollectionOptions): void;
|
|
57
|
+
syncIndexes(collection_name: string, index_defs: FxOrmSqlDDLSync__DbIndex.CollectionDbIndexInfo[]): void;
|
|
58
|
+
/**
|
|
59
|
+
* @description
|
|
60
|
+
* sync all collections to db (if not existing), with initializing ones' properties.
|
|
61
|
+
*
|
|
62
|
+
* @callbackable
|
|
63
|
+
*/
|
|
64
|
+
sync(cb: FxOrmCoreCallbackNS.ExecutionCallback<FxOrmSqlDDLSync.SyncResult>): void;
|
|
65
|
+
sync(): FxOrmSqlDDLSync.SyncResult;
|
|
66
|
+
/**
|
|
67
|
+
* @description
|
|
68
|
+
* sync all collections to db whatever it existed,
|
|
69
|
+
* with sync ones' properties whatever the property existed.
|
|
70
|
+
*
|
|
71
|
+
* @callbackable
|
|
72
|
+
*/
|
|
73
|
+
forceSync(cb: FxOrmCoreCallbackNS.ExecutionCallback<FxOrmSqlDDLSync.SyncResult>): void;
|
|
74
|
+
forceSync(): FxOrmSqlDDLSync.SyncResult;
|
|
75
|
+
/**
|
|
76
|
+
* @description if sync one column
|
|
77
|
+
*
|
|
78
|
+
* @param property existed property in collection
|
|
79
|
+
* @param column column expected to be synced
|
|
80
|
+
*/
|
|
81
|
+
needDefinitionToColumn(property: IProperty, column: IProperty, options?: {
|
|
82
|
+
collection?: string;
|
|
83
|
+
}): boolean;
|
|
84
|
+
}
|
|
85
|
+
export type { FxOrmSqlDDLSync } from "./Typo/_common";
|
|
86
|
+
export type { FxOrmSqlDDLSync__Driver } from "./Typo/Driver";
|
|
87
|
+
export type { FxOrmSqlDDLSync__Dialect } from "./Typo/Dialect";
|
|
@@ -0,0 +1,372 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Sync = void 0;
|
|
4
|
+
exports.dialect = dialect;
|
|
5
|
+
const FxORMCore = require("../orm-core/index");
|
|
6
|
+
const util = require("util");
|
|
7
|
+
const Utils_1 = require("./Utils");
|
|
8
|
+
require("./Dialects");
|
|
9
|
+
const index_1 = require("../orm-property/index");
|
|
10
|
+
const SQL_1 = require("./SQL");
|
|
11
|
+
const noOp = () => { };
|
|
12
|
+
function dialect(name) {
|
|
13
|
+
const Dialects = require('./Dialects');
|
|
14
|
+
switch (name) {
|
|
15
|
+
case 'psql':
|
|
16
|
+
case 'postgresql':
|
|
17
|
+
return Dialects['postgresql'];
|
|
18
|
+
case 'sqlite':
|
|
19
|
+
case 'mssql':
|
|
20
|
+
case 'mysql':
|
|
21
|
+
case 'dm':
|
|
22
|
+
return Dialects[name];
|
|
23
|
+
default:
|
|
24
|
+
throw new Error(`no dialect with name '${name}'`);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
function alterCollectionComment(collection, dbdriver) {
|
|
28
|
+
if (dbdriver.type === 'sqlite')
|
|
29
|
+
return;
|
|
30
|
+
// don't remove old comment if not provided
|
|
31
|
+
if (!collection.comment)
|
|
32
|
+
return '';
|
|
33
|
+
dbdriver.execute((0, SQL_1.ALTER_TABLE_COMMENT)(dbdriver.type, collection.name, collection.comment));
|
|
34
|
+
}
|
|
35
|
+
function updateColumnsComment(collection, dbdriver, remote_properties) {
|
|
36
|
+
if (dbdriver.type !== 'psql' && dbdriver.type !== 'dm')
|
|
37
|
+
return;
|
|
38
|
+
// TODO: support mysql also
|
|
39
|
+
const dialect = (0, Utils_1.getSqlQueryDialect)(dbdriver.type);
|
|
40
|
+
for (let k in collection.properties) {
|
|
41
|
+
const prop = collection.properties[k];
|
|
42
|
+
if (!prop.comment)
|
|
43
|
+
continue;
|
|
44
|
+
const remote_prop = remote_properties[k];
|
|
45
|
+
const mapsTo = prop.mapsTo || k;
|
|
46
|
+
if (!mapsTo) {
|
|
47
|
+
this.debug(`[updateColumnsComment] No mapsTo for property '${k}' in collection '${collection.name}'`);
|
|
48
|
+
continue;
|
|
49
|
+
}
|
|
50
|
+
if (remote_prop.comment === prop.comment)
|
|
51
|
+
continue;
|
|
52
|
+
dbdriver.execute(dialect.escape(`comment on column ??.?? is ?`, [collection.name, mapsTo, prop.comment]));
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* @description iterate collection, create property's column which didn't exist.
|
|
57
|
+
*
|
|
58
|
+
* @param collection
|
|
59
|
+
* @param force_sync (dangerous) if force re-syncing property to column
|
|
60
|
+
*/
|
|
61
|
+
function processCollection(syncInstnace, collection, opts) {
|
|
62
|
+
let has;
|
|
63
|
+
let is_processed = false;
|
|
64
|
+
has = syncInstnace.Dialect.hasCollectionSync(syncInstnace.dbdriver, collection.name);
|
|
65
|
+
if (!has) {
|
|
66
|
+
syncInstnace.createCollection(collection);
|
|
67
|
+
is_processed = true;
|
|
68
|
+
}
|
|
69
|
+
const { strategy = syncInstnace.strategy } = opts || {};
|
|
70
|
+
alterCollectionComment(collection, syncInstnace.dbdriver);
|
|
71
|
+
switch (strategy) {
|
|
72
|
+
case 'soft':
|
|
73
|
+
return is_processed;
|
|
74
|
+
case 'mixed':
|
|
75
|
+
case 'hard':
|
|
76
|
+
break;
|
|
77
|
+
}
|
|
78
|
+
syncInstnace.syncCollection(collection, { strategy });
|
|
79
|
+
return true;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* @param collection_name table where column created
|
|
83
|
+
* @param prop column's property
|
|
84
|
+
*/
|
|
85
|
+
function getColumnTypeRaw(syncInstance, collection_name, prop, opts) {
|
|
86
|
+
var _a;
|
|
87
|
+
let type;
|
|
88
|
+
/**
|
|
89
|
+
* get type, customTypes first
|
|
90
|
+
*/
|
|
91
|
+
if (syncInstance.types.hasOwnProperty(prop.type)) {
|
|
92
|
+
type = syncInstance.types[prop.type].datastoreType(prop);
|
|
93
|
+
}
|
|
94
|
+
else { // fallback to driver's types
|
|
95
|
+
const { for: _for = 'create_table' } = opts || {};
|
|
96
|
+
const dbtype = syncInstance.dbdriver.type;
|
|
97
|
+
type = (0, index_1.transformer)(dbtype).toStorageType(prop, {
|
|
98
|
+
collection: collection_name,
|
|
99
|
+
customTypes: (_a = syncInstance.dbdriver) === null || _a === void 0 ? void 0 : _a.customTypes,
|
|
100
|
+
escapeVal: (0, Utils_1.getSqlQueryDialect)(dbtype).escapeVal,
|
|
101
|
+
userOptions: {
|
|
102
|
+
useDefaultValue: _for === 'create_table' || (dbtype === 'sqlite' && ['add_column', 'alter_column'].includes(_for)),
|
|
103
|
+
}
|
|
104
|
+
}).typeValue;
|
|
105
|
+
}
|
|
106
|
+
if (!type)
|
|
107
|
+
return false;
|
|
108
|
+
if (typeof type == "string") {
|
|
109
|
+
type = { value: type };
|
|
110
|
+
}
|
|
111
|
+
if (prop.mapsTo === undefined)
|
|
112
|
+
throw new Error("undefined prop.mapsTo" + JSON.stringify(prop));
|
|
113
|
+
return {
|
|
114
|
+
value: (0, Utils_1.getSqlQueryDialect)(syncInstance.dbdriver.type).escapeId(prop.mapsTo) + " " + type.value,
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
class Sync {
|
|
118
|
+
constructor(options) {
|
|
119
|
+
this.strategy = 'soft';
|
|
120
|
+
const dbdriver = options.dbdriver;
|
|
121
|
+
this.suppressColumnDrop = (0, Utils_1.filterSuppressColumnDrop)(options.suppressColumnDrop !== false, dbdriver.type);
|
|
122
|
+
this.strategy = (0, Utils_1.filterSyncStrategy)(options.syncStrategy);
|
|
123
|
+
this.debug = typeof options.debug === 'function' ? options.debug : noOp;
|
|
124
|
+
Object.defineProperty(this, 'types', { value: {}, writable: false });
|
|
125
|
+
Object.defineProperty(this, 'collections', { value: [], writable: false });
|
|
126
|
+
Object.defineProperty(this, 'dbdriver', { value: dbdriver, writable: false });
|
|
127
|
+
Object.defineProperty(this, 'Dialect', { value: dialect(dbdriver.type), writable: false });
|
|
128
|
+
}
|
|
129
|
+
defineCollection(collection_name, properties, options) {
|
|
130
|
+
let collectionIdx = this.collections.findIndex(collection => collection.name === collection_name);
|
|
131
|
+
if (collectionIdx >= 0)
|
|
132
|
+
this.collections.splice(collectionIdx, 1);
|
|
133
|
+
properties = Object.assign({}, properties);
|
|
134
|
+
let index_defs = [];
|
|
135
|
+
for (let k in properties) {
|
|
136
|
+
// reassign it
|
|
137
|
+
properties[k] = Object.assign({}, properties[k]);
|
|
138
|
+
properties[k].mapsTo = properties[k].mapsTo || k;
|
|
139
|
+
(0, Utils_1.extractCollectionIndexes)(collection_name, k, properties[k], this.dbdriver.type, index_defs);
|
|
140
|
+
(0, Utils_1.normalizeDefinedProperty)(properties[k], this.dbdriver.type);
|
|
141
|
+
}
|
|
142
|
+
if (typeof this.Dialect.convertIndexes === 'function') {
|
|
143
|
+
index_defs = this.Dialect.convertIndexes(collection_name, index_defs);
|
|
144
|
+
}
|
|
145
|
+
this.collections.push({
|
|
146
|
+
name: collection_name,
|
|
147
|
+
properties,
|
|
148
|
+
index_defs,
|
|
149
|
+
comment: options === null || options === void 0 ? void 0 : options.comment,
|
|
150
|
+
});
|
|
151
|
+
return this;
|
|
152
|
+
}
|
|
153
|
+
findCollection(collection_name) {
|
|
154
|
+
return this.collections.find(collection => collection.name === collection_name) || null;
|
|
155
|
+
}
|
|
156
|
+
defineType(type, proto) {
|
|
157
|
+
this.types[type] = proto;
|
|
158
|
+
return this;
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* @description
|
|
162
|
+
* create collection in db if it doesn't exist, then sync all columns for it.
|
|
163
|
+
*
|
|
164
|
+
* @param collection collection relation to create
|
|
165
|
+
*/
|
|
166
|
+
createCollection(collection) {
|
|
167
|
+
const columns = [];
|
|
168
|
+
let keys = [];
|
|
169
|
+
for (let k in collection.properties) {
|
|
170
|
+
let property = collection.properties[k], col;
|
|
171
|
+
col = getColumnTypeRaw(this, collection.name, property, { for: 'create_table' });
|
|
172
|
+
if (col === false) {
|
|
173
|
+
(0, Utils_1.logJson)('createCollection', property);
|
|
174
|
+
throw new Error(`Invalid type definition for property '${k}'.`);
|
|
175
|
+
}
|
|
176
|
+
if (property.key)
|
|
177
|
+
keys.push(property.mapsTo);
|
|
178
|
+
columns.push(col.value);
|
|
179
|
+
}
|
|
180
|
+
this.debug("Creating " + collection.name);
|
|
181
|
+
// ? TODO: what it means?
|
|
182
|
+
if (typeof this.Dialect.processKeys === "function")
|
|
183
|
+
keys = this.Dialect.processKeys(keys);
|
|
184
|
+
this.total_changes += 1;
|
|
185
|
+
if (this.dbdriver.type === 'psql') {
|
|
186
|
+
(0, Utils_1.psqlRepairEnumTypes)(collection.properties, collection.name, this.dbdriver);
|
|
187
|
+
}
|
|
188
|
+
const result_1 = this.Dialect.createCollectionSync(this.dbdriver, collection.name, columns, keys, { comment: collection.comment });
|
|
189
|
+
this.syncIndexes(collection.name, collection.index_defs);
|
|
190
|
+
updateColumnsComment(collection, this.dbdriver, this.Dialect.getCollectionPropertiesSync(this.dbdriver, collection.name));
|
|
191
|
+
return result_1;
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* @description
|
|
195
|
+
* compare/diff properties between definition ones and the real ones,
|
|
196
|
+
* then sync column in definition but missing in the real
|
|
197
|
+
*
|
|
198
|
+
* @param collection collection properties user provided
|
|
199
|
+
* @param opts
|
|
200
|
+
* - opts.columns: properties from user(default from db)
|
|
201
|
+
* - opts.strategy: (default soft) strategy when conflict between local and remote db, see details below
|
|
202
|
+
*
|
|
203
|
+
* @strategy
|
|
204
|
+
* - 'soft': no change
|
|
205
|
+
* - 'mixed': add missing columns, but never change existed column in db
|
|
206
|
+
* - 'hard': modify existed columns in db
|
|
207
|
+
*/
|
|
208
|
+
syncCollection(_collection, opts) {
|
|
209
|
+
const collection = typeof _collection === 'string' ? this.findCollection(_collection) : _collection;
|
|
210
|
+
if (!collection)
|
|
211
|
+
throw new Error('[syncCollection] invalid collection');
|
|
212
|
+
let { columns = this.Dialect.getCollectionPropertiesSync(this.dbdriver, collection.name), strategy = this.strategy, suppressColumnDrop = this.suppressColumnDrop } = opts || {};
|
|
213
|
+
suppressColumnDrop = (0, Utils_1.filterSuppressColumnDrop)(suppressColumnDrop, this.dbdriver.type);
|
|
214
|
+
strategy = (0, Utils_1.filterSyncStrategy)(strategy);
|
|
215
|
+
let last_k = null;
|
|
216
|
+
this.debug("Synchronizing " + collection.name);
|
|
217
|
+
if (strategy !== 'soft') {
|
|
218
|
+
for (let k in collection.properties) {
|
|
219
|
+
const prop = collection.properties[k];
|
|
220
|
+
if (!columns.hasOwnProperty(k)) {
|
|
221
|
+
prop.mapsTo = prop.mapsTo || k;
|
|
222
|
+
const col = getColumnTypeRaw(this, collection.name, prop, { for: 'add_column' });
|
|
223
|
+
if (col === false) {
|
|
224
|
+
(0, Utils_1.logJson)('syncCollection', prop);
|
|
225
|
+
throw new Error(`Invalid type definition for property '${k}'.`);
|
|
226
|
+
}
|
|
227
|
+
this.debug("Adding column " + collection.name + "." + k + ": " + col.value);
|
|
228
|
+
// check existence again
|
|
229
|
+
if (!this.Dialect.hasCollectionColumnsSync(this.dbdriver, collection.name, prop.mapsTo)) {
|
|
230
|
+
this.Dialect.addCollectionColumnSync(this.dbdriver, collection.name, col.value,
|
|
231
|
+
// for sqlite, added column must be the last one,
|
|
232
|
+
// we pass empty string to make `addCollectionColumnSync`
|
|
233
|
+
// find last column automatically
|
|
234
|
+
this.dbdriver.type === 'sqlite' ? '' : last_k);
|
|
235
|
+
this.total_changes += 1;
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
else if (strategy === 'hard' &&
|
|
239
|
+
this.dbdriver.type !== 'sqlite'
|
|
240
|
+
&& this.needDefinitionToColumn(prop, columns[k], { collection: collection.name })) {
|
|
241
|
+
const col = getColumnTypeRaw(this, collection.name, prop, { for: 'alter_column' });
|
|
242
|
+
if (col === false) {
|
|
243
|
+
(0, Utils_1.logJson)('syncCollection', prop);
|
|
244
|
+
throw new Error(`Invalid type definition for property '${k}'.`);
|
|
245
|
+
}
|
|
246
|
+
this.debug("Modifying column " + collection.name + "." + k + ": " + col.value);
|
|
247
|
+
// check existence again
|
|
248
|
+
if (this.Dialect.hasCollectionColumnsSync(this.dbdriver, collection.name, prop.mapsTo)) {
|
|
249
|
+
this.Dialect.modifyCollectionColumnSync(this.dbdriver, collection.name, col.value);
|
|
250
|
+
this.total_changes += 1;
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
last_k = k;
|
|
254
|
+
}
|
|
255
|
+
if (strategy === 'hard' && !suppressColumnDrop) {
|
|
256
|
+
const hash = (0, Utils_1.getCollectionMapsTo_PropertyNameDict)(collection);
|
|
257
|
+
for (let colname in columns) {
|
|
258
|
+
if (collection.properties.hasOwnProperty(colname))
|
|
259
|
+
continue;
|
|
260
|
+
/* colname maybe mapsTo */
|
|
261
|
+
if (hash.hasOwnProperty(colname))
|
|
262
|
+
continue;
|
|
263
|
+
this.debug(`Dropping column ${collection.name}.${colname}`);
|
|
264
|
+
this.total_changes += 1;
|
|
265
|
+
this.Dialect.dropCollectionColumnSync(this.dbdriver, collection.name, colname);
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
this.syncIndexes(collection.name, collection.index_defs);
|
|
270
|
+
}
|
|
271
|
+
syncIndexes(collection_name, index_defs) {
|
|
272
|
+
if (index_defs.length == 0)
|
|
273
|
+
return;
|
|
274
|
+
const db_indexes = this.Dialect.getCollectionIndexesSync(this.dbdriver, collection_name);
|
|
275
|
+
for (let i = 0; i < index_defs.length; i++) {
|
|
276
|
+
if (!db_indexes.hasOwnProperty(index_defs[i].name)) {
|
|
277
|
+
this.debug("Adding index " + collection_name + "." + index_defs[i].name + " (" + index_defs[i].columns.join(", ") + ")");
|
|
278
|
+
this.total_changes += 1;
|
|
279
|
+
const index = index_defs[i];
|
|
280
|
+
this.Dialect.addIndexSync(this.dbdriver, index.name, index.unique, collection_name, index.columns);
|
|
281
|
+
continue;
|
|
282
|
+
}
|
|
283
|
+
else if (!db_indexes[index_defs[i].name].unique != !index_defs[i].unique) {
|
|
284
|
+
this.debug("Replacing index " + collection_name + "." + index_defs[i].name);
|
|
285
|
+
this.total_changes += 1;
|
|
286
|
+
const index = index_defs[i];
|
|
287
|
+
this.Dialect.removeIndexSync(this.dbdriver, index.name, collection_name);
|
|
288
|
+
this.Dialect.addIndexSync(this.dbdriver, index.name, index.unique, collection_name, index.columns);
|
|
289
|
+
}
|
|
290
|
+
delete db_indexes[index_defs[i].name];
|
|
291
|
+
}
|
|
292
|
+
for (let idx in db_indexes) {
|
|
293
|
+
this.debug("Removing index " + collection_name + "." + idx);
|
|
294
|
+
this.total_changes += 1;
|
|
295
|
+
this.Dialect.removeIndexSync(this.dbdriver, collection_name, idx);
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
sync(cb) {
|
|
299
|
+
const exposedErrResults = FxORMCore.Utils.exposeErrAndResultFromSyncMethod(() => {
|
|
300
|
+
this.total_changes = 0;
|
|
301
|
+
this.collections.forEach(collection => processCollection(this, collection, { strategy: this.strategy }));
|
|
302
|
+
return {
|
|
303
|
+
changes: this.total_changes
|
|
304
|
+
};
|
|
305
|
+
});
|
|
306
|
+
FxORMCore.Utils.throwErrOrCallabckErrResult(exposedErrResults, { no_throw: !!cb, callback: cb });
|
|
307
|
+
return exposedErrResults.result;
|
|
308
|
+
}
|
|
309
|
+
;
|
|
310
|
+
forceSync(cb) {
|
|
311
|
+
const exposedErrResults = FxORMCore.Utils.exposeErrAndResultFromSyncMethod(() => {
|
|
312
|
+
this.total_changes = 0;
|
|
313
|
+
this.collections.forEach(collection => processCollection(this, collection, { strategy: 'hard' }));
|
|
314
|
+
return {
|
|
315
|
+
changes: this.total_changes
|
|
316
|
+
};
|
|
317
|
+
});
|
|
318
|
+
FxORMCore.Utils.throwErrOrCallabckErrResult(exposedErrResults, { no_throw: !!cb, callback: cb });
|
|
319
|
+
return exposedErrResults.result;
|
|
320
|
+
}
|
|
321
|
+
;
|
|
322
|
+
/**
|
|
323
|
+
* @description if sync one column
|
|
324
|
+
*
|
|
325
|
+
* @param property existed property in collection
|
|
326
|
+
* @param column column expected to be synced
|
|
327
|
+
*/
|
|
328
|
+
needDefinitionToColumn(property, column, options) {
|
|
329
|
+
if (property.serial && property.type === "number") {
|
|
330
|
+
property.type = "serial";
|
|
331
|
+
}
|
|
332
|
+
/* if type not equal, sync is required */
|
|
333
|
+
if (property.type != column.type) {
|
|
334
|
+
if (typeof this.Dialect.supportsType !== "function") {
|
|
335
|
+
return true;
|
|
336
|
+
}
|
|
337
|
+
if (this.Dialect.supportsType(property.type) !== column.type) {
|
|
338
|
+
return true;
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
/* deal with type which maybe require sync as type equals between two sides :start */
|
|
342
|
+
if (property.type === 'serial') {
|
|
343
|
+
return false; // serial columns have a fixed form, nothing more to check
|
|
344
|
+
}
|
|
345
|
+
if (property.required !== column.required && !property.key) {
|
|
346
|
+
return true;
|
|
347
|
+
}
|
|
348
|
+
const { collection: collection_name = undefined } = options || {};
|
|
349
|
+
if (property.hasOwnProperty('defaultValue')
|
|
350
|
+
&& (0, Utils_1.filterPropertyDefaultValue)(property, {
|
|
351
|
+
collection: collection_name,
|
|
352
|
+
property,
|
|
353
|
+
driver: this.dbdriver
|
|
354
|
+
}) != column.defaultValue) {
|
|
355
|
+
return true;
|
|
356
|
+
}
|
|
357
|
+
if (property.type === 'number' || property.type === 'integer') {
|
|
358
|
+
if (column.hasOwnProperty('size') && (property.size || 4) != column.size) {
|
|
359
|
+
return true;
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
if (property.type === 'enum' && column.type === 'enum') {
|
|
363
|
+
if (util.difference(property.values, column.values).length > 0
|
|
364
|
+
|| util.difference(column.values, property.values).length > 0) {
|
|
365
|
+
return true;
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
/* deal with type which maybe require sync as type equals between two sides :end */
|
|
369
|
+
return false;
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
exports.Sync = Sync;
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
function between(a, b, opts) {
|
|
3
|
+
return createSpecialObject({
|
|
4
|
+
from: a, to: b, asIdentifier: !!(opts === null || opts === void 0 ? void 0 : opts.asIdentifier)
|
|
5
|
+
}, 'between');
|
|
6
|
+
}
|
|
7
|
+
;
|
|
8
|
+
function not_between(a, b, opts) {
|
|
9
|
+
return createSpecialObject({
|
|
10
|
+
from: a, to: b, asIdentifier: !!(opts === null || opts === void 0 ? void 0 : opts.asIdentifier)
|
|
11
|
+
}, 'not_between');
|
|
12
|
+
}
|
|
13
|
+
;
|
|
14
|
+
function like(expr, opts) {
|
|
15
|
+
return createSpecialObject({
|
|
16
|
+
expr: expr, asIdentifier: !!(opts === null || opts === void 0 ? void 0 : opts.asIdentifier)
|
|
17
|
+
}, 'like');
|
|
18
|
+
}
|
|
19
|
+
;
|
|
20
|
+
function not_like(expr, opts) {
|
|
21
|
+
return createSpecialObject({
|
|
22
|
+
expr: expr, asIdentifier: !!(opts === null || opts === void 0 ? void 0 : opts.asIdentifier)
|
|
23
|
+
}, 'not_like');
|
|
24
|
+
}
|
|
25
|
+
;
|
|
26
|
+
function eq(v, opts) {
|
|
27
|
+
return createSpecialObject({
|
|
28
|
+
val: v, asIdentifier: !!(opts === null || opts === void 0 ? void 0 : opts.asIdentifier)
|
|
29
|
+
}, 'eq');
|
|
30
|
+
}
|
|
31
|
+
;
|
|
32
|
+
function ne(v, opts) {
|
|
33
|
+
return createSpecialObject({
|
|
34
|
+
val: v, asIdentifier: !!(opts === null || opts === void 0 ? void 0 : opts.asIdentifier)
|
|
35
|
+
}, 'ne');
|
|
36
|
+
}
|
|
37
|
+
;
|
|
38
|
+
function gt(v, opts) {
|
|
39
|
+
return createSpecialObject({
|
|
40
|
+
val: v, asIdentifier: !!(opts === null || opts === void 0 ? void 0 : opts.asIdentifier)
|
|
41
|
+
}, 'gt');
|
|
42
|
+
}
|
|
43
|
+
;
|
|
44
|
+
function gte(v, opts) {
|
|
45
|
+
return createSpecialObject({
|
|
46
|
+
val: v, asIdentifier: !!(opts === null || opts === void 0 ? void 0 : opts.asIdentifier)
|
|
47
|
+
}, 'gte');
|
|
48
|
+
}
|
|
49
|
+
;
|
|
50
|
+
function lt(v, opts) {
|
|
51
|
+
return createSpecialObject({
|
|
52
|
+
val: v, asIdentifier: !!(opts === null || opts === void 0 ? void 0 : opts.asIdentifier)
|
|
53
|
+
}, 'lt');
|
|
54
|
+
}
|
|
55
|
+
;
|
|
56
|
+
function lte(v, opts) {
|
|
57
|
+
return createSpecialObject({
|
|
58
|
+
val: v, asIdentifier: !!(opts === null || opts === void 0 ? void 0 : opts.asIdentifier)
|
|
59
|
+
}, 'lte');
|
|
60
|
+
}
|
|
61
|
+
;
|
|
62
|
+
function _in(v, opts) {
|
|
63
|
+
return createSpecialObject({
|
|
64
|
+
val: v, asIdentifier: !!(opts === null || opts === void 0 ? void 0 : opts.asIdentifier)
|
|
65
|
+
}, 'in');
|
|
66
|
+
}
|
|
67
|
+
;
|
|
68
|
+
function not_in(v, opts) {
|
|
69
|
+
return createSpecialObject({
|
|
70
|
+
val: v, asIdentifier: !!(opts === null || opts === void 0 ? void 0 : opts.asIdentifier)
|
|
71
|
+
}, 'not_in');
|
|
72
|
+
}
|
|
73
|
+
;
|
|
74
|
+
function createSpecialObject(obj, tag) {
|
|
75
|
+
Object.defineProperty(obj, "sql_comparator", {
|
|
76
|
+
configurable: false,
|
|
77
|
+
enumerable: false,
|
|
78
|
+
value: function () { return tag; }
|
|
79
|
+
});
|
|
80
|
+
return obj;
|
|
81
|
+
}
|
|
82
|
+
module.exports = {
|
|
83
|
+
between,
|
|
84
|
+
not_between,
|
|
85
|
+
like,
|
|
86
|
+
not_like,
|
|
87
|
+
eq,
|
|
88
|
+
ne,
|
|
89
|
+
gt,
|
|
90
|
+
gte,
|
|
91
|
+
lt,
|
|
92
|
+
lte,
|
|
93
|
+
in: _in,
|
|
94
|
+
not_in,
|
|
95
|
+
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { ChainBuilderBase } from "./Helpers";
|
|
2
|
+
import { FxSqlQueryDialect } from "./Typo/Dialect";
|
|
3
|
+
import { FxSqlQueryColumns } from "./Typo/Field";
|
|
4
|
+
import { FxSqlQueryChainBuilder } from "./Typo/Query-ChainBuilder";
|
|
5
|
+
/**
|
|
6
|
+
* Instantiate a new CREATE-type query builder
|
|
7
|
+
* @param Dialect
|
|
8
|
+
* @returns {{table: table, field: field, fields: fields, build: build}}
|
|
9
|
+
* @constructor
|
|
10
|
+
*/
|
|
11
|
+
export declare class CreateQuery extends ChainBuilderBase implements FxSqlQueryChainBuilder.ChainBuilder__Create {
|
|
12
|
+
tableName: string;
|
|
13
|
+
structure: FxSqlQueryColumns.FieldItemTypeMap;
|
|
14
|
+
constructor(Dialect: FxSqlQueryDialect.Dialect);
|
|
15
|
+
/**
|
|
16
|
+
* Set the table name
|
|
17
|
+
* @param table_name
|
|
18
|
+
*/
|
|
19
|
+
table(table_name: string): this;
|
|
20
|
+
/**
|
|
21
|
+
* Add a field
|
|
22
|
+
* @param name
|
|
23
|
+
* @param type
|
|
24
|
+
*/
|
|
25
|
+
field(name: string, type: FxSqlQueryDialect.DialectFieldType): this;
|
|
26
|
+
/**
|
|
27
|
+
* Set all the fields
|
|
28
|
+
* @param fields
|
|
29
|
+
*/
|
|
30
|
+
fields(fields?: FxSqlQueryColumns.FieldItemTypeMap): any;
|
|
31
|
+
/**
|
|
32
|
+
* Build a query from the passed params
|
|
33
|
+
*/
|
|
34
|
+
build(): string;
|
|
35
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CreateQuery = void 0;
|
|
4
|
+
const Helpers_1 = require("./Helpers");
|
|
5
|
+
/**
|
|
6
|
+
* Instantiate a new CREATE-type query builder
|
|
7
|
+
* @param Dialect
|
|
8
|
+
* @returns {{table: table, field: field, fields: fields, build: build}}
|
|
9
|
+
* @constructor
|
|
10
|
+
*/
|
|
11
|
+
class CreateQuery extends Helpers_1.ChainBuilderBase {
|
|
12
|
+
constructor(Dialect) {
|
|
13
|
+
super(Dialect);
|
|
14
|
+
this.tableName = null;
|
|
15
|
+
this.structure = {};
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Set the table name
|
|
19
|
+
* @param table_name
|
|
20
|
+
*/
|
|
21
|
+
table(table_name) {
|
|
22
|
+
this.tableName = table_name;
|
|
23
|
+
return this;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Add a field
|
|
27
|
+
* @param name
|
|
28
|
+
* @param type
|
|
29
|
+
*/
|
|
30
|
+
field(name, type) {
|
|
31
|
+
this.structure[name] = type;
|
|
32
|
+
return this;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Set all the fields
|
|
36
|
+
* @param fields
|
|
37
|
+
*/
|
|
38
|
+
fields(fields) {
|
|
39
|
+
if (!fields) {
|
|
40
|
+
return this.structure;
|
|
41
|
+
}
|
|
42
|
+
this.structure = fields;
|
|
43
|
+
return this;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Build a query from the passed params
|
|
47
|
+
*/
|
|
48
|
+
build() {
|
|
49
|
+
if (!this.tableName) {
|
|
50
|
+
return '';
|
|
51
|
+
}
|
|
52
|
+
const structure = this.structure;
|
|
53
|
+
const sqlBuilder = this.Dialect.knex.schema.createTable(this.tableName, function (t) {
|
|
54
|
+
Object.keys(structure).forEach(field => {
|
|
55
|
+
const desc = structure[field];
|
|
56
|
+
switch (desc) {
|
|
57
|
+
case 'id':
|
|
58
|
+
t.increments(field);
|
|
59
|
+
break;
|
|
60
|
+
case 'int':
|
|
61
|
+
t.integer(field);
|
|
62
|
+
break;
|
|
63
|
+
case 'float':
|
|
64
|
+
t.float(field, 12, 2);
|
|
65
|
+
break;
|
|
66
|
+
case 'bool':
|
|
67
|
+
t.specificType(field, 'TINYINT(1)');
|
|
68
|
+
break;
|
|
69
|
+
case 'text':
|
|
70
|
+
t.text(field);
|
|
71
|
+
break;
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
return sqlBuilder.toQuery();
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
exports.CreateQuery = CreateQuery;
|