@riao/dbal 3.8.0 → 3.9.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.
Files changed (269) hide show
  1. package/CHANGELOG.md +3 -3
  2. package/LICENSE.md +20 -20
  3. package/README.md +148 -148
  4. package/builder/builder.d.ts +7 -7
  5. package/builder/builder.js +19 -19
  6. package/builder/index.d.ts +2 -2
  7. package/builder/index.js +7 -7
  8. package/builder/sql-builder.d.ts +54 -53
  9. package/builder/sql-builder.js +161 -157
  10. package/builder/sql-builder.js.map +1 -1
  11. package/builder/statement-builder.d.ts +12 -12
  12. package/builder/statement-builder.js +32 -32
  13. package/column/column-options.d.ts +156 -156
  14. package/column/column-options.js +2 -2
  15. package/column/column-type.d.ts +18 -18
  16. package/column/column-type.js +27 -27
  17. package/column/column-values.d.ts +34 -34
  18. package/column/column-values.js +2 -2
  19. package/column/create-column-template.d.ts +11 -0
  20. package/column/create-column-template.js +57 -0
  21. package/column/create-column-template.js.map +1 -0
  22. package/column/index.d.ts +4 -3
  23. package/column/index.js +20 -19
  24. package/column/index.js.map +1 -1
  25. package/column-pack/date-time/create-timestamp-column.d.ts +2 -2
  26. package/column-pack/date-time/create-timestamp-column.js +10 -10
  27. package/column-pack/date-time/index.d.ts +2 -2
  28. package/column-pack/date-time/index.js +7 -7
  29. package/column-pack/date-time/update-timestamp-column.d.ts +2 -2
  30. package/column-pack/date-time/update-timestamp-column.js +14 -14
  31. package/column-pack/index.d.ts +6 -6
  32. package/column-pack/index.js +22 -22
  33. package/column-pack/keys/big-int-key-column.d.ts +2 -2
  34. package/column-pack/keys/big-int-key-column.js +10 -10
  35. package/column-pack/keys/index.d.ts +3 -3
  36. package/column-pack/keys/index.js +9 -9
  37. package/column-pack/keys/int-key-column.d.ts +2 -2
  38. package/column-pack/keys/int-key-column.js +10 -10
  39. package/column-pack/keys/uuid-key-column.d.ts +2 -2
  40. package/column-pack/keys/uuid-key-column.js +11 -11
  41. package/column-pack/person/date-of-birth-column.d.ts +2 -2
  42. package/column-pack/person/date-of-birth-column.js +8 -8
  43. package/column-pack/person/first-name-column.d.ts +2 -2
  44. package/column-pack/person/first-name-column.js +9 -9
  45. package/column-pack/person/index.d.ts +3 -3
  46. package/column-pack/person/index.js +9 -9
  47. package/column-pack/person/last-name-column.d.ts +2 -2
  48. package/column-pack/person/last-name-column.js +9 -9
  49. package/column-pack/resource/content-column.d.ts +2 -2
  50. package/column-pack/resource/content-column.js +9 -9
  51. package/column-pack/resource/description-column.d.ts +2 -2
  52. package/column-pack/resource/description-column.js +9 -9
  53. package/column-pack/resource/index.d.ts +6 -6
  54. package/column-pack/resource/index.js +15 -15
  55. package/column-pack/resource/is-active-column.d.ts +2 -2
  56. package/column-pack/resource/is-active-column.js +9 -9
  57. package/column-pack/resource/name-column.d.ts +2 -2
  58. package/column-pack/resource/name-column.js +10 -10
  59. package/column-pack/resource/path-column.d.ts +2 -2
  60. package/column-pack/resource/path-column.js +11 -11
  61. package/column-pack/resource/title-column.d.ts +2 -2
  62. package/column-pack/resource/title-column.js +10 -10
  63. package/column-pack/system/filename-column.d.ts +2 -2
  64. package/column-pack/system/filename-column.js +9 -9
  65. package/column-pack/system/filepath-column.d.ts +2 -2
  66. package/column-pack/system/filepath-column.js +9 -9
  67. package/column-pack/system/index.d.ts +4 -4
  68. package/column-pack/system/index.js +11 -11
  69. package/column-pack/system/ip-address-column.d.ts +2 -2
  70. package/column-pack/system/ip-address-column.js +9 -9
  71. package/column-pack/system/url-column.d.ts +3 -3
  72. package/column-pack/system/url-column.js +13 -13
  73. package/column-pack/user/email-column.d.ts +2 -2
  74. package/column-pack/user/email-column.js +11 -11
  75. package/column-pack/user/index.d.ts +4 -4
  76. package/column-pack/user/index.js +11 -11
  77. package/column-pack/user/password-column.d.ts +2 -2
  78. package/column-pack/user/password-column.js +10 -10
  79. package/column-pack/user/temp-email-column.d.ts +2 -2
  80. package/column-pack/user/temp-email-column.js +5 -5
  81. package/column-pack/user/username-column.d.ts +2 -2
  82. package/column-pack/user/username-column.js +11 -11
  83. package/comparison/comparison-aliases.d.ts +10 -10
  84. package/comparison/comparison-aliases.js +40 -40
  85. package/comparison/comparison-token.d.ts +17 -17
  86. package/comparison/comparison-token.js +15 -15
  87. package/comparison/comparison.d.ts +13 -13
  88. package/comparison/comparison.js +71 -71
  89. package/comparison/index.d.ts +4 -4
  90. package/comparison/index.js +24 -24
  91. package/comparison/is-comparison-token.d.ts +2 -2
  92. package/comparison/is-comparison-token.js +8 -8
  93. package/config/configure-db.d.ts +14 -14
  94. package/config/configure-db.js +18 -18
  95. package/config/database-env.d.ts +16 -16
  96. package/config/database-env.js +14 -14
  97. package/config/index.d.ts +2 -2
  98. package/config/index.js +7 -7
  99. package/database/connection-options.d.ts +7 -7
  100. package/database/connection-options.js +2 -2
  101. package/database/database.d.ts +204 -204
  102. package/database/database.js +330 -330
  103. package/database/driver-query.d.ts +10 -10
  104. package/database/driver-query.js +2 -2
  105. package/database/driver.d.ts +12 -12
  106. package/database/driver.js +47 -47
  107. package/database/get-database-path.d.ts +6 -6
  108. package/database/get-database-path.js +12 -12
  109. package/database/index.d.ts +7 -7
  110. package/database/index.js +26 -26
  111. package/database/load-database.d.ts +9 -9
  112. package/database/load-database.js +36 -36
  113. package/database/transaction.d.ts +8 -8
  114. package/database/transaction.js +2 -2
  115. package/ddl/alter-table.d.ts +26 -26
  116. package/ddl/alter-table.js +2 -2
  117. package/ddl/create-database.d.ts +3 -3
  118. package/ddl/create-database.js +2 -2
  119. package/ddl/create-index.d.ts +5 -5
  120. package/ddl/create-index.js +2 -2
  121. package/ddl/create-table.d.ts +8 -8
  122. package/ddl/create-table.js +2 -2
  123. package/ddl/create-user.d.ts +4 -4
  124. package/ddl/create-user.js +2 -2
  125. package/ddl/ddl-builder.d.ts +96 -96
  126. package/ddl/ddl-builder.js +565 -565
  127. package/ddl/ddl-repository.d.ts +135 -135
  128. package/ddl/ddl-repository.js +228 -228
  129. package/ddl/drop-database.d.ts +4 -4
  130. package/ddl/drop-database.js +2 -2
  131. package/ddl/drop-table.d.ts +4 -4
  132. package/ddl/drop-table.js +2 -2
  133. package/ddl/drop-user.d.ts +4 -4
  134. package/ddl/drop-user.js +2 -2
  135. package/ddl/foreign-key-constraint.d.ts +19 -19
  136. package/ddl/foreign-key-constraint.js +2 -2
  137. package/ddl/grant.d.ts +12 -12
  138. package/ddl/grant.js +2 -2
  139. package/ddl/index.d.ts +13 -13
  140. package/ddl/index.js +23 -23
  141. package/ddl/truncate.d.ts +3 -3
  142. package/ddl/truncate.js +2 -2
  143. package/dml/case-expression.d.ts +16 -16
  144. package/dml/case-expression.js +11 -11
  145. package/dml/delete.d.ts +8 -8
  146. package/dml/delete.js +2 -2
  147. package/dml/from.d.ts +4 -4
  148. package/dml/from.js +2 -2
  149. package/dml/group-by.d.ts +4 -4
  150. package/dml/group-by.js +2 -2
  151. package/dml/index.d.ts +11 -11
  152. package/dml/index.js +30 -30
  153. package/dml/insert.d.ts +14 -14
  154. package/dml/insert.js +2 -2
  155. package/dml/join.d.ts +7 -7
  156. package/dml/join.js +2 -2
  157. package/dml/order-by.d.ts +2 -2
  158. package/dml/order-by.js +2 -2
  159. package/dml/query-builder.d.ts +125 -106
  160. package/dml/query-builder.js +991 -793
  161. package/dml/query-builder.js.map +1 -1
  162. package/dml/query-repository.d.ts +84 -84
  163. package/dml/query-repository.js +239 -225
  164. package/dml/query-repository.js.map +1 -1
  165. package/dml/select.d.ts +44 -29
  166. package/dml/select.js +2 -2
  167. package/dml/set-options.d.ts +5 -5
  168. package/dml/set-options.js +2 -2
  169. package/dml/subquery.d.ts +5 -5
  170. package/dml/subquery.js +10 -10
  171. package/dml/update.d.ts +11 -11
  172. package/dml/update.js +2 -2
  173. package/expression/expression-token.d.ts +11 -11
  174. package/expression/expression-token.js +12 -12
  175. package/expression/expression.d.ts +6 -6
  176. package/expression/expression.js +2 -2
  177. package/expression/identifier.d.ts +7 -7
  178. package/expression/identifier.js +15 -15
  179. package/expression/index.d.ts +7 -7
  180. package/expression/index.js +25 -25
  181. package/expression/is-expression-token.d.ts +2 -2
  182. package/expression/is-expression-token.js +7 -7
  183. package/expression/key-val-expression.d.ts +7 -7
  184. package/expression/key-val-expression.js +2 -2
  185. package/expression/literal.d.ts +3 -3
  186. package/expression/literal.js +2 -2
  187. package/expression/logical.d.ts +28 -18
  188. package/expression/logical.js +54 -30
  189. package/expression/logical.js.map +1 -1
  190. package/expression/math.d.ts +17 -17
  191. package/expression/math.js +36 -36
  192. package/expression/raw.d.ts +8 -8
  193. package/expression/raw.js +16 -16
  194. package/expression/simple-expression.d.ts +8 -8
  195. package/expression/simple-expression.js +2 -2
  196. package/functions/function-aliases.d.ts +6 -4
  197. package/functions/function-aliases.js +16 -12
  198. package/functions/function-aliases.js.map +1 -1
  199. package/functions/function-token.d.ts +33 -29
  200. package/functions/function-token.js +19 -15
  201. package/functions/function-token.js.map +1 -1
  202. package/functions/functions.d.ts +23 -19
  203. package/functions/functions.js +126 -94
  204. package/functions/functions.js.map +1 -1
  205. package/functions/index.d.ts +4 -4
  206. package/functions/index.js +22 -22
  207. package/functions/is-database-function.d.ts +8 -8
  208. package/functions/is-database-function.js +14 -14
  209. package/functions/signatures/count.d.ts +14 -11
  210. package/functions/signatures/count.js +2 -2
  211. package/index.d.ts +16 -16
  212. package/index.js +32 -32
  213. package/migration/index.d.ts +3 -3
  214. package/migration/index.js +9 -9
  215. package/migration/migration-package.d.ts +14 -14
  216. package/migration/migration-package.js +10 -10
  217. package/migration/migration-record.d.ts +10 -10
  218. package/migration/migration-record.js +2 -2
  219. package/migration/migration-runner.d.ts +33 -33
  220. package/migration/migration-runner.js +180 -180
  221. package/migration/migration.d.ts +12 -12
  222. package/migration/migration.js +27 -27
  223. package/migration/migrations/001-create-migration-table.d.ts +8 -8
  224. package/migration/migrations/001-create-migration-table.js +54 -54
  225. package/migration/migrations/002-add-migration-package-column.d.ts +9 -9
  226. package/migration/migrations/002-add-migration-package-column.js +44 -44
  227. package/package.json +1 -1
  228. package/record/index.d.ts +1 -1
  229. package/record/index.js +17 -17
  230. package/record/record.d.ts +2 -2
  231. package/record/record.js +2 -2
  232. package/repository/index.d.ts +2 -2
  233. package/repository/index.js +5 -5
  234. package/repository/repository-options.d.ts +6 -6
  235. package/repository/repository-options.js +2 -2
  236. package/repository/repository.d.ts +29 -29
  237. package/repository/repository.js +68 -68
  238. package/schema/index.d.ts +3 -3
  239. package/schema/index.js +5 -5
  240. package/schema/schema-query-repository.d.ts +54 -54
  241. package/schema/schema-query-repository.js +159 -159
  242. package/schema/schema-table.d.ts +9 -9
  243. package/schema/schema-table.js +2 -2
  244. package/schema/schema.d.ts +4 -4
  245. package/schema/schema.js +2 -2
  246. package/seed/auto-seed.d.ts +9 -9
  247. package/seed/auto-seed.js +61 -61
  248. package/seed/create-seed-table.d.ts +8 -8
  249. package/seed/create-seed-table.js +64 -64
  250. package/seed/index.d.ts +4 -4
  251. package/seed/index.js +9 -9
  252. package/seed/seed-record.d.ts +11 -11
  253. package/seed/seed-record.js +2 -2
  254. package/seed/seed-runner.d.ts +20 -20
  255. package/seed/seed-runner.js +91 -91
  256. package/seed/seed.d.ts +12 -12
  257. package/seed/seed.js +27 -27
  258. package/tokens/index.d.ts +1 -1
  259. package/tokens/index.js +5 -5
  260. package/triggers/index.d.ts +2 -2
  261. package/triggers/index.js +18 -18
  262. package/triggers/prebuilt/index.d.ts +1 -1
  263. package/triggers/prebuilt/index.js +5 -5
  264. package/triggers/prebuilt/update-timestamp-trigger.d.ts +16 -16
  265. package/triggers/prebuilt/update-timestamp-trigger.js +24 -24
  266. package/triggers/trigger-options.d.ts +22 -22
  267. package/triggers/trigger-options.js +2 -2
  268. package/triggers/trigger.d.ts +19 -19
  269. package/triggers/trigger.js +23 -23
