@riao/dbal 1.0.1

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 (196) hide show
  1. package/CHANGELOG.md +3 -0
  2. package/LICENSE.md +20 -0
  3. package/README.md +241 -0
  4. package/builder/builder.d.ts +41 -0
  5. package/builder/builder.js +73 -0
  6. package/builder/builder.js.map +1 -0
  7. package/builder/index.d.ts +1 -0
  8. package/builder/index.js +6 -0
  9. package/builder/index.js.map +1 -0
  10. package/column/column-options.d.ts +141 -0
  11. package/column/column-options.js +3 -0
  12. package/column/column-options.js.map +1 -0
  13. package/column/column-type.d.ts +17 -0
  14. package/column/column-type.js +26 -0
  15. package/column/column-type.js.map +1 -0
  16. package/column/column-values.d.ts +29 -0
  17. package/column/column-values.js +3 -0
  18. package/column/column-values.js.map +1 -0
  19. package/column/index.d.ts +3 -0
  20. package/column/index.js +20 -0
  21. package/column/index.js.map +1 -0
  22. package/config/configure-db.d.ts +14 -0
  23. package/config/configure-db.js +19 -0
  24. package/config/configure-db.js.map +1 -0
  25. package/config/database-env.d.ts +16 -0
  26. package/config/database-env.js +15 -0
  27. package/config/database-env.js.map +1 -0
  28. package/config/index.d.ts +2 -0
  29. package/config/index.js +8 -0
  30. package/config/index.js.map +1 -0
  31. package/database/connection-options.d.ts +7 -0
  32. package/database/connection-options.js +3 -0
  33. package/database/connection-options.js.map +1 -0
  34. package/database/database.d.ts +185 -0
  35. package/database/database.js +257 -0
  36. package/database/database.js.map +1 -0
  37. package/database/driver-query.d.ts +10 -0
  38. package/database/driver-query.js +3 -0
  39. package/database/driver-query.js.map +1 -0
  40. package/database/driver.d.ts +9 -0
  41. package/database/driver.js +43 -0
  42. package/database/driver.js.map +1 -0
  43. package/database/get-database-path.d.ts +6 -0
  44. package/database/get-database-path.js +13 -0
  45. package/database/get-database-path.js.map +1 -0
  46. package/database/index.d.ts +6 -0
  47. package/database/index.js +27 -0
  48. package/database/index.js.map +1 -0
  49. package/database/load-database.d.ts +9 -0
  50. package/database/load-database.js +37 -0
  51. package/database/load-database.js.map +1 -0
  52. package/ddl/alter-table.d.ts +26 -0
  53. package/ddl/alter-table.js +3 -0
  54. package/ddl/alter-table.js.map +1 -0
  55. package/ddl/create-database.d.ts +3 -0
  56. package/ddl/create-database.js +3 -0
  57. package/ddl/create-database.js.map +1 -0
  58. package/ddl/create-table.d.ts +8 -0
  59. package/ddl/create-table.js +3 -0
  60. package/ddl/create-table.js.map +1 -0
  61. package/ddl/create-user.d.ts +4 -0
  62. package/ddl/create-user.js +3 -0
  63. package/ddl/create-user.js.map +1 -0
  64. package/ddl/ddl-builder.d.ts +68 -0
  65. package/ddl/ddl-builder.js +358 -0
  66. package/ddl/ddl-builder.js.map +1 -0
  67. package/ddl/ddl-repository.d.ts +104 -0
  68. package/ddl/ddl-repository.js +176 -0
  69. package/ddl/ddl-repository.js.map +1 -0
  70. package/ddl/drop-database.d.ts +4 -0
  71. package/ddl/drop-database.js +3 -0
  72. package/ddl/drop-database.js.map +1 -0
  73. package/ddl/drop-table.d.ts +4 -0
  74. package/ddl/drop-table.js +3 -0
  75. package/ddl/drop-table.js.map +1 -0
  76. package/ddl/drop-user.d.ts +4 -0
  77. package/ddl/drop-user.js +3 -0
  78. package/ddl/drop-user.js.map +1 -0
  79. package/ddl/foreign-key-constraint.d.ts +9 -0
  80. package/ddl/foreign-key-constraint.js +3 -0
  81. package/ddl/foreign-key-constraint.js.map +1 -0
  82. package/ddl/grant.d.ts +12 -0
  83. package/ddl/grant.js +3 -0
  84. package/ddl/grant.js.map +1 -0
  85. package/ddl/index.d.ts +12 -0
  86. package/ddl/index.js +24 -0
  87. package/ddl/index.js.map +1 -0
  88. package/ddl/truncate.d.ts +3 -0
  89. package/ddl/truncate.js +3 -0
  90. package/ddl/truncate.js.map +1 -0
  91. package/dml/column-name.d.ts +3 -0
  92. package/dml/column-name.js +12 -0
  93. package/dml/column-name.js.map +1 -0
  94. package/dml/delete.d.ts +8 -0
  95. package/dml/delete.js +3 -0
  96. package/dml/delete.js.map +1 -0
  97. package/dml/index.d.ts +10 -0
  98. package/dml/index.js +30 -0
  99. package/dml/index.js.map +1 -0
  100. package/dml/insert.d.ts +11 -0
  101. package/dml/insert.js +3 -0
  102. package/dml/insert.js.map +1 -0
  103. package/dml/join.d.ts +15 -0
  104. package/dml/join.js +3 -0
  105. package/dml/join.js.map +1 -0
  106. package/dml/order-by.d.ts +2 -0
  107. package/dml/order-by.js +3 -0
  108. package/dml/order-by.js.map +1 -0
  109. package/dml/query-builder.d.ts +53 -0
  110. package/dml/query-builder.js +398 -0
  111. package/dml/query-builder.js.map +1 -0
  112. package/dml/query-repository.d.ts +67 -0
  113. package/dml/query-repository.js +140 -0
  114. package/dml/query-repository.js.map +1 -0
  115. package/dml/select.d.ts +23 -0
  116. package/dml/select.js +3 -0
  117. package/dml/select.js.map +1 -0
  118. package/dml/update.d.ts +9 -0
  119. package/dml/update.js +3 -0
  120. package/dml/update.js.map +1 -0
  121. package/dml/where.d.ts +26 -0
  122. package/dml/where.js +67 -0
  123. package/dml/where.js.map +1 -0
  124. package/functions/function-interface.d.ts +18 -0
  125. package/functions/function-interface.js +8 -0
  126. package/functions/function-interface.js.map +1 -0
  127. package/functions/functions.d.ts +5 -0
  128. package/functions/functions.js +18 -0
  129. package/functions/functions.js.map +1 -0
  130. package/functions/index.d.ts +1 -0
  131. package/functions/index.js +18 -0
  132. package/functions/index.js.map +1 -0
  133. package/index.d.ts +9 -0
  134. package/index.js +26 -0
  135. package/index.js.map +1 -0
  136. package/migration/create-migration-table.d.ts +8 -0
  137. package/migration/create-migration-table.js +54 -0
  138. package/migration/create-migration-table.js.map +1 -0
  139. package/migration/index.d.ts +2 -0
  140. package/migration/index.js +8 -0
  141. package/migration/index.js.map +1 -0
  142. package/migration/migration-record.d.ts +9 -0
  143. package/migration/migration-record.js +3 -0
  144. package/migration/migration-record.js.map +1 -0
  145. package/migration/migration-runner.d.ts +19 -0
  146. package/migration/migration-runner.js +114 -0
  147. package/migration/migration-runner.js.map +1 -0
  148. package/migration/migration.d.ts +11 -0
  149. package/migration/migration.js +27 -0
  150. package/migration/migration.js.map +1 -0
  151. package/package.json +28 -0
  152. package/record/index.d.ts +1 -0
  153. package/record/index.js +18 -0
  154. package/record/index.js.map +1 -0
  155. package/record/record.d.ts +2 -0
  156. package/record/record.js +3 -0
  157. package/record/record.js.map +1 -0
  158. package/repository/index.d.ts +2 -0
  159. package/repository/index.js +6 -0
  160. package/repository/index.js.map +1 -0
  161. package/repository/repository-options.d.ts +4 -0
  162. package/repository/repository-options.js +3 -0
  163. package/repository/repository-options.js.map +1 -0
  164. package/repository/repository.d.ts +6 -0
  165. package/repository/repository.js +10 -0
  166. package/repository/repository.js.map +1 -0
  167. package/schema/index.d.ts +3 -0
  168. package/schema/index.js +6 -0
  169. package/schema/index.js.map +1 -0
  170. package/schema/schema-query-repository.d.ts +45 -0
  171. package/schema/schema-query-repository.js +154 -0
  172. package/schema/schema-query-repository.js.map +1 -0
  173. package/schema/schema-table.d.ts +9 -0
  174. package/schema/schema-table.js +3 -0
  175. package/schema/schema-table.js.map +1 -0
  176. package/schema/schema.d.ts +4 -0
  177. package/schema/schema.js +3 -0
  178. package/schema/schema.js.map +1 -0
  179. package/seed/auto-seed.d.ts +8 -0
  180. package/seed/auto-seed.js +58 -0
  181. package/seed/auto-seed.js.map +1 -0
  182. package/seed/create-seed-table.d.ts +8 -0
  183. package/seed/create-seed-table.js +64 -0
  184. package/seed/create-seed-table.js.map +1 -0
  185. package/seed/index.d.ts +4 -0
  186. package/seed/index.js +10 -0
  187. package/seed/index.js.map +1 -0
  188. package/seed/seed-record.d.ts +11 -0
  189. package/seed/seed-record.js +3 -0
  190. package/seed/seed-record.js.map +1 -0
  191. package/seed/seed-runner.d.ts +20 -0
  192. package/seed/seed-runner.js +91 -0
  193. package/seed/seed-runner.js.map +1 -0
  194. package/seed/seed.d.ts +12 -0
  195. package/seed/seed.js +28 -0
  196. package/seed/seed.js.map +1 -0
