@riao/dbal 1.1.3 → 2.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 +5 -1
- package/builder/builder.d.ts +1 -46
- package/builder/builder.js +1 -125
- package/builder/builder.js.map +1 -1
- package/builder/index.d.ts +1 -0
- package/builder/index.js +3 -1
- package/builder/index.js.map +1 -1
- package/builder/sql-builder.d.ts +48 -0
- package/builder/sql-builder.js +152 -0
- package/builder/sql-builder.js.map +1 -0
- package/builder/statement-builder.d.ts +9 -0
- package/builder/statement-builder.js +19 -0
- package/builder/statement-builder.js.map +1 -0
- package/column/column-options.d.ts +1 -1
- package/conditions/condition-aliases.d.ts +12 -0
- package/conditions/condition-aliases.js +43 -0
- package/conditions/condition-aliases.js.map +1 -0
- package/conditions/condition-token.d.ts +18 -0
- package/conditions/condition-token.js +16 -0
- package/conditions/condition-token.js.map +1 -0
- package/conditions/conditions.d.ts +14 -0
- package/conditions/conditions.js +68 -0
- package/conditions/conditions.js.map +1 -0
- package/conditions/index.d.ts +4 -0
- package/conditions/index.js +23 -0
- package/conditions/index.js.map +1 -0
- package/conditions/is-condition.d.ts +1 -0
- package/conditions/is-condition.js +8 -0
- package/conditions/is-condition.js.map +1 -0
- package/database/database.d.ts +0 -6
- package/database/database.js +1 -8
- package/database/database.js.map +1 -1
- package/ddl/ddl-builder.d.ts +4 -2
- package/ddl/ddl-builder.js +98 -91
- package/ddl/ddl-builder.js.map +1 -1
- package/dml/index.d.ts +0 -1
- package/dml/index.js +0 -1
- package/dml/index.js.map +1 -1
- package/dml/insert.d.ts +1 -0
- package/dml/query-builder.d.ts +12 -7
- package/dml/query-builder.js +179 -136
- package/dml/query-builder.js.map +1 -1
- package/dml/query-repository.d.ts +7 -1
- package/dml/query-repository.js +57 -9
- package/dml/query-repository.js.map +1 -1
- package/dml/select.d.ts +3 -1
- package/dml/where.d.ts +5 -23
- package/dml/where.js +0 -64
- package/dml/where.js.map +1 -1
- package/functions/function-aliases.d.ts +3 -0
- package/functions/function-aliases.js +13 -0
- package/functions/function-aliases.js.map +1 -0
- package/functions/{function-interface.d.ts → function-token.d.ts} +2 -3
- package/functions/{function-interface.js → function-token.js} +3 -2
- package/functions/function-token.js.map +1 -0
- package/functions/functions.d.ts +3 -2
- package/functions/functions.js +12 -4
- package/functions/functions.js.map +1 -1
- package/functions/index.d.ts +4 -1
- package/functions/index.js +6 -1
- package/functions/index.js.map +1 -1
- package/functions/is-database-function.d.ts +7 -0
- package/functions/is-database-function.js +14 -0
- package/functions/is-database-function.js.map +1 -0
- package/index.d.ts +3 -0
- package/index.js +3 -0
- package/index.js.map +1 -1
- package/migration/create-migration-table.js +2 -1
- package/migration/create-migration-table.js.map +1 -1
- package/package.json +1 -1
- package/repository/repository-options.d.ts +0 -2
- package/repository/repository.d.ts +0 -2
- package/repository/repository.js +1 -3
- package/repository/repository.js.map +1 -1
- package/seed/auto-seed.js +16 -16
- package/seed/auto-seed.js.map +1 -1
- package/seed/create-seed-table.js +2 -1
- package/seed/create-seed-table.js.map +1 -1
- package/tokens/column-name-token.d.ts +4 -0
- package/tokens/column-name-token.js +8 -0
- package/tokens/column-name-token.js.map +1 -0
- package/tokens/index.d.ts +1 -0
- package/tokens/index.js +18 -0
- package/tokens/index.js.map +1 -0
- package/dml/column-name.d.ts +0 -3
- package/dml/column-name.js +0 -12
- package/dml/column-name.js.map +0 -1
- package/functions/function-interface.js.map +0 -1
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.isCondition = exports.Conditions = void 0;
|
|
18
|
+
__exportStar(require("./condition-aliases"), exports);
|
|
19
|
+
var conditions_1 = require("./conditions");
|
|
20
|
+
Object.defineProperty(exports, "Conditions", { enumerable: true, get: function () { return conditions_1.Conditions; } });
|
|
21
|
+
var is_condition_1 = require("./is-condition");
|
|
22
|
+
Object.defineProperty(exports, "isCondition", { enumerable: true, get: function () { return is_condition_1.isCondition; } });
|
|
23
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/conditions/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,sDAAoC;AAEpC,2CAA0C;AAAjC,wGAAA,UAAU,OAAA;AACnB,+CAA6C;AAApC,2GAAA,WAAW,OAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function isCondition(value: any): boolean;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isCondition = void 0;
|
|
4
|
+
function isCondition(value) {
|
|
5
|
+
return value && typeof value === 'object' && 'riao_condition' in value;
|
|
6
|
+
}
|
|
7
|
+
exports.isCondition = isCondition;
|
|
8
|
+
//# sourceMappingURL=is-condition.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"is-condition.js","sourceRoot":"","sources":["../../../src/conditions/is-condition.ts"],"names":[],"mappings":";;;AAAA,SAAgB,WAAW,CAAC,KAAU;IACrC,OAAO,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,gBAAgB,IAAI,KAAK,CAAC;AACxE,CAAC;AAFD,kCAEC"}
|
package/database/database.d.ts
CHANGED
|
@@ -6,7 +6,6 @@ import { DatabaseRecord } from '../record';
|
|
|
6
6
|
import { DatabaseQueryBuilder, QueryRepository, QueryRepositoryOptions } from '../dml';
|
|
7
7
|
import { SchemaQueryRepository } from '../schema/schema-query-repository';
|
|
8
8
|
import { Schema } from '../schema';
|
|
9
|
-
import { DatabaseFunctions } from '../functions';
|
|
10
9
|
import { Transaction } from './transaction';
|
|
11
10
|
/**
|
|
12
11
|
* Represents a single database instance, including a driver,
|
|
@@ -102,11 +101,6 @@ export declare abstract class Database {
|
|
|
102
101
|
* Database schema
|
|
103
102
|
*/
|
|
104
103
|
protected schema: Schema;
|
|
105
|
-
/**
|
|
106
|
-
* Functions
|
|
107
|
-
*/
|
|
108
|
-
functions: DatabaseFunctions;
|
|
109
|
-
functionsType: typeof DatabaseFunctions;
|
|
110
104
|
/**
|
|
111
105
|
* Initialize the database
|
|
112
106
|
*
|
package/database/database.js
CHANGED
|
@@ -17,7 +17,6 @@ const get_database_path_1 = require("./get-database-path");
|
|
|
17
17
|
const ddl_1 = require("../ddl");
|
|
18
18
|
const dml_1 = require("../dml");
|
|
19
19
|
const schema_query_repository_1 = require("../schema/schema-query-repository");
|
|
20
|
-
const functions_1 = require("../functions");
|
|
21
20
|
/**
|
|
22
21
|
* Represents a single database instance, including a driver,
|
|
23
22
|
* configuration, connection, etc.
|
|
@@ -73,7 +72,6 @@ class Database {
|
|
|
73
72
|
* Schema Query repository class type used to create new repos
|
|
74
73
|
*/
|
|
75
74
|
this.schemaQueryRepositoryType = schema_query_repository_1.SchemaQueryRepository;
|
|
76
|
-
this.functionsType = functions_1.DatabaseFunctions;
|
|
77
75
|
}
|
|
78
76
|
/**
|
|
79
77
|
* Initialize the database
|
|
@@ -92,9 +90,6 @@ class Database {
|
|
|
92
90
|
if (!this.driver) {
|
|
93
91
|
this.driver = new this.driverType();
|
|
94
92
|
}
|
|
95
|
-
if (!this.functions) {
|
|
96
|
-
this.functions = new this.functionsType();
|
|
97
|
-
}
|
|
98
93
|
if (options.connectionOptions) {
|
|
99
94
|
this.env = options.connectionOptions;
|
|
100
95
|
}
|
|
@@ -195,7 +190,6 @@ class Database {
|
|
|
195
190
|
getDataDefinitionRepository() {
|
|
196
191
|
const repo = new this.ddlRepositoryType({
|
|
197
192
|
ddlBuilderType: this.ddlBuilderType,
|
|
198
|
-
functions: this.functions,
|
|
199
193
|
});
|
|
200
194
|
if (this.isLoaded) {
|
|
201
195
|
repo.init({ driver: this.driver });
|
|
@@ -220,7 +214,7 @@ class Database {
|
|
|
220
214
|
* @returns Returns the query repository
|
|
221
215
|
*/
|
|
222
216
|
getQueryRepository(options) {
|
|
223
|
-
const repo = new this.queryRepositoryType(Object.assign(Object.assign({}, (options !== null && options !== void 0 ? options : {})), { queryBuilderType: this.queryBuilderType
|
|
217
|
+
const repo = new this.queryRepositoryType(Object.assign(Object.assign({}, (options !== null && options !== void 0 ? options : {})), { queryBuilderType: this.queryBuilderType }));
|
|
224
218
|
if (this.isLoaded) {
|
|
225
219
|
repo.init({
|
|
226
220
|
driver: this.driver,
|
|
@@ -240,7 +234,6 @@ class Database {
|
|
|
240
234
|
getSchemaQueryRepository() {
|
|
241
235
|
const repo = new this.schemaQueryRepositoryType({
|
|
242
236
|
queryBuilderType: this.queryBuilderType,
|
|
243
|
-
functions: this.functions,
|
|
244
237
|
});
|
|
245
238
|
if (this.isLoaded) {
|
|
246
239
|
repo.init({
|
package/database/database.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"database.js","sourceRoot":"","sources":["../../../src/database/database.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2BAAwE;AACxE,+BAAwC;AAExC,sCAAqD;AACrD,2DAAsD;AACtD,gCAAyE;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AAM,EAAE,gBAAgB,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC;YAE9D,OAAO,MAAM,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,EAAE,EAAE;gBACxC,MAAM,EAAE,gBAAgB;gBACxB,GAAG;gBACH,KAAK;aACL,CAAC,CAAC;QACJ,CAAC;KAAA;CACD;AA1YD,4BA0YC"}
|
package/ddl/ddl-builder.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { StatementBuilder } from '../builder/statement-builder';
|
|
2
2
|
import { ColumnOptions, ColumnType } from '../column';
|
|
3
3
|
import { AddColumnsOptions, AddForeignKeyOptions, ChangeColumnOptions, DropColumnOptions, DropForeignKeyOptions, RenameTableOptions } from './alter-table';
|
|
4
4
|
import { CreateDatabaseOptions } from './create-database';
|
|
@@ -10,8 +10,9 @@ import { DropUserOptions } from './drop-user';
|
|
|
10
10
|
import { ForeignKeyConstraint, ForeignKeyReferenceOption } from './foreign-key-constraint';
|
|
11
11
|
import { GrantOn, GrantOptions } from './grant';
|
|
12
12
|
import { TruncateOptions } from './truncate';
|
|
13
|
-
export declare class DataDefinitionBuilder extends
|
|
13
|
+
export declare class DataDefinitionBuilder extends StatementBuilder {
|
|
14
14
|
protected columnTypes: typeof ColumnType;
|
|
15
|
+
getColumnTypes(): typeof ColumnType;
|
|
15
16
|
createDatabaseStatement(): this;
|
|
16
17
|
createDatabase(options: CreateDatabaseOptions): this;
|
|
17
18
|
createUserStatement(): this;
|
|
@@ -27,6 +28,7 @@ export declare class DataDefinitionBuilder extends Builder {
|
|
|
27
28
|
columnDefaultFalse(): this;
|
|
28
29
|
columnAutoIncrement(): this;
|
|
29
30
|
createTableColumn(column: ColumnOptions): this;
|
|
31
|
+
createTablePrimaryKeys(names: string[]): this;
|
|
30
32
|
createTableColumns(options: CreateTableOptions): this;
|
|
31
33
|
createTable(options: CreateTableOptions): this;
|
|
32
34
|
constraintStatement(): this;
|
package/ddl/ddl-builder.js
CHANGED
|
@@ -1,39 +1,43 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.DataDefinitionBuilder = void 0;
|
|
4
|
-
const
|
|
4
|
+
const statement_builder_1 = require("../builder/statement-builder");
|
|
5
5
|
const column_1 = require("../column");
|
|
6
|
-
|
|
6
|
+
const functions_1 = require("../functions");
|
|
7
|
+
class DataDefinitionBuilder extends statement_builder_1.StatementBuilder {
|
|
7
8
|
constructor() {
|
|
8
9
|
super(...arguments);
|
|
9
10
|
this.columnTypes = column_1.ColumnType;
|
|
10
11
|
}
|
|
12
|
+
getColumnTypes() {
|
|
13
|
+
return this.columnTypes;
|
|
14
|
+
}
|
|
11
15
|
// ------------------------------------------------------------------------
|
|
12
16
|
// Create Database
|
|
13
17
|
// ------------------------------------------------------------------------
|
|
14
18
|
createDatabaseStatement() {
|
|
15
|
-
this.sql
|
|
19
|
+
this.sql.append('CREATE DATABASE ');
|
|
16
20
|
return this;
|
|
17
21
|
}
|
|
18
22
|
createDatabase(options) {
|
|
19
23
|
this.createDatabaseStatement();
|
|
20
|
-
this.sql
|
|
24
|
+
this.sql.append(options.name);
|
|
21
25
|
return this;
|
|
22
26
|
}
|
|
23
27
|
// ------------------------------------------------------------------------
|
|
24
28
|
// Create User
|
|
25
29
|
// ------------------------------------------------------------------------
|
|
26
30
|
createUserStatement() {
|
|
27
|
-
this.sql
|
|
31
|
+
this.sql.append('CREATE USER ');
|
|
28
32
|
return this;
|
|
29
33
|
}
|
|
30
34
|
createUserPassword(password) {
|
|
31
|
-
this.sql
|
|
35
|
+
this.sql.append(`WITH PASSWORD '${password}' `);
|
|
32
36
|
return this;
|
|
33
37
|
}
|
|
34
38
|
createUser(options) {
|
|
35
39
|
this.createUserStatement();
|
|
36
|
-
this.sql
|
|
40
|
+
this.sql.append(options.name + ' ');
|
|
37
41
|
if (options.password) {
|
|
38
42
|
this.createUserPassword(options.password);
|
|
39
43
|
}
|
|
@@ -43,32 +47,32 @@ class DataDefinitionBuilder extends builder_1.Builder {
|
|
|
43
47
|
// Create Table
|
|
44
48
|
// ------------------------------------------------------------------------
|
|
45
49
|
createTableStatement() {
|
|
46
|
-
this.sql
|
|
50
|
+
this.sql.append('CREATE TABLE ');
|
|
47
51
|
return this;
|
|
48
52
|
}
|
|
49
53
|
ifNotExists() {
|
|
50
|
-
this.sql
|
|
54
|
+
this.sql.append('IF NOT EXISTS ');
|
|
51
55
|
return this;
|
|
52
56
|
}
|
|
53
57
|
createColumnType(column) {
|
|
54
|
-
this.sql
|
|
58
|
+
this.sql.append(this.columnTypes[column.type]);
|
|
55
59
|
if ('length' in column) {
|
|
56
|
-
this.sql
|
|
60
|
+
this.sql.append(`(${column.length})`);
|
|
57
61
|
}
|
|
58
62
|
if ('significant' in column && 'decimal' in column) {
|
|
59
63
|
const significant = column.significant + column.decimal;
|
|
60
64
|
const decimal = column.decimal;
|
|
61
|
-
this.sql
|
|
65
|
+
this.sql.append(`(${significant}, ${decimal})`);
|
|
62
66
|
}
|
|
63
|
-
this.sql
|
|
67
|
+
this.sql.space();
|
|
64
68
|
return this;
|
|
65
69
|
}
|
|
66
70
|
columnRequired() {
|
|
67
|
-
this.sql
|
|
71
|
+
this.sql.append('NOT NULL ');
|
|
68
72
|
return this;
|
|
69
73
|
}
|
|
70
74
|
columnDefaultValue(column) {
|
|
71
|
-
this.sql
|
|
75
|
+
this.sql.append('DEFAULT ');
|
|
72
76
|
if (column.default === null) {
|
|
73
77
|
this.columnDefaultNull();
|
|
74
78
|
}
|
|
@@ -78,33 +82,33 @@ class DataDefinitionBuilder extends builder_1.Builder {
|
|
|
78
82
|
else if (column.default === false) {
|
|
79
83
|
this.columnDefaultFalse();
|
|
80
84
|
}
|
|
81
|
-
else if (
|
|
82
|
-
this.databaseFunction(column.default);
|
|
85
|
+
else if ((0, functions_1.isDatabaseFunction)(column.default)) {
|
|
86
|
+
this.sql.databaseFunction(column.default);
|
|
83
87
|
}
|
|
84
88
|
else {
|
|
85
|
-
this.sql
|
|
89
|
+
this.sql.append(column.default + ' ');
|
|
86
90
|
}
|
|
87
91
|
return this;
|
|
88
92
|
}
|
|
89
93
|
columnDefaultNull() {
|
|
90
|
-
this.sql
|
|
94
|
+
this.sql.append('NULL ');
|
|
91
95
|
return this;
|
|
92
96
|
}
|
|
93
97
|
columnDefaultTrue() {
|
|
94
|
-
this.sql
|
|
98
|
+
this.sql.append('TRUE ');
|
|
95
99
|
return this;
|
|
96
100
|
}
|
|
97
101
|
columnDefaultFalse() {
|
|
98
|
-
this.sql
|
|
102
|
+
this.sql.append('FALSE ');
|
|
99
103
|
return this;
|
|
100
104
|
}
|
|
101
105
|
columnAutoIncrement() {
|
|
102
|
-
this.sql
|
|
106
|
+
this.sql.append('AUTO_INCREMENT ');
|
|
103
107
|
return this;
|
|
104
108
|
}
|
|
105
109
|
createTableColumn(column) {
|
|
106
|
-
this.columnName(column.name);
|
|
107
|
-
this.sql
|
|
110
|
+
this.sql.columnName(column.name);
|
|
111
|
+
this.sql.space();
|
|
108
112
|
this.createColumnType(column);
|
|
109
113
|
if (column.default !== undefined) {
|
|
110
114
|
this.columnDefaultValue(column);
|
|
@@ -115,36 +119,39 @@ class DataDefinitionBuilder extends builder_1.Builder {
|
|
|
115
119
|
if (column.required) {
|
|
116
120
|
this.columnRequired();
|
|
117
121
|
}
|
|
118
|
-
this.trimEnd(' ');
|
|
122
|
+
this.sql.trimEnd(' ');
|
|
123
|
+
return this;
|
|
124
|
+
}
|
|
125
|
+
createTablePrimaryKeys(names) {
|
|
126
|
+
this.sql.append(', PRIMARY KEY (');
|
|
127
|
+
this.sql.append(names.map((key) => this.sql.getEnclosedName(key)).join(','));
|
|
128
|
+
this.sql.append(')');
|
|
119
129
|
return this;
|
|
120
130
|
}
|
|
121
131
|
createTableColumns(options) {
|
|
122
132
|
var _a;
|
|
123
|
-
this.sql
|
|
133
|
+
this.sql.append('(');
|
|
124
134
|
for (const column of options.columns) {
|
|
125
135
|
this.createTableColumn(column);
|
|
126
|
-
this.sql
|
|
136
|
+
this.sql.append(', ');
|
|
127
137
|
}
|
|
128
|
-
this.trimEnd(', ');
|
|
138
|
+
this.sql.trimEnd(', ');
|
|
129
139
|
const primaryKeys = options.columns
|
|
130
140
|
.filter((column) => column.primaryKey)
|
|
131
141
|
.map((column) => column.name);
|
|
132
142
|
if (primaryKeys.length > 0) {
|
|
133
|
-
this.
|
|
134
|
-
', PRIMARY KEY (' +
|
|
135
|
-
primaryKeys.map((key) => this.getEnclosedName(key)).join(',') +
|
|
136
|
-
')';
|
|
143
|
+
this.createTablePrimaryKeys(primaryKeys);
|
|
137
144
|
}
|
|
138
145
|
for (const uniqueColumn of options.columns.filter((column) => column.isUnique)) {
|
|
139
|
-
this.sql
|
|
146
|
+
this.sql.append(', ');
|
|
140
147
|
this.uniqueConstraint(options.name, uniqueColumn.name);
|
|
141
148
|
}
|
|
142
149
|
for (const fk of (_a = options.foreignKeys) !== null && _a !== void 0 ? _a : []) {
|
|
143
|
-
this.sql
|
|
150
|
+
this.sql.append(', ');
|
|
144
151
|
this.foreignKeyConstraint(options.name, fk);
|
|
145
152
|
}
|
|
146
|
-
this.trimEnd(' ');
|
|
147
|
-
this.sql
|
|
153
|
+
this.sql.trimEnd(' ');
|
|
154
|
+
this.sql.append(')');
|
|
148
155
|
return this;
|
|
149
156
|
}
|
|
150
157
|
createTable(options) {
|
|
@@ -152,33 +159,33 @@ class DataDefinitionBuilder extends builder_1.Builder {
|
|
|
152
159
|
if (options.ifNotExists) {
|
|
153
160
|
this.ifNotExists();
|
|
154
161
|
}
|
|
155
|
-
this.tableName(options.name);
|
|
156
|
-
this.sql
|
|
162
|
+
this.sql.tableName(options.name);
|
|
163
|
+
this.sql.space();
|
|
157
164
|
this.createTableColumns(options);
|
|
158
165
|
return this;
|
|
159
166
|
}
|
|
160
167
|
constraintStatement() {
|
|
161
|
-
this.sql
|
|
168
|
+
this.sql.append('CONSTRAINT ');
|
|
162
169
|
return this;
|
|
163
170
|
}
|
|
164
171
|
// ------------------------------------------------------------------------
|
|
165
172
|
// Grant permissions
|
|
166
173
|
// ------------------------------------------------------------------------
|
|
167
174
|
grantOnDatabase(database) {
|
|
168
|
-
this.sql
|
|
175
|
+
this.sql.append(database + '.*');
|
|
169
176
|
return this;
|
|
170
177
|
}
|
|
171
178
|
grantOn(on) {
|
|
172
179
|
if (on === '*') {
|
|
173
|
-
this.sql
|
|
180
|
+
this.sql.append('*.*');
|
|
174
181
|
}
|
|
175
182
|
else if ('database' in on && 'table' in on) {
|
|
176
|
-
this.sql
|
|
183
|
+
this.sql.append(on.database + '.' + on.table);
|
|
177
184
|
}
|
|
178
185
|
else if ('database' in on) {
|
|
179
186
|
this.grantOnDatabase(on.database);
|
|
180
187
|
}
|
|
181
|
-
this.sql
|
|
188
|
+
this.sql.space();
|
|
182
189
|
return this;
|
|
183
190
|
}
|
|
184
191
|
/**
|
|
@@ -200,46 +207,46 @@ class DataDefinitionBuilder extends builder_1.Builder {
|
|
|
200
207
|
if (!Array.isArray(options.to)) {
|
|
201
208
|
options.to = [options.to];
|
|
202
209
|
}
|
|
203
|
-
this.sql
|
|
204
|
-
this.sql
|
|
205
|
-
this.sql
|
|
210
|
+
this.sql.append('GRANT ');
|
|
211
|
+
this.sql.append(options.privileges.join(', ') + ' ');
|
|
212
|
+
this.sql.append('ON ');
|
|
206
213
|
this.grantOn(options.on);
|
|
207
|
-
this.sql
|
|
214
|
+
this.sql.append('TO ' + options.to.join(', ') + ' ');
|
|
208
215
|
return this;
|
|
209
216
|
}
|
|
210
217
|
// ------------------------------------------------------------------------
|
|
211
218
|
// Foreign Key Constraint
|
|
212
219
|
// ------------------------------------------------------------------------
|
|
213
220
|
foreignKeyStatement() {
|
|
214
|
-
this.sql
|
|
221
|
+
this.sql.append('FOREIGN KEY ');
|
|
215
222
|
return this;
|
|
216
223
|
}
|
|
217
224
|
foreignKeyName(childTable, fk) {
|
|
218
225
|
var _a;
|
|
219
|
-
this.sql
|
|
220
|
-
this.sql
|
|
226
|
+
this.sql.append((_a = fk.name) !== null && _a !== void 0 ? _a : `fk_${childTable}_${fk.columns.join('_')}`);
|
|
227
|
+
this.sql.space();
|
|
221
228
|
return this;
|
|
222
229
|
}
|
|
223
230
|
foreignKeyColumns(columns) {
|
|
224
|
-
this.openParens();
|
|
225
|
-
this.commaSeparate(columns.map((column) => this.getEnclosedName(column)));
|
|
226
|
-
this.closeParens();
|
|
231
|
+
this.sql.openParens();
|
|
232
|
+
this.sql.commaSeparate(columns.map((column) => this.sql.getEnclosedName(column)));
|
|
233
|
+
this.sql.closeParens();
|
|
227
234
|
return this;
|
|
228
235
|
}
|
|
229
236
|
referencesStatement(table, columns) {
|
|
230
|
-
this.sql
|
|
231
|
-
this.tableName(table);
|
|
232
|
-
this.openParens();
|
|
233
|
-
this.commaSeparate(columns.map((column) => this.getEnclosedName(column)));
|
|
234
|
-
this.closeParens();
|
|
237
|
+
this.sql.append('REFERENCES ');
|
|
238
|
+
this.sql.tableName(table);
|
|
239
|
+
this.sql.openParens();
|
|
240
|
+
this.sql.commaSeparate(columns.map((column) => this.sql.getEnclosedName(column)));
|
|
241
|
+
this.sql.closeParens();
|
|
235
242
|
return this;
|
|
236
243
|
}
|
|
237
244
|
fkOnUpdate(option) {
|
|
238
|
-
this.sql
|
|
245
|
+
this.sql.append('ON UPDATE ' + option + ' ');
|
|
239
246
|
return this;
|
|
240
247
|
}
|
|
241
248
|
fkOnDelete(option) {
|
|
242
|
-
this.sql
|
|
249
|
+
this.sql.append('ON DELETE ' + option + ' ');
|
|
243
250
|
return this;
|
|
244
251
|
}
|
|
245
252
|
foreignKeyConstraint(childTable, fk) {
|
|
@@ -259,39 +266,39 @@ class DataDefinitionBuilder extends builder_1.Builder {
|
|
|
259
266
|
// Constraints
|
|
260
267
|
// ------------------------------------------------------------------------
|
|
261
268
|
uniqueConstraint(table, column) {
|
|
262
|
-
this.sql
|
|
263
|
-
this.sql
|
|
269
|
+
this.sql.append(`CONSTRAINT uq_${table}_${column} `);
|
|
270
|
+
this.sql.append('UNIQUE(' + this.sql.getEnclosedName(column) + ')');
|
|
264
271
|
return this;
|
|
265
272
|
}
|
|
266
273
|
// ------------------------------------------------------------------------
|
|
267
274
|
// Alter Table
|
|
268
275
|
// ------------------------------------------------------------------------
|
|
269
276
|
alterTableStatement(table) {
|
|
270
|
-
this.sql
|
|
271
|
-
this.tableName(table);
|
|
272
|
-
this.sql
|
|
277
|
+
this.sql.append('ALTER TABLE ');
|
|
278
|
+
this.sql.tableName(table);
|
|
279
|
+
this.sql.space();
|
|
273
280
|
return this;
|
|
274
281
|
}
|
|
275
282
|
addColumns(options) {
|
|
276
283
|
this.alterTableStatement(options.table);
|
|
277
|
-
this.sql
|
|
284
|
+
this.sql.append('ADD ');
|
|
278
285
|
for (const column of options.columns) {
|
|
279
286
|
this.createTableColumn(column);
|
|
280
|
-
this.sql
|
|
287
|
+
this.sql.append(', ');
|
|
281
288
|
}
|
|
282
|
-
this.trimEnd(', ');
|
|
289
|
+
this.sql.trimEnd(', ');
|
|
283
290
|
return this;
|
|
284
291
|
}
|
|
285
292
|
addForeignKey(options) {
|
|
286
293
|
this.alterTableStatement(options.table);
|
|
287
|
-
this.sql
|
|
294
|
+
this.sql.append('ADD ');
|
|
288
295
|
this.foreignKeyConstraint(options.table, options);
|
|
289
296
|
return this;
|
|
290
297
|
}
|
|
291
298
|
alterColumnStatement(column) {
|
|
292
|
-
this.sql
|
|
293
|
-
this.columnName(column);
|
|
294
|
-
this.sql
|
|
299
|
+
this.sql.append('ALTER COLUMN ');
|
|
300
|
+
this.sql.columnName(column);
|
|
301
|
+
this.sql.space();
|
|
295
302
|
return this;
|
|
296
303
|
}
|
|
297
304
|
changeColumn(options) {
|
|
@@ -302,32 +309,32 @@ class DataDefinitionBuilder extends builder_1.Builder {
|
|
|
302
309
|
}
|
|
303
310
|
dropColumn(options) {
|
|
304
311
|
this.alterTableStatement(options.table);
|
|
305
|
-
this.sql
|
|
306
|
-
this.columnName(options.column);
|
|
312
|
+
this.sql.append('DROP COLUMN ');
|
|
313
|
+
this.sql.columnName(options.column);
|
|
307
314
|
return this;
|
|
308
315
|
}
|
|
309
316
|
dropForeignKey(options) {
|
|
310
317
|
this.alterTableStatement(options.table);
|
|
311
|
-
this.sql
|
|
318
|
+
this.sql.append('DROP ');
|
|
312
319
|
this.foreignKeyStatement();
|
|
313
|
-
this.sql
|
|
320
|
+
this.sql.append(options.fk);
|
|
314
321
|
return this;
|
|
315
322
|
}
|
|
316
323
|
renameTable(options) {
|
|
317
324
|
this.alterTableStatement(options.table);
|
|
318
|
-
this.sql
|
|
319
|
-
this.tableName(options.to);
|
|
325
|
+
this.sql.append('RENAME ');
|
|
326
|
+
this.sql.tableName(options.to);
|
|
320
327
|
return this;
|
|
321
328
|
}
|
|
322
329
|
// ------------------------------------------------------------------------
|
|
323
330
|
// Drop Database
|
|
324
331
|
// ------------------------------------------------------------------------
|
|
325
332
|
dropDatabase(options) {
|
|
326
|
-
this.sql
|
|
333
|
+
this.sql.append('DROP DATABASE ');
|
|
327
334
|
if (options.ifExists) {
|
|
328
|
-
this.sql
|
|
335
|
+
this.sql.append('IF EXISTS ');
|
|
329
336
|
}
|
|
330
|
-
this.sql
|
|
337
|
+
this.sql.append(options.name);
|
|
331
338
|
return this;
|
|
332
339
|
}
|
|
333
340
|
// ------------------------------------------------------------------------
|
|
@@ -337,14 +344,14 @@ class DataDefinitionBuilder extends builder_1.Builder {
|
|
|
337
344
|
if (Array.isArray(options.tables)) {
|
|
338
345
|
options.tables = options.tables.join(',');
|
|
339
346
|
}
|
|
340
|
-
this.sql
|
|
347
|
+
this.sql.append('DROP TABLE ');
|
|
341
348
|
if (options.ifExists) {
|
|
342
|
-
this.sql
|
|
349
|
+
this.sql.append('IF EXISTS ');
|
|
343
350
|
}
|
|
344
|
-
this.sql
|
|
351
|
+
this.sql.append(options.tables
|
|
345
352
|
.split(',')
|
|
346
|
-
.map((table) => this.getEnclosedName(table))
|
|
347
|
-
.join(',');
|
|
353
|
+
.map((table) => this.sql.getEnclosedName(table))
|
|
354
|
+
.join(','));
|
|
348
355
|
return this;
|
|
349
356
|
}
|
|
350
357
|
// ------------------------------------------------------------------------
|
|
@@ -354,19 +361,19 @@ class DataDefinitionBuilder extends builder_1.Builder {
|
|
|
354
361
|
if (Array.isArray(options.names)) {
|
|
355
362
|
options.names = options.names.join(',');
|
|
356
363
|
}
|
|
357
|
-
this.sql
|
|
364
|
+
this.sql.append('DROP USER ');
|
|
358
365
|
if (options.ifExists) {
|
|
359
|
-
this.sql
|
|
366
|
+
this.sql.append('IF EXISTS ');
|
|
360
367
|
}
|
|
361
|
-
this.sql
|
|
368
|
+
this.sql.append(options.names);
|
|
362
369
|
return this;
|
|
363
370
|
}
|
|
364
371
|
// ------------------------------------------------------------------------
|
|
365
372
|
// Truncate Table
|
|
366
373
|
// ------------------------------------------------------------------------
|
|
367
374
|
truncate(options) {
|
|
368
|
-
this.sql
|
|
369
|
-
this.tableName(options.table);
|
|
375
|
+
this.sql.append('TRUNCATE TABLE ');
|
|
376
|
+
this.sql.tableName(options.table);
|
|
370
377
|
return this;
|
|
371
378
|
}
|
|
372
379
|
}
|