@@ -1,54 +1,54 @@
1
- import { DatabaseRecord } from '../record';
2
- import { ColumnOptions } from '../column';
3
- import { DatabaseQueryBuilder, QueryRepository } from '../dml';
4
- import { SchemaTable, SchemaTableWithColumns } from './schema-table';
5
- import { Schema } from './schema';
6
- import { RepositoryInit, RepositoryOptions } from '../repository';
7
- export interface SchemaQueryRepositoryOptions extends RepositoryOptions {
8
- queryBuilderType: typeof DatabaseQueryBuilder;
9
- }
10
- export interface SchemaQueryRepositoryInit extends RepositoryInit {
11
- database: string;
12
- }
13
- /**
14
- * Use the Schema Query Repository to query your schema information
15
- */
16
- export declare class SchemaQueryRepository extends QueryRepository {
17
- protected database: string;
18
- protected tablesTable: string;
19
- protected columnsTable: string;
20
- protected databaseNameColumn: string;
21
- protected tableNameColumn: string;
22
- protected tableTypeColumn: string;
23
- protected columnNameColumn: string;
24
- protected columnTypeColumn: string;
25
- protected columnPositionColumn: string;
26
- protected returnedTableTypes: Record<any, 'table' | 'view'>;
27
- constructor(options: SchemaQueryRepositoryOptions);
28
- init(options: SchemaQueryRepositoryInit): void;
29
- getSchema(): Promise<Schema>;
30
- protected getTablesQueryWhere(): {
31
- [x: string]: string;
32
- };
33
- protected getTablesQuery(): Promise<DatabaseRecord[]>;
34
- protected getTablesResultParser(tables: DatabaseRecord[]): {
35
- name: any;
36
- type: "table" | "view";
37
- }[];
38
- getTables(): Promise<SchemaTable[]>;
39
- getTablesWithColumns(): Promise<SchemaTableWithColumns[]>;
40
- protected getPrimaryKeyResultParser(result?: DatabaseRecord): undefined | string;
41
- protected getPrimaryKeyQuery(table: string): Promise<null | DatabaseRecord>;
42
- getPrimaryKeyName(options: {
43
- table: string;
44
- }): Promise<undefined | string>;
45
- protected getColumnsQuery(table: string): Promise<DatabaseRecord[]>;
46
- protected getColumnsResultParser(options: {
47
- records: DatabaseRecord[];
48
- primaryKey?: string;
49
- }): ColumnOptions[];
50
- getColumns(options: {
51
- table: string;
52
- primaryKey?: string;
53
- }): Promise<ColumnOptions[]>;
54
- }
1
+ import { DatabaseRecord } from '../record';
2
+ import { ColumnOptions } from '../column';
3
+ import { DatabaseQueryBuilder, QueryRepository } from '../dml';
4
+ import { SchemaTable, SchemaTableWithColumns } from './schema-table';
5
+ import { Schema } from './schema';
6
+ import { RepositoryInit, RepositoryOptions } from '../repository';
7
+ export interface SchemaQueryRepositoryOptions extends RepositoryOptions {
8
+ queryBuilderType: typeof DatabaseQueryBuilder;
9
+ }
10
+ export interface SchemaQueryRepositoryInit extends RepositoryInit {
11
+ database: string;
12
+ }
13
+ /**
14
+ * Use the Schema Query Repository to query your schema information
15
+ */
16
+ export declare class SchemaQueryRepository extends QueryRepository {
17
+ protected database: string;
18
+ protected tablesTable: string;
19
+ protected columnsTable: string;
20
+ protected databaseNameColumn: string;
21
+ protected tableNameColumn: string;
22
+ protected tableTypeColumn: string;
23
+ protected columnNameColumn: string;
24
+ protected columnTypeColumn: string;
25
+ protected columnPositionColumn: string;
26
+ protected returnedTableTypes: Record<any, 'table' | 'view'>;
27
+ constructor(options: SchemaQueryRepositoryOptions);
28
+ init(options: SchemaQueryRepositoryInit): void;
29
+ getSchema(): Promise<Schema>;
30
+ protected getTablesQueryWhere(): {
31
+ [x: string]: string;
32
+ };
33
+ protected getTablesQuery(): Promise<DatabaseRecord[]>;
34
+ protected getTablesResultParser(tables: DatabaseRecord[]): {
35
+ name: any;
36
+ type: "table" | "view";
37
+ }[];
38
+ getTables(): Promise<SchemaTable[]>;
39
+ getTablesWithColumns(): Promise<SchemaTableWithColumns[]>;
40
+ protected getPrimaryKeyResultParser(result?: DatabaseRecord): undefined | string;
41
+ protected getPrimaryKeyQuery(table: string): Promise<null | DatabaseRecord>;
42
+ getPrimaryKeyName(options: {
43
+ table: string;
44
+ }): Promise<undefined | string>;
45
+ protected getColumnsQuery(table: string): Promise<DatabaseRecord[]>;
46
+ protected getColumnsResultParser(options: {
47
+ records: DatabaseRecord[];
48
+ primaryKey?: string;
49
+ }): ColumnOptions[];
50
+ getColumns(options: {
51
+ table: string;
52
+ primaryKey?: string;
53
+ }): Promise<ColumnOptions[]>;
54
+ }
@@ -1,160 +1,160 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.SchemaQueryRepository = void 0;
13
- const dml_1 = require("../dml");
14
- /**
15
- * Use the Schema Query Repository to query your schema information
16
- */
17
- class SchemaQueryRepository extends dml_1.QueryRepository {
18
- constructor(options) {
19
- var _a;
20
- super(options);
21
- this.tablesTable = 'information_schema.tables';
22
- this.columnsTable = 'information_schema.columns';
23
- this.databaseNameColumn = 'TABLE_SCHEMA';
24
- this.tableNameColumn = 'TABLE_NAME';
25
- this.tableTypeColumn = 'TABLE_TYPE';
26
- this.columnNameColumn = 'COLUMN_NAME';
27
- this.columnTypeColumn = 'DATA_TYPE';
28
- this.columnPositionColumn = 'ORDINAL_POSITION';
29
- this.returnedTableTypes = {
30
- 'BASE TABLE': 'table',
31
- VIEW: 'view',
32
- };
33
- this.queryBuilderType =
34
- (_a = options.queryBuilderType) !== null && _a !== void 0 ? _a : this.queryBuilderType;
35
- }
36
- init(options) {
37
- super.init(options);
38
- this.database = options.database;
39
- }
40
- getSchema() {
41
- return __awaiter(this, void 0, void 0, function* () {
42
- const tables = yield this.getTablesWithColumns();
43
- const mappedTables = {};
44
- for (const table of tables) {
45
- mappedTables[table.name] = table;
46
- }
47
- return {
48
- tables: mappedTables,
49
- };
50
- });
51
- }
52
- getTablesQueryWhere() {
53
- return { [this.databaseNameColumn]: this.database };
54
- }
55
- getTablesQuery() {
56
- return __awaiter(this, void 0, void 0, function* () {
57
- return yield this.find({
58
- table: this.tablesTable,
59
- columns: [this.tableNameColumn, this.tableTypeColumn],
60
- where: this.getTablesQueryWhere(),
61
- });
62
- });
63
- }
64
- getTablesResultParser(tables) {
65
- return tables.map((table) => ({
66
- name: table[this.tableNameColumn],
67
- type: this.returnedTableTypes[table[this.tableTypeColumn]],
68
- }));
69
- }
70
- getTables() {
71
- return __awaiter(this, void 0, void 0, function* () {
72
- const results = yield this.getTablesQuery();
73
- return this.getTablesResultParser(results);
74
- });
75
- }
76
- getTablesWithColumns() {
77
- return __awaiter(this, void 0, void 0, function* () {
78
- const tables = yield this.getTables();
79
- const out = [];
80
- for (const table of tables) {
81
- const tableName = table.name;
82
- const primaryKey = yield this.getPrimaryKeyName({
83
- table: tableName,
84
- });
85
- const columns = yield this.getColumns({
86
- table: tableName,
87
- primaryKey,
88
- });
89
- const mappedColumns = {};
90
- for (const column of columns) {
91
- mappedColumns[column.name] = column;
92
- }
93
- out.push({
94
- name: tableName,
95
- type: table.type,
96
- columns: mappedColumns,
97
- primaryKey,
98
- });
99
- }
100
- return out;
101
- });
102
- }
103
- getPrimaryKeyResultParser(result) {
104
- return result === null || result === void 0 ? void 0 : result[this.columnNameColumn];
105
- }
106
- getPrimaryKeyQuery(table) {
107
- return __awaiter(this, void 0, void 0, function* () {
108
- return yield this.findOne({
109
- table: this.columnsTable,
110
- columns: [this.columnNameColumn],
111
- where: {
112
- [this.databaseNameColumn]: this.database,
113
- [this.tableNameColumn]: table,
114
- COLUMN_KEY: 'PRI',
115
- },
116
- });
117
- });
118
- }
119
- getPrimaryKeyName(options) {
120
- return __awaiter(this, void 0, void 0, function* () {
121
- const result = yield this.getPrimaryKeyQuery(options.table);
122
- return this.getPrimaryKeyResultParser(result !== null && result !== void 0 ? result : undefined);
123
- });
124
- }
125
- getColumnsQuery(table) {
126
- return __awaiter(this, void 0, void 0, function* () {
127
- return yield this.find({
128
- table: this.columnsTable,
129
- columns: [this.columnNameColumn, this.columnTypeColumn],
130
- where: {
131
- [this.databaseNameColumn]: this.database,
132
- [this.tableNameColumn]: table,
133
- },
134
- orderBy: { [this.columnPositionColumn]: 'ASC' },
135
- });
136
- });
137
- }
138
- getColumnsResultParser(options) {
139
- return options.records.map((column) => ({
140
- name: column[this.columnNameColumn],
141
- type: column[this.columnTypeColumn]
142
- .toUpperCase()
143
- .replace('CHARACTER VARYING', 'VARCHAR'),
144
- primaryKey: column[this.columnNameColumn] === options.primaryKey,
145
- }));
146
- }
147
- getColumns(options) {
148
- var _a;
149
- return __awaiter(this, void 0, void 0, function* () {
150
- const primaryKey = (_a = options.primaryKey) !== null && _a !== void 0 ? _a : (yield this.getPrimaryKeyName({ table: options.table }));
151
- const results = yield this.getColumnsQuery(options.table);
152
- return this.getColumnsResultParser({
153
- records: results,
154
- primaryKey: primaryKey,
155
- });
156
- });
157
- }
158
- }
159
- exports.SchemaQueryRepository = SchemaQueryRepository;
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.SchemaQueryRepository = void 0;
13
+ const dml_1 = require("../dml");
14
+ /**
15
+ * Use the Schema Query Repository to query your schema information
16
+ */
17
+ class SchemaQueryRepository extends dml_1.QueryRepository {
18
+ constructor(options) {
19
+ var _a;
20
+ super(options);
21
+ this.tablesTable = 'information_schema.tables';
22
+ this.columnsTable = 'information_schema.columns';
23
+ this.databaseNameColumn = 'TABLE_SCHEMA';
24
+ this.tableNameColumn = 'TABLE_NAME';
25
+ this.tableTypeColumn = 'TABLE_TYPE';
26
+ this.columnNameColumn = 'COLUMN_NAME';
27
+ this.columnTypeColumn = 'DATA_TYPE';
28
+ this.columnPositionColumn = 'ORDINAL_POSITION';
29
+ this.returnedTableTypes = {
30
+ 'BASE TABLE': 'table',
31
+ VIEW: 'view',
32
+ };
33
+ this.queryBuilderType =
34
+ (_a = options.queryBuilderType) !== null && _a !== void 0 ? _a : this.queryBuilderType;
35
+ }
36
+ init(options) {
37
+ super.init(options);
38
+ this.database = options.database;
39
+ }
40
+ getSchema() {
41
+ return __awaiter(this, void 0, void 0, function* () {
42
+ const tables = yield this.getTablesWithColumns();
43
+ const mappedTables = {};
44
+ for (const table of tables) {
45
+ mappedTables[table.name] = table;
46
+ }
47
+ return {
48
+ tables: mappedTables,
49
+ };
50
+ });
51
+ }
52
+ getTablesQueryWhere() {
53
+ return { [this.databaseNameColumn]: this.database };
54
+ }
55
+ getTablesQuery() {
56
+ return __awaiter(this, void 0, void 0, function* () {
57
+ return yield this.find({
58
+ table: this.tablesTable,
59
+ columns: [this.tableNameColumn, this.tableTypeColumn],
60
+ where: this.getTablesQueryWhere(),
61
+ });
62
+ });
63
+ }
64
+ getTablesResultParser(tables) {
65
+ return tables.map((table) => ({
66
+ name: table[this.tableNameColumn],
67
+ type: this.returnedTableTypes[table[this.tableTypeColumn]],
68
+ }));
69
+ }
70
+ getTables() {
71
+ return __awaiter(this, void 0, void 0, function* () {
72
+ const results = yield this.getTablesQuery();
73
+ return this.getTablesResultParser(results);
74
+ });
75
+ }
76
+ getTablesWithColumns() {
77
+ return __awaiter(this, void 0, void 0, function* () {
78
+ const tables = yield this.getTables();
79
+ const out = [];
80
+ for (const table of tables) {
81
+ const tableName = table.name;
82
+ const primaryKey = yield this.getPrimaryKeyName({
83
+ table: tableName,
84
+ });
85
+ const columns = yield this.getColumns({
86
+ table: tableName,
87
+ primaryKey,
88
+ });
89
+ const mappedColumns = {};
90
+ for (const column of columns) {
91
+ mappedColumns[column.name] = column;
92
+ }
93
+ out.push({
94
+ name: tableName,
95
+ type: table.type,
96
+ columns: mappedColumns,
97
+ primaryKey,
98
+ });
99
+ }
100
+ return out;
101
+ });
102
+ }
103
+ getPrimaryKeyResultParser(result) {
104
+ return result === null || result === void 0 ? void 0 : result[this.columnNameColumn];
105
+ }
106
+ getPrimaryKeyQuery(table) {
107
+ return __awaiter(this, void 0, void 0, function* () {
108
+ return yield this.findOne({
109
+ table: this.columnsTable,
110
+ columns: [this.columnNameColumn],
111
+ where: {
112
+ [this.databaseNameColumn]: this.database,
113
+ [this.tableNameColumn]: table,
114
+ COLUMN_KEY: 'PRI',
115
+ },
116
+ });
117
+ });
118
+ }
119
+ getPrimaryKeyName(options) {
120
+ return __awaiter(this, void 0, void 0, function* () {
121
+ const result = yield this.getPrimaryKeyQuery(options.table);
122
+ return this.getPrimaryKeyResultParser(result !== null && result !== void 0 ? result : undefined);
123
+ });
124
+ }
125
+ getColumnsQuery(table) {
126
+ return __awaiter(this, void 0, void 0, function* () {
127
+ return yield this.find({
128
+ table: this.columnsTable,
129
+ columns: [this.columnNameColumn, this.columnTypeColumn],
130
+ where: {
131
+ [this.databaseNameColumn]: this.database,
132
+ [this.tableNameColumn]: table,
133
+ },
134
+ orderBy: { [this.columnPositionColumn]: 'ASC' },
135
+ });
136
+ });
137
+ }
138
+ getColumnsResultParser(options) {
139
+ return options.records.map((column) => ({
140
+ name: column[this.columnNameColumn],
141
+ type: column[this.columnTypeColumn]
142
+ .toUpperCase()
143
+ .replace('CHARACTER VARYING', 'VARCHAR'),
144
+ primaryKey: column[this.columnNameColumn] === options.primaryKey,
145
+ }));
146
+ }
147
+ getColumns(options) {
148
+ var _a;
149
+ return __awaiter(this, void 0, void 0, function* () {
150
+ const primaryKey = (_a = options.primaryKey) !== null && _a !== void 0 ? _a : (yield this.getPrimaryKeyName({ table: options.table }));
151
+ const results = yield this.getColumnsQuery(options.table);
152
+ return this.getColumnsResultParser({
153
+ records: results,
154
+ primaryKey: primaryKey,
155
+ });
156
+ });
157
+ }
158
+ }
159
+ exports.SchemaQueryRepository = SchemaQueryRepository;
160
160
  //# sourceMappingURL=schema-query-repository.js.map