package/dml/where.d.ts ADDED
@@ -0,0 +1,26 @@
1
+ import { DatabaseFunctionToken } from '../functions/function-interface';
2
+ import { DatabaseRecord } from '../record';
3
+ import { ColumnName } from './column-name';
4
+ export type WhereConditionType = 'equals' | 'like' | 'lt' | 'lte' | 'gt' | 'gte' | 'in' | 'not';
5
+ export interface WhereCondition {
6
+ riao_condition: WhereConditionType;
7
+ value: any;
8
+ }
9
+ export declare function equals(value: any): WhereCondition;
10
+ export declare function like(value: any): WhereCondition;
11
+ export declare function lt(value: any): WhereCondition;
12
+ export declare function lte(value: any): WhereCondition;
13
+ export declare function gt(value: any): WhereCondition;
14
+ export declare function gte(value: any): WhereCondition;
15
+ export declare function inArray(value: any[]): WhereCondition;
16
+ export declare function columnName(name: string): ColumnName;
17
+ export interface NotWhereCondition extends WhereCondition {
18
+ riao_condition: 'not';
19
+ }
20
+ export declare function not(value: any): NotWhereCondition;
21
+ export type WhereKeyVal<T extends DatabaseRecord = DatabaseRecord> = {
22
+ [key in keyof Partial<T>]: undefined | null | string | number | boolean | WhereCondition | ColumnName | DatabaseFunctionToken;
23
+ };
24
+ export type Where<T extends DatabaseRecord = DatabaseRecord> = 'and' | 'or' | 'null' | WhereKeyVal<T> | NotWhereCondition | Where<T>[];
25
+ export declare const and = "and";
26
+ export declare const or = "or";
package/dml/where.js ADDED
@@ -0,0 +1,67 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.or = exports.and = exports.not = exports.columnName = exports.inArray = exports.gte = exports.gt = exports.lte = exports.lt = exports.like = exports.equals = void 0;
4
+ const column_name_1 = require("./column-name");
5
+ function equals(value) {
6
+ return {
7
+ riao_condition: 'equals',
8
+ value: value,
9
+ };
10
+ }
11
+ exports.equals = equals;
12
+ function like(value) {
13
+ return {
14
+ riao_condition: 'like',
15
+ value: value,
16
+ };
17
+ }
18
+ exports.like = like;
19
+ function lt(value) {
20
+ return {
21
+ riao_condition: 'lt',
22
+ value: value,
23
+ };
24
+ }
25
+ exports.lt = lt;
26
+ function lte(value) {
27
+ return {
28
+ riao_condition: 'lte',
29
+ value: value,
30
+ };
31
+ }
32
+ exports.lte = lte;
33
+ function gt(value) {
34
+ return {
35
+ riao_condition: 'gt',
36
+ value: value,
37
+ };
38
+ }
39
+ exports.gt = gt;
40
+ function gte(value) {
41
+ return {
42
+ riao_condition: 'gte',
43
+ value: value,
44
+ };
45
+ }
46
+ exports.gte = gte;
47
+ function inArray(value) {
48
+ return {
49
+ riao_condition: 'in',
50
+ value: value,
51
+ };
52
+ }
53
+ exports.inArray = inArray;
54
+ function columnName(name) {
55
+ return new column_name_1.ColumnName(name);
56
+ }
57
+ exports.columnName = columnName;
58
+ function not(value) {
59
+ return {
60
+ riao_condition: 'not',
61
+ value: value,
62
+ };
63
+ }
64
+ exports.not = not;
65
+ exports.and = 'and';
66
+ exports.or = 'or';
67
+ //# sourceMappingURL=where.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"where.js","sourceRoot":"","sources":["../../../src/dml/where.ts"],"names":[],"mappings":";;;AAEA,+CAA2C;AAiB3C,SAAgB,MAAM,CAAC,KAAU;IAChC,OAAO;QACN,cAAc,EAAE,QAAQ;QACxB,KAAK,EAAE,KAAK;KACZ,CAAC;AACH,CAAC;AALD,wBAKC;AAED,SAAgB,IAAI,CAAC,KAAU;IAC9B,OAAO;QACN,cAAc,EAAE,MAAM;QACtB,KAAK,EAAE,KAAK;KACZ,CAAC;AACH,CAAC;AALD,oBAKC;AAED,SAAgB,EAAE,CAAC,KAAU;IAC5B,OAAO;QACN,cAAc,EAAE,IAAI;QACpB,KAAK,EAAE,KAAK;KACZ,CAAC;AACH,CAAC;AALD,gBAKC;AAED,SAAgB,GAAG,CAAC,KAAU;IAC7B,OAAO;QACN,cAAc,EAAE,KAAK;QACrB,KAAK,EAAE,KAAK;KACZ,CAAC;AACH,CAAC;AALD,kBAKC;AAED,SAAgB,EAAE,CAAC,KAAU;IAC5B,OAAO;QACN,cAAc,EAAE,IAAI;QACpB,KAAK,EAAE,KAAK;KACZ,CAAC;AACH,CAAC;AALD,gBAKC;AAED,SAAgB,GAAG,CAAC,KAAU;IAC7B,OAAO;QACN,cAAc,EAAE,KAAK;QACrB,KAAK,EAAE,KAAK;KACZ,CAAC;AACH,CAAC;AALD,kBAKC;AAED,SAAgB,OAAO,CAAC,KAAY;IACnC,OAAO;QACN,cAAc,EAAE,IAAI;QACpB,KAAK,EAAE,KAAK;KACZ,CAAC;AACH,CAAC;AALD,0BAKC;AAED,SAAgB,UAAU,CAAC,IAAY;IACtC,OAAO,IAAI,wBAAU,CAAC,IAAI,CAAC,CAAC;AAC7B,CAAC;AAFD,gCAEC;AAMD,SAAgB,GAAG,CAAC,KAAU;IAC7B,OAAO;QACN,cAAc,EAAE,KAAK;QACrB,KAAK,EAAE,KAAK;KACZ,CAAC;AACH,CAAC;AALD,kBAKC;AAsBY,QAAA,GAAG,GAAG,KAAK,CAAC;AACZ,QAAA,EAAE,GAAG,IAAI,CAAC"}
@@ -0,0 +1,18 @@
1
+ import { ColumnType } from '../column';
2
+ /**
3
+ * Database functions are typed by column type, so that users
4
+ * gain strong typing when using functions, i.e. the user
5
+ * can't assign a date function to a bool column.
6
+ */
7
+ export type DatabaseFunctionReturnType = keyof typeof ColumnType;
8
+ export declare enum DatabaseFunctionKeys {
9
+ CURRENT_TIMESTAMP = "CURRENT_TIMESTAMP"
10
+ }
11
+ /**
12
+ * A token is returned by database functions, so that it can be
13
+ * interpreted during sql generation.
14
+ */
15
+ export interface DatabaseFunctionToken<T extends DatabaseFunctionReturnType = DatabaseFunctionReturnType> {
16
+ riao_dbfn: DatabaseFunctionKeys;
17
+ type: T;
18
+ }
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DatabaseFunctionKeys = void 0;
4
+ var DatabaseFunctionKeys;
5
+ (function (DatabaseFunctionKeys) {
6
+ DatabaseFunctionKeys["CURRENT_TIMESTAMP"] = "CURRENT_TIMESTAMP";
7
+ })(DatabaseFunctionKeys = exports.DatabaseFunctionKeys || (exports.DatabaseFunctionKeys = {}));
8
+ //# sourceMappingURL=function-interface.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"function-interface.js","sourceRoot":"","sources":["../../../src/functions/function-interface.ts"],"names":[],"mappings":";;;AASA,IAAY,oBAEX;AAFD,WAAY,oBAAoB;IAC/B,+DAAuC,CAAA;AACxC,CAAC,EAFW,oBAAoB,GAApB,4BAAoB,KAApB,4BAAoB,QAE/B"}
@@ -0,0 +1,5 @@
1
+ import { ColumnType } from '../column';
2
+ import { DatabaseFunctionToken } from './function-interface';
3
+ export declare class DatabaseFunctions {
4
+ currentTimestamp(): DatabaseFunctionToken<ColumnType.TIMESTAMP>;
5
+ }
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DatabaseFunctions = void 0;
4
+ const column_1 = require("../column");
5
+ const function_interface_1 = require("./function-interface");
6
+ class DatabaseFunctions {
7
+ // ------------------------------------------------------------------------
8
+ // Date/Time functions
9
+ // ------------------------------------------------------------------------
10
+ currentTimestamp() {
11
+ return {
12
+ riao_dbfn: function_interface_1.DatabaseFunctionKeys.CURRENT_TIMESTAMP,
13
+ type: column_1.ColumnType.TIMESTAMP,
14
+ };
15
+ }
16
+ }
17
+ exports.DatabaseFunctions = DatabaseFunctions;
18
+ //# sourceMappingURL=functions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"functions.js","sourceRoot":"","sources":["../../../src/functions/functions.ts"],"names":[],"mappings":";;;AAAA,sCAAuC;AACvC,6DAG8B;AAE9B,MAAa,iBAAiB;IAC7B,2EAA2E;IAC3E,sBAAsB;IACtB,2EAA2E;IAEpE,gBAAgB;QACtB,OAAO;YACN,SAAS,EAAE,yCAAoB,CAAC,iBAAiB;YACjD,IAAI,EAAE,mBAAU,CAAC,SAAS;SAC1B,CAAC;IACH,CAAC;CACD;AAXD,8CAWC"}
@@ -0,0 +1 @@
1
+ export * from './functions';
@@ -0,0 +1,18 @@
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
+ __exportStar(require("./functions"), exports);
18
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/functions/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,8CAA4B"}
package/index.d.ts ADDED
@@ -0,0 +1,9 @@
1
+ export * from './column';
2
+ export * from './config';
3
+ export * from './database';
4
+ export * from './ddl';
5
+ export * from './dml';
6
+ export * from './migration';
7
+ export * from './record';
8
+ export * from './repository';
9
+ export * from './schema';
package/index.js ADDED
@@ -0,0 +1,26 @@
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
+ __exportStar(require("./column"), exports);
18
+ __exportStar(require("./config"), exports);
19
+ __exportStar(require("./database"), exports);
20
+ __exportStar(require("./ddl"), exports);
21
+ __exportStar(require("./dml"), exports);
22
+ __exportStar(require("./migration"), exports);
23
+ __exportStar(require("./record"), exports);
24
+ __exportStar(require("./repository"), exports);
25
+ __exportStar(require("./schema"), exports);
26
+ //# sourceMappingURL=index.js.map
package/index.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAAyB;AACzB,2CAAyB;AACzB,6CAA2B;AAC3B,wCAAsB;AACtB,wCAAsB;AACtB,8CAA4B;AAC5B,2CAAyB;AACzB,+CAA6B;AAC7B,2CAAyB"}
@@ -0,0 +1,8 @@
1
+ import { Migration } from './migration';
2
+ /**
3
+ * Create a migration table to track current-state
4
+ */
5
+ export declare class CreateMigrationTable extends Migration {
6
+ up(): Promise<void>;
7
+ down(): Promise<void>;
8
+ }
@@ -0,0 +1,54 @@
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.CreateMigrationTable = void 0;
13
+ const column_1 = require("../column");
14
+ const migration_1 = require("./migration");
15
+ /**
16
+ * Create a migration table to track current-state
17
+ */
18
+ class CreateMigrationTable extends migration_1.Migration {
19
+ up() {
20
+ return __awaiter(this, void 0, void 0, function* () {
21
+ yield this.ddl.createTable({
22
+ name: 'riao_migration',
23
+ ifNotExists: true,
24
+ columns: [
25
+ {
26
+ name: 'id',
27
+ type: column_1.ColumnType.INT,
28
+ autoIncrement: true,
29
+ primaryKey: true,
30
+ },
31
+ {
32
+ name: 'name',
33
+ type: column_1.ColumnType.VARCHAR,
34
+ length: 255,
35
+ },
36
+ {
37
+ name: 'timestamp',
38
+ type: column_1.ColumnType.TIMESTAMP,
39
+ default: this.db.functions.currentTimestamp(),
40
+ },
41
+ ],
42
+ });
43
+ });
44
+ }
45
+ down() {
46
+ return __awaiter(this, void 0, void 0, function* () {
47
+ yield this.ddl.dropTable({
48
+ tables: 'riao_migration',
49
+ });
50
+ });
51
+ }
52
+ }
53
+ exports.CreateMigrationTable = CreateMigrationTable;
54
+ //# sourceMappingURL=create-migration-table.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-migration-table.js","sourceRoot":"","sources":["../../../src/migration/create-migration-table.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,sCAAuC;AACvC,2CAAwC;AAExC;;GAEG;AACH,MAAa,oBAAqB,SAAQ,qBAAS;IACrC,EAAE;;YACd,MAAM,IAAI,CAAC,GAAG,CAAC,WAAW,CAAC;gBAC1B,IAAI,EAAE,gBAAgB;gBACtB,WAAW,EAAE,IAAI;gBACjB,OAAO,EAAE;oBACR;wBACC,IAAI,EAAE,IAAI;wBACV,IAAI,EAAE,mBAAU,CAAC,GAAG;wBACpB,aAAa,EAAE,IAAI;wBACnB,UAAU,EAAE,IAAI;qBAChB;oBACD;wBACC,IAAI,EAAE,MAAM;wBACZ,IAAI,EAAE,mBAAU,CAAC,OAAO;wBACxB,MAAM,EAAE,GAAG;qBACX;oBACD;wBACC,IAAI,EAAE,WAAW;wBACjB,IAAI,EAAE,mBAAU,CAAC,SAAS;wBAC1B,OAAO,EAAE,IAAI,CAAC,EAAE,CAAC,SAAS,CAAC,gBAAgB,EAAE;qBAC7C;iBACD;aACD,CAAC,CAAC;QACJ,CAAC;KAAA;IAEY,IAAI;;YAChB,MAAM,IAAI,CAAC,GAAG,CAAC,SAAS,CAAC;gBACxB,MAAM,EAAE,gBAAgB;aACxB,CAAC,CAAC;QACJ,CAAC;KAAA;CACD;AA/BD,oDA+BC"}
@@ -0,0 +1,2 @@
1
+ export { MigrationRunner } from './migration-runner';
2
+ export { Migration } from './migration';
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Migration = exports.MigrationRunner = void 0;
4
+ var migration_runner_1 = require("./migration-runner");
5
+ Object.defineProperty(exports, "MigrationRunner", { enumerable: true, get: function () { return migration_runner_1.MigrationRunner; } });
6
+ var migration_1 = require("./migration");
7
+ Object.defineProperty(exports, "Migration", { enumerable: true, get: function () { return migration_1.Migration; } });
8
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/migration/index.ts"],"names":[],"mappings":";;;AAAA,uDAAqD;AAA5C,mHAAA,eAAe,OAAA;AACxB,yCAAwC;AAA/B,sGAAA,SAAS,OAAA"}
@@ -0,0 +1,9 @@
1
+ import { DatabaseRecordId } from '../record';
2
+ /**
3
+ * A record in the migration table
4
+ */
5
+ export interface MigrationRecord {
6
+ id: DatabaseRecordId;
7
+ name: string;
8
+ timestamp: string;
9
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=migration-record.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"migration-record.js","sourceRoot":"","sources":["../../../src/migration/migration-record.ts"],"names":[],"mappings":""}
@@ -0,0 +1,19 @@
1
+ import { Database } from '../database';
2
+ /**
3
+ * Runs migrations
4
+ */
5
+ export declare class MigrationRunner {
6
+ protected db: Database;
7
+ constructor(db: Database);
8
+ /**
9
+ * Run migrations
10
+ *
11
+ * @param migrations (Optional) Folder to find migrations in. Default is
12
+ * db.getMigraitonDirectory()
13
+ * @param log (Optional) Log function. Defaults to console.log
14
+ * @param direction (Optional) Run migrations up or down?
15
+ * @param steps (Optional) Run a certain number of steps?
16
+ */
17
+ run(migrations?: string, log?: (...args: any[]) => void, direction?: 'up' | 'down', steps?: number): Promise<void>;
18
+ protected getMigrationName(filename: string): string;
19
+ }
@@ -0,0 +1,114 @@
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.MigrationRunner = void 0;
13
+ const fs = require("fs");
14
+ const path_1 = require("path");
15
+ const ts_import_ts_1 = require("ts-import-ts");
16
+ const create_migration_table_1 = require("./create-migration-table");
17
+ /**
18
+ * Runs migrations
19
+ */
20
+ class MigrationRunner {
21
+ constructor(db) {
22
+ this.db = db;
23
+ }
24
+ /**
25
+ * Run migrations
26
+ *
27
+ * @param migrations (Optional) Folder to find migrations in. Default is
28
+ * db.getMigraitonDirectory()
29
+ * @param log (Optional) Log function. Defaults to console.log
30
+ * @param direction (Optional) Run migrations up or down?
31
+ * @param steps (Optional) Run a certain number of steps?
32
+ */
33
+ run(migrations,
34
+ /* eslint-disable-next-line no-console */
35
+ log = console.log, direction = 'up', steps) {
36
+ return __awaiter(this, void 0, void 0, function* () {
37
+ if (!migrations) {
38
+ migrations = this.db.getMigrationsDirectory();
39
+ }
40
+ if (steps === -1) {
41
+ steps = undefined;
42
+ }
43
+ if (steps < 0) {
44
+ throw new Error('Steps must be a positive integer, or -1 for all.');
45
+ }
46
+ // Create migration table, if not existing
47
+ const createMigrationTable = new create_migration_table_1.CreateMigrationTable(this.db);
48
+ yield createMigrationTable.up();
49
+ // Query migrations that have already run
50
+ const repo = this.db.getQueryRepository();
51
+ const alreadyRanMigrations = yield repo.find({
52
+ columns: ['name'],
53
+ table: 'riao_migration',
54
+ });
55
+ const alreadyRanNames = alreadyRanMigrations.map((migration) => migration.name);
56
+ // Get migration files in folder
57
+ const migrationsInPath = fs
58
+ .readdirSync(migrations)
59
+ .filter((fname) => /\.ts$/.test(fname));
60
+ if (!migrationsInPath.length) {
61
+ log('No migrations found!');
62
+ return;
63
+ }
64
+ // Check which migrations need to run
65
+ let migrationsToRun;
66
+ if (direction === 'up') {
67
+ migrationsToRun = migrationsInPath.filter((file) => !alreadyRanNames.includes(this.getMigrationName(file)));
68
+ }
69
+ else {
70
+ migrationsToRun = alreadyRanNames.reverse();
71
+ }
72
+ if (!migrationsToRun.length) {
73
+ log('All migrations have already run');
74
+ return;
75
+ }
76
+ log(`Discovered ${migrationsToRun.length} ` +
77
+ 'pending migrations in this direction.');
78
+ if (steps !== undefined) {
79
+ migrationsToRun = migrationsToRun.slice(0, steps);
80
+ }
81
+ log(`Running ${migrationsToRun.length} migrations...`);
82
+ // Run each migration
83
+ for (const migrationFile of migrationsToRun) {
84
+ // Get the migration path & name
85
+ const path = (0, path_1.join)(migrations, migrationFile);
86
+ const name = this.getMigrationName(path);
87
+ // Run the migration
88
+ log(direction.toLocaleUpperCase() + ' | ', name);
89
+ const migrationType = (0, ts_import_ts_1.tsimport)(path);
90
+ const migration = new migrationType(this.db);
91
+ yield migration[direction]();
92
+ // Save the migration record
93
+ if (direction === 'up') {
94
+ yield repo.insert({
95
+ table: 'riao_migration',
96
+ records: { name },
97
+ });
98
+ }
99
+ else {
100
+ yield repo.delete({
101
+ table: 'riao_migration',
102
+ where: { name },
103
+ });
104
+ }
105
+ }
106
+ log('Migrations complete');
107
+ });
108
+ }
109
+ getMigrationName(filename) {
110
+ return (0, path_1.basename)(filename.toLowerCase(), (0, path_1.extname)(filename));
111
+ }
112
+ }
113
+ exports.MigrationRunner = MigrationRunner;
114
+ //# sourceMappingURL=migration-runner.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"migration-runner.js","sourceRoot":"","sources":["../../../src/migration/migration-runner.ts"],"names":[],"mappings":"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"}
@@ -0,0 +1,11 @@
1
+ import { QueryRepository } from '../dml/query-repository';
2
+ import { DataDefinitionRepository } from '../ddl/ddl-repository';
3
+ import { Database } from '../database';
4
+ export declare class Migration {
5
+ protected db: Database;
6
+ protected ddl: DataDefinitionRepository;
7
+ protected query: QueryRepository;
8
+ constructor(db: Database);
9
+ up(): Promise<void>;
10
+ down(): Promise<void>;
11
+ }
@@ -0,0 +1,27 @@
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.Migration = void 0;
13
+ class Migration {
14
+ constructor(db) {
15
+ this.db = db;
16
+ this.ddl = db.ddl;
17
+ this.query = db.query;
18
+ }
19
+ up() {
20
+ return __awaiter(this, void 0, void 0, function* () { });
21
+ }
22
+ down() {
23
+ return __awaiter(this, void 0, void 0, function* () { });
24
+ }
25
+ }
26
+ exports.Migration = Migration;
27
+ //# sourceMappingURL=migration.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"migration.js","sourceRoot":"","sources":["../../../src/migration/migration.ts"],"names":[],"mappings":";;;;;;;;;;;;AAIA,MAAa,SAAS;IAKrB,YAAmB,EAAY;QAC9B,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC;QACb,IAAI,CAAC,GAAG,GAAG,EAAE,CAAC,GAAG,CAAC;QAClB,IAAI,CAAC,KAAK,GAAG,EAAE,CAAC,KAAK,CAAC;IACvB,CAAC;IAEY,EAAE;8DAAmB,CAAC;KAAA;IAEtB,IAAI;8DAAmB,CAAC;KAAA;CACrC;AAdD,8BAcC"}
package/package.json ADDED
@@ -0,0 +1,28 @@
1
+ {
2
+ "name": "@riao/dbal",
3
+ "version": "1.0.1",
4
+ "description": "riao database",
5
+ "typescript-template": {
6
+ "base": "1.0.0",
7
+ "jasmine": "1.0.0",
8
+ "library": "1.0.0"
9
+ },
10
+ "scripts": {},
11
+ "dependencies": {
12
+ "ts-appconfig": "^1.2.0",
13
+ "ts-import-ts": "^1.0.0"
14
+ },
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "git+https://github.com/riao-dbal/riao-dbal.git"
18
+ },
19
+ "author": "riao",
20
+ "license": "MIT",
21
+ "bugs": {
22
+ "url": "https://github.com/riao-dbal/riao-dbal/issues"
23
+ },
24
+ "homepage": "https://github.com/riao-dbal/riao-dbal#readme",
25
+ "keywords": [],
26
+ "main": "index.js",
27
+ "types": "index.d.ts"
28
+ }
@@ -0,0 +1 @@
1
+ export * from './record';
@@ -0,0 +1,18 @@
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
+ __exportStar(require("./record"), exports);
18
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/record/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAAyB"}
@@ -0,0 +1,2 @@
1
+ export type DatabaseRecordId = number | string;
2
+ export type DatabaseRecord = Record<string, any>;
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=record.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"record.js","sourceRoot":"","sources":["../../../src/record/record.ts"],"names":[],"mappings":""}
@@ -0,0 +1,2 @@
1
+ export { Repository } from './repository';
2
+ export { RepositoryOptions } from './repository-options';
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Repository = void 0;
4
+ var repository_1 = require("./repository");
5
+ Object.defineProperty(exports, "Repository", { enumerable: true, get: function () { return repository_1.Repository; } });
6
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/repository/index.ts"],"names":[],"mappings":";;;AAAA,2CAA0C;AAAjC,wGAAA,UAAU,OAAA"}
@@ -0,0 +1,4 @@
1
+ import { DatabaseDriver } from '../database';
2
+ export interface RepositoryOptions {
3
+ driver: DatabaseDriver;
4
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=repository-options.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"repository-options.js","sourceRoot":"","sources":["../../../src/repository/repository-options.ts"],"names":[],"mappings":""}
@@ -0,0 +1,6 @@
1
+ import { DatabaseDriver } from '../database';
2
+ import { RepositoryOptions } from './repository-options';
3
+ export declare class Repository {
4
+ protected driver: DatabaseDriver;
5
+ constructor(options: RepositoryOptions);
6
+ }
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Repository = void 0;
4
+ class Repository {
5
+ constructor(options) {
6
+ this.driver = options.driver;
7
+ }
8
+ }
9
+ exports.Repository = Repository;
10
+ //# sourceMappingURL=repository.js.map