@@ -1,9 +1,9 @@
1
- import { ColumnOptions } from '../column';
2
- export interface SchemaTable {
3
- name: string;
4
- type: 'table' | 'view';
5
- }
6
- export interface SchemaTableWithColumns extends SchemaTable {
7
- columns: Record<string, ColumnOptions>;
8
- primaryKey?: string;
9
- }
1
+ import { ColumnOptions } from '../column';
2
+ export interface SchemaTable {
3
+ name: string;
4
+ type: 'table' | 'view';
5
+ }
6
+ export interface SchemaTableWithColumns extends SchemaTable {
7
+ columns: Record<string, ColumnOptions>;
8
+ primaryKey?: string;
9
+ }
@@ -1,3 +1,3 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  //# sourceMappingURL=schema-table.js.map
@@ -1,4 +1,4 @@
1
- import { SchemaTableWithColumns } from './schema-table';
2
- export interface Schema {
3
- tables: Record<string, SchemaTableWithColumns>;
4
- }
1
+ import { SchemaTableWithColumns } from './schema-table';
2
+ export interface Schema {
3
+ tables: Record<string, SchemaTableWithColumns>;
4
+ }
package/schema/schema.js CHANGED
@@ -1,3 +1,3 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  //# sourceMappingURL=schema.js.map
@@ -1,9 +1,9 @@
1
- import { DatabaseRecord } from '../record';
2
- import { Seed } from './seed';
3
- export declare class AutoSeed extends Seed {
4
- protected table?: string;
5
- protected records: Array<DatabaseRecord | (() => Promise<DatabaseRecord>)>;
6
- protected primaryKey: string;
7
- up(): Promise<void>;
8
- down(): Promise<void>;
9
- }
1
+ import { DatabaseRecord } from '../record';
2
+ import { Seed } from './seed';
3
+ export declare class AutoSeed extends Seed {
4
+ protected table?: string;
5
+ protected records: Array<DatabaseRecord | (() => Promise<DatabaseRecord>)>;
6
+ protected primaryKey: string;
7
+ up(): Promise<void>;
8
+ down(): Promise<void>;
9
+ }
package/seed/auto-seed.js CHANGED
@@ -1,62 +1,62 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.AutoSeed = void 0;
13
- const comparison_1 = require("../comparison");
14
- const seed_1 = require("./seed");
15
- class AutoSeed extends seed_1.Seed {
16
- constructor() {
17
- super(...arguments);
18
- this.primaryKey = 'id';
19
- }
20
- up() {
21
- return __awaiter(this, void 0, void 0, function* () {
22
- const resolvedRecords = yield Promise.all(this.records.map((record) => __awaiter(this, void 0, void 0, function* () { return typeof record === 'function' ? record.bind(this)() : record; })));
23
- for (const record of resolvedRecords) {
24
- const inserted = yield this.query.insertOne({
25
- table: this.table,
26
- record: record,
27
- ifNotExists: true,
28
- });
29
- yield this.query.insertOne({
30
- table: 'riao_seed',
31
- record: {
32
- name: this.name,
33
- tableName: this.table,
34
- recordId: inserted[this.primaryKey],
35
- },
36
- ifNotExists: true,
37
- });
38
- }
39
- });
40
- }
41
- down() {
42
- return __awaiter(this, void 0, void 0, function* () {
43
- const records = (yield this.query.find({
44
- table: 'riao_seed',
45
- where: { name: this.name },
46
- }));
47
- const recordIds = records.map((record) => record.id);
48
- yield this.query.delete({
49
- table: this.table,
50
- where: { id: (0, comparison_1.inArray)(recordIds) },
51
- });
52
- yield this.query.delete({
53
- table: 'riao_seed',
54
- where: {
55
- name: this.name,
56
- },
57
- });
58
- });
59
- }
60
- }
61
- exports.AutoSeed = AutoSeed;
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.AutoSeed = void 0;
13
+ const comparison_1 = require("../comparison");
14
+ const seed_1 = require("./seed");
15
+ class AutoSeed extends seed_1.Seed {
16
+ constructor() {
17
+ super(...arguments);
18
+ this.primaryKey = 'id';
19
+ }
20
+ up() {
21
+ return __awaiter(this, void 0, void 0, function* () {
22
+ const resolvedRecords = yield Promise.all(this.records.map((record) => __awaiter(this, void 0, void 0, function* () { return typeof record === 'function' ? record.bind(this)() : record; })));
23
+ for (const record of resolvedRecords) {
24
+ const inserted = yield this.query.insertOne({
25
+ table: this.table,
26
+ record: record,
27
+ ifNotExists: true,
28
+ });
29
+ yield this.query.insertOne({
30
+ table: 'riao_seed',
31
+ record: {
32
+ name: this.name,
33
+ tableName: this.table,
34
+ recordId: inserted[this.primaryKey],
35
+ },
36
+ ifNotExists: true,
37
+ });
38
+ }
39
+ });
40
+ }
41
+ down() {
42
+ return __awaiter(this, void 0, void 0, function* () {
43
+ const records = (yield this.query.find({
44
+ table: 'riao_seed',
45
+ where: { name: this.name },
46
+ }));
47
+ const recordIds = records.map((record) => record.id);
48
+ yield this.query.delete({
49
+ table: this.table,
50
+ where: { id: (0, comparison_1.inArray)(recordIds) },
51
+ });
52
+ yield this.query.delete({
53
+ table: 'riao_seed',
54
+ where: {
55
+ name: this.name,
56
+ },
57
+ });
58
+ });
59
+ }
60
+ }
61
+ exports.AutoSeed = AutoSeed;
62
62
  //# sourceMappingURL=auto-seed.js.map
@@ -1,8 +1,8 @@
1
- import { Migration } from '../migration';
2
- /**
3
- * Create a seed table to track seeded record IDs
4
- */
5
- export declare class CreateSeedTable extends Migration {
6
- up(): Promise<void>;
7
- down(): Promise<void>;
8
- }
1
+ import { Migration } from '../migration';
2
+ /**
3
+ * Create a seed table to track seeded record IDs
4
+ */
5
+ export declare class CreateSeedTable extends Migration {
6
+ up(): Promise<void>;
7
+ down(): Promise<void>;
8
+ }