@iamkirbki/database-handler-core 3.1.3 → 4.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.
Files changed (71) hide show
  1. package/dist/abstract/Model.d.ts +39 -16
  2. package/dist/abstract/Model.d.ts.map +1 -1
  3. package/dist/abstract/Model.js +148 -36
  4. package/dist/abstract/{Schema.d.ts → SchemaTableBuilder.d.ts} +3 -8
  5. package/dist/abstract/SchemaTableBuilder.d.ts.map +1 -0
  6. package/dist/abstract/{Schema.js → SchemaTableBuilder.js} +1 -3
  7. package/dist/base/Database.d.ts +13 -0
  8. package/dist/base/Database.d.ts.map +1 -0
  9. package/dist/base/Database.js +27 -0
  10. package/dist/base/Query.d.ts +43 -0
  11. package/dist/base/Query.d.ts.map +1 -0
  12. package/dist/base/Query.js +87 -0
  13. package/dist/base/Record.d.ts +23 -0
  14. package/dist/base/Record.d.ts.map +1 -0
  15. package/dist/base/Record.js +72 -0
  16. package/dist/base/Table.d.ts +27 -0
  17. package/dist/base/Table.d.ts.map +1 -0
  18. package/dist/base/Table.js +128 -0
  19. package/dist/helpers/QueryStatementBuilder.d.ts +4 -35
  20. package/dist/helpers/QueryStatementBuilder.d.ts.map +1 -1
  21. package/dist/helpers/QueryStatementBuilder.js +6 -37
  22. package/dist/index.d.ts +13 -9
  23. package/dist/index.d.ts.map +1 -1
  24. package/dist/index.js +8 -8
  25. package/dist/interfaces/IController.d.ts +8 -0
  26. package/dist/interfaces/IController.d.ts.map +1 -0
  27. package/dist/interfaces/IController.js +1 -0
  28. package/dist/interfaces/IDatabaseAdapter.d.ts.map +1 -1
  29. package/dist/interfaces/IMigration.d.ts +6 -0
  30. package/dist/interfaces/IMigration.d.ts.map +1 -0
  31. package/dist/interfaces/IMigration.js +1 -0
  32. package/dist/interfaces/ISchemaBuilder.d.ts +7 -0
  33. package/dist/interfaces/ISchemaBuilder.d.ts.map +1 -0
  34. package/dist/interfaces/ISchemaBuilder.js +1 -0
  35. package/dist/runtime/Container.d.ts +12 -0
  36. package/dist/runtime/Container.d.ts.map +1 -0
  37. package/dist/runtime/Container.js +29 -0
  38. package/dist/runtime/Repository.d.ts +17 -0
  39. package/dist/runtime/Repository.d.ts.map +1 -0
  40. package/dist/runtime/Repository.js +101 -0
  41. package/dist/types/index.d.ts +1 -4
  42. package/dist/types/index.d.ts.map +1 -1
  43. package/dist/types/index.js +1 -0
  44. package/dist/types/model.d.ts +71 -0
  45. package/dist/types/model.d.ts.map +1 -0
  46. package/dist/types/model.js +2 -0
  47. package/dist/types/table.d.ts +6 -2
  48. package/dist/types/table.d.ts.map +1 -1
  49. package/package.json +5 -4
  50. package/dist/Database.d.ts +0 -98
  51. package/dist/Database.d.ts.map +0 -1
  52. package/dist/Database.js +0 -126
  53. package/dist/Query.d.ts +0 -143
  54. package/dist/Query.d.ts.map +0 -1
  55. package/dist/Query.js +0 -205
  56. package/dist/Record.d.ts +0 -125
  57. package/dist/Record.d.ts.map +0 -1
  58. package/dist/Record.js +0 -174
  59. package/dist/Table.d.ts +0 -158
  60. package/dist/Table.d.ts.map +0 -1
  61. package/dist/Table.js +0 -258
  62. package/dist/abstract/Controller.d.ts +0 -13
  63. package/dist/abstract/Controller.d.ts.map +0 -1
  64. package/dist/abstract/Controller.js +0 -6
  65. package/dist/abstract/Migration.d.ts +0 -6
  66. package/dist/abstract/Migration.d.ts.map +0 -1
  67. package/dist/abstract/Migration.js +0 -2
  68. package/dist/abstract/Schema.d.ts.map +0 -1
  69. package/dist/abstract/User.d.ts +0 -8
  70. package/dist/abstract/User.d.ts.map +0 -1
  71. package/dist/abstract/User.js +0 -6
@@ -0,0 +1,128 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import Query from "../base/Query.js";
11
+ import QueryStatementBuilder from "../helpers/QueryStatementBuilder.js";
12
+ import Container from "../runtime/Container.js";
13
+ /** Table class for interacting with a database table */
14
+ export default class Table {
15
+ /** Private constructor - use Table.create() */
16
+ constructor(name) {
17
+ this._adapter = Container.getInstance().getAdapter();
18
+ this._name = name;
19
+ }
20
+ /** Get the table name */
21
+ get Name() {
22
+ return this._name;
23
+ }
24
+ /** Get raw column information */
25
+ TableColumnInformation() {
26
+ return __awaiter(this, void 0, void 0, function* () {
27
+ return this._adapter.tableColumnInformation(this._name);
28
+ });
29
+ }
30
+ /** Get readable, formatted column information */
31
+ ReadableTableColumnInformation() {
32
+ return __awaiter(this, void 0, void 0, function* () {
33
+ const columns = yield this.TableColumnInformation();
34
+ return columns.map((col) => ({
35
+ name: col.name,
36
+ type: col.type,
37
+ nullable: col.notnull === 0,
38
+ isPrimaryKey: col.pk === 1,
39
+ defaultValue: col.dflt_value,
40
+ }));
41
+ });
42
+ }
43
+ Drop() {
44
+ return __awaiter(this, void 0, void 0, function* () {
45
+ const queryStr = `DROP TABLE IF EXISTS "${this._name}";`;
46
+ const query = new Query(this, queryStr, this._adapter);
47
+ yield query.Run();
48
+ });
49
+ }
50
+ /** Fetch records with optional filtering, ordering, and pagination */
51
+ Records(options) {
52
+ return __awaiter(this, void 0, void 0, function* () {
53
+ const queryStr = QueryStatementBuilder.BuildSelect(this, {
54
+ select: options === null || options === void 0 ? void 0 : options.select,
55
+ where: options === null || options === void 0 ? void 0 : options.where,
56
+ orderBy: options === null || options === void 0 ? void 0 : options.orderBy,
57
+ limit: options === null || options === void 0 ? void 0 : options.limit,
58
+ offset: options === null || options === void 0 ? void 0 : options.offset,
59
+ });
60
+ const query = new Query(this, queryStr, this._adapter);
61
+ if ((options === null || options === void 0 ? void 0 : options.where) && Object.keys(options.where).length > 0)
62
+ query.Parameters = options.where;
63
+ const results = yield query.All();
64
+ // Wrap each result in a Record object
65
+ return results;
66
+ });
67
+ }
68
+ /** Fetch a single record from the table */
69
+ Record(options) {
70
+ return __awaiter(this, void 0, void 0, function* () {
71
+ const results = yield this.Records({
72
+ select: options === null || options === void 0 ? void 0 : options.select,
73
+ where: options === null || options === void 0 ? void 0 : options.where,
74
+ orderBy: options === null || options === void 0 ? void 0 : options.orderBy,
75
+ limit: 1
76
+ });
77
+ return results[0];
78
+ });
79
+ }
80
+ /** Get the total count of records */
81
+ RecordsCount() {
82
+ return __awaiter(this, void 0, void 0, function* () {
83
+ const stmt = yield this._adapter.prepare(`SELECT COUNT(*) as count FROM "${this._name}";`);
84
+ const count = yield stmt.get({});
85
+ return parseInt(count.count) || 0;
86
+ });
87
+ }
88
+ /** Insert a record into the table */
89
+ Insert(values) {
90
+ return __awaiter(this, void 0, void 0, function* () {
91
+ var _a, _b;
92
+ const columns = Object.keys(values);
93
+ if (columns.length === 0) {
94
+ throw new Error("Cannot insert record with no columns");
95
+ }
96
+ const queryStr = QueryStatementBuilder.BuildInsert(this, values);
97
+ const query = new Query(this, queryStr, this._adapter);
98
+ query.Parameters = values;
99
+ const result = yield query.Run();
100
+ let recordId;
101
+ // For PostgreSQL compatibility: use 'id' from values if lastInsertRowid is undefined
102
+ if (Array.isArray(values)) {
103
+ recordId = (_a = result === null || result === void 0 ? void 0 : result.lastInsertRowid) !== null && _a !== void 0 ? _a : values.map(v => v.column === 'id' ? v.value : undefined);
104
+ }
105
+ else {
106
+ recordId = (_b = result === null || result === void 0 ? void 0 : result.lastInsertRowid) !== null && _b !== void 0 ? _b : values.id;
107
+ }
108
+ if (recordId === undefined) {
109
+ return undefined;
110
+ }
111
+ return this.Record({
112
+ where: { id: recordId }
113
+ });
114
+ });
115
+ }
116
+ /** Perform JOIN operations with other tables */
117
+ Join(Joins, options) {
118
+ return __awaiter(this, void 0, void 0, function* () {
119
+ const queryString = QueryStatementBuilder.BuildJoin(this, Joins, options);
120
+ const query = new Query(this, queryString, this._adapter);
121
+ // Set parameters if WHERE clause is present
122
+ if (options === null || options === void 0 ? void 0 : options.where) {
123
+ query.Parameters = options.where;
124
+ }
125
+ return yield query.All();
126
+ });
127
+ }
128
+ }
@@ -1,37 +1,6 @@
1
1
  import { DefaultQueryOptions, QueryOptions, QueryCondition, Join, QueryWhereParameters } from "../types/index.js";
2
- import Table from "Table";
3
- /**
4
- * QueryStatementBuilder - Utility class for building SQL query strings
5
- *
6
- * Provides static methods to construct SQL statements in a consistent, safe manner.
7
- * All methods use named parameters (@fieldName syntax) for better-sqlite3 compatibility.
8
- *
9
- * Features:
10
- * - Consistent query building pattern using array concatenation
11
- * - Support for SELECT, INSERT, UPDATE, DELETE, and COUNT operations
12
- * - JOIN support with nested join capabilities
13
- * - WHERE clause building with AND conditions
14
- * - Query options (ORDER BY, LIMIT, OFFSET)
15
- *
16
- * @example
17
- * ```typescript
18
- * // Build a SELECT query
19
- * const query = QueryStatementBuilder.BuildSelect(usersTable, {
20
- * select: 'id, name, email',
21
- * where: { status: 'active' },
22
- * orderBy: 'created_at DESC',
23
- * limit: 10
24
- * });
25
- * // Result: "SELECT id, name, email FROM users WHERE status = @status ORDER BY created_at DESC LIMIT 10"
26
- *
27
- * // Build an INSERT query
28
- * const insertQuery = QueryStatementBuilder.BuildInsert(usersTable, {
29
- * name: 'John',
30
- * email: 'john@example.com'
31
- * });
32
- * // Result: "INSERT INTO users (name, email) VALUES (@name, @email)"
33
- * ```
34
- */
2
+ import Table from "../base/Table";
3
+ /** Utility class for building SQL query strings */
35
4
  export default class QueryStatementBuilder {
36
5
  /**
37
6
  * Build a SELECT SQL statement with optional filtering, ordering, and pagination
@@ -177,8 +146,8 @@ export default class QueryStatementBuilder {
177
146
  * ```
178
147
  */
179
148
  static BuildWhere(where?: QueryCondition): string;
180
- private static BuildWhereWithOperators;
181
- private static BuildWhereSimple;
149
+ private static buildWhereWithOperators;
150
+ private static buildWhereSimple;
182
151
  /**
183
152
  * Build a SELECT statement with JOIN operations (INNER, LEFT, RIGHT, FULL)
184
153
  *
@@ -1 +1 @@
1
- {"version":3,"file":"QueryStatementBuilder.d.ts","sourceRoot":"","sources":["../../src/helpers/QueryStatementBuilder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,YAAY,EAAE,cAAc,EAAE,IAAI,EAAmB,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AACnI,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,MAAM,CAAC,OAAO,OAAO,qBAAqB;IACtC;;;;;;;;;;;;;;;;;;;;;;;OAuBG;WACW,WAAW,CAAC,KAAK,EAAE,KAAK,EAAE,OAAO,CAAC,EAAE,mBAAmB,GAAG,YAAY,GAAG,MAAM;IAY7F;;;;;;;;;;;;;;;;;;OAkBG;WACW,WAAW,CAAC,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,oBAAoB,GAAG,MAAM;IAY7E;;;;;;;;;;;;;;;;;;;;;;;;;OAyBG;WACW,WAAW,CAAC,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,cAAc,EAAE,KAAK,EAAE,cAAc,GAAG,MAAM;IAW9F;;;;;;;;;;;;;;;;;;;OAmBG;WACW,WAAW,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,cAAc,GAAG,MAAM;IAStE;;;;;;;;;;;;;;;;;;;;OAoBG;WACW,UAAU,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,CAAC,EAAE,cAAc,GAAG,MAAM;IAQtE;;;;;;;;;;;;;;;;;;;;;;;;;;;OA2BG;WACW,UAAU,CAAC,KAAK,CAAC,EAAE,cAAc,GAAG,MAAM;IAgBxD,OAAO,CAAC,MAAM,CAAC,uBAAuB;IAStC,OAAO,CAAC,MAAM,CAAC,gBAAgB;IAK/B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA2CG;WACW,SAAS,CACnB,SAAS,EAAE,KAAK,EAChB,KAAK,EAAE,IAAI,GAAG,IAAI,EAAE,EACpB,OAAO,CAAC,EAAE,mBAAmB,GAAG,YAAY;IAYhD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAsCG;WACW,aAAa,CACvB,SAAS,EAAE,KAAK,EAChB,KAAK,EAAE,IAAI,GAAG,IAAI,EAAE,GACrB,MAAM;IAcT;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA+BG;WACW,eAAe,CACzB,KAAK,EAAE,KAAK,EACZ,SAAS,EAAE,KAAK,EAChB,EAAE,EAAE,oBAAoB,GAAG,oBAAoB,EAAE,GAClD,MAAM;IAWT;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAgCG;WACW,iBAAiB,CAAC,OAAO,EAAE,YAAY,GAAG,MAAM;CAiBjE"}
1
+ {"version":3,"file":"QueryStatementBuilder.d.ts","sourceRoot":"","sources":["../../src/helpers/QueryStatementBuilder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,YAAY,EAAE,cAAc,EAAE,IAAI,EAAmB,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AACtI,OAAO,KAAK,MAAM,kBAAkB,CAAC;AAErC,mDAAmD;AACnD,MAAM,CAAC,OAAO,OAAO,qBAAqB;IACtC;;;;;;;;;;;;;;;;;;;;;;;OAuBG;WACW,WAAW,CAAC,KAAK,EAAE,KAAK,EAAE,OAAO,CAAC,EAAE,mBAAmB,GAAG,YAAY,GAAG,MAAM;IAY7F;;;;;;;;;;;;;;;;;;OAkBG;WACW,WAAW,CAAC,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,oBAAoB,GAAG,MAAM;IAY7E;;;;;;;;;;;;;;;;;;;;;;;;;OAyBG;WACW,WAAW,CAAC,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,cAAc,EAAE,KAAK,EAAE,cAAc,GAAG,MAAM;IAW9F;;;;;;;;;;;;;;;;;;;OAmBG;WACW,WAAW,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,cAAc,GAAG,MAAM;IAStE;;;;;;;;;;;;;;;;;;;;OAoBG;WACW,UAAU,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,CAAC,EAAE,cAAc,GAAG,MAAM;IAQtE;;;;;;;;;;;;;;;;;;;;;;;;;;;OA2BG;WACW,UAAU,CAAC,KAAK,CAAC,EAAE,cAAc,GAAG,MAAM;IAgBxD,OAAO,CAAC,MAAM,CAAC,uBAAuB;IAStC,OAAO,CAAC,MAAM,CAAC,gBAAgB;IAK/B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA2CG;WACW,SAAS,CACnB,SAAS,EAAE,KAAK,EAChB,KAAK,EAAE,IAAI,GAAG,IAAI,EAAE,EACpB,OAAO,CAAC,EAAE,mBAAmB,GAAG,YAAY,GAC7C,MAAM;IAWT;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAsCG;WACW,aAAa,CACvB,SAAS,EAAE,KAAK,EAChB,KAAK,EAAE,IAAI,GAAG,IAAI,EAAE,GACrB,MAAM;IAcT;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA+BG;WACW,eAAe,CACzB,KAAK,EAAE,KAAK,EACZ,SAAS,EAAE,KAAK,EAChB,EAAE,EAAE,oBAAoB,GAAG,oBAAoB,EAAE,GAClD,MAAM;IAWT;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAgCG;WACW,iBAAiB,CAAC,OAAO,EAAE,YAAY,GAAG,MAAM;CAiBjE"}
@@ -1,35 +1,4 @@
1
- /**
2
- * QueryStatementBuilder - Utility class for building SQL query strings
3
- *
4
- * Provides static methods to construct SQL statements in a consistent, safe manner.
5
- * All methods use named parameters (@fieldName syntax) for better-sqlite3 compatibility.
6
- *
7
- * Features:
8
- * - Consistent query building pattern using array concatenation
9
- * - Support for SELECT, INSERT, UPDATE, DELETE, and COUNT operations
10
- * - JOIN support with nested join capabilities
11
- * - WHERE clause building with AND conditions
12
- * - Query options (ORDER BY, LIMIT, OFFSET)
13
- *
14
- * @example
15
- * ```typescript
16
- * // Build a SELECT query
17
- * const query = QueryStatementBuilder.BuildSelect(usersTable, {
18
- * select: 'id, name, email',
19
- * where: { status: 'active' },
20
- * orderBy: 'created_at DESC',
21
- * limit: 10
22
- * });
23
- * // Result: "SELECT id, name, email FROM users WHERE status = @status ORDER BY created_at DESC LIMIT 10"
24
- *
25
- * // Build an INSERT query
26
- * const insertQuery = QueryStatementBuilder.BuildInsert(usersTable, {
27
- * name: 'John',
28
- * email: 'john@example.com'
29
- * });
30
- * // Result: "INSERT INTO users (name, email) VALUES (@name, @email)"
31
- * ```
32
- */
1
+ /** Utility class for building SQL query strings */
33
2
  export default class QueryStatementBuilder {
34
3
  /**
35
4
  * Build a SELECT SQL statement with optional filtering, ordering, and pagination
@@ -214,21 +183,21 @@ export default class QueryStatementBuilder {
214
183
  const queryParts = [];
215
184
  queryParts.push("WHERE");
216
185
  if (isSimpleObject) {
217
- queryParts.push(this.BuildWhereSimple(where));
186
+ queryParts.push(this.buildWhereSimple(where));
218
187
  }
219
188
  else {
220
- queryParts.push(this.BuildWhereWithOperators(where));
189
+ queryParts.push(this.buildWhereWithOperators(where));
221
190
  }
222
191
  return queryParts.join(" ");
223
192
  }
224
- static BuildWhereWithOperators(where) {
193
+ static buildWhereWithOperators(where) {
225
194
  const queryParts = where.map(condition => {
226
195
  const operator = condition.operator || "=";
227
196
  return `${condition.column} ${operator} @${condition.column.trim()}`;
228
197
  });
229
198
  return queryParts.join(" AND ");
230
199
  }
231
- static BuildWhereSimple(where) {
200
+ static buildWhereSimple(where) {
232
201
  const queryParts = Object.keys(where).map(col => `${col} = @${col}`);
233
202
  return queryParts.join(" AND ");
234
203
  }
@@ -330,7 +299,7 @@ export default class QueryStatementBuilder {
330
299
  const joinsArray = Array.isArray(joins) ? joins : [joins];
331
300
  let currentTable = fromTable;
332
301
  for (const join of joinsArray) {
333
- queryParts.push(`${join.joinType} JOIN ${join.fromTable.Name}`);
302
+ queryParts.push(`${join.joinType} JOIN "${join.fromTable.Name}"`);
334
303
  queryParts.push(this.BuildJoinOnPart(currentTable, join.fromTable, join.on));
335
304
  currentTable = join.fromTable;
336
305
  }
package/dist/index.d.ts CHANGED
@@ -44,16 +44,20 @@
44
44
  *
45
45
  * @packageDocumentation
46
46
  */
47
- import Database from "./Database.js";
48
- import Table from "./Table.js";
49
- import Record from "./Record.js";
50
- import Query from "./Query.js";
47
+ import Database from "./base/Database.js";
48
+ import Table from "./base/Table.js";
49
+ import Record from "./base/Record.js";
50
+ import Query from "./base/Query.js";
51
+ import Model from "./abstract/Model.js";
52
+ import SchemaTableBuilder from "./abstract/SchemaTableBuilder.js";
53
+ import AbstractSchemaBuilder from "./interfaces/ISchemaBuilder.js";
54
+ import Repository from "./runtime/Repository.js";
55
+ import Container from "./runtime/Container.js";
51
56
  import IDatabaseAdapter from "./interfaces/IDatabaseAdapter.js";
52
57
  import IStatementAdapter from "./interfaces/IStatementAdapter.js";
53
- import Model from "./abstract/Model.js";
54
- import Controller from "./abstract/Controller.js";
55
- export * from "./abstract/Migration.js";
56
- export * from "./abstract/Schema.js";
57
- export { Database, Model, IDatabaseAdapter, IStatementAdapter, Table, Query, Record, Controller };
58
+ import IController from "./interfaces/IController.js";
59
+ import IMigration from "./interfaces/IMigration.js";
60
+ import ISchemaBuilder from "./interfaces/ISchemaBuilder.js";
61
+ export { Database, Model, Table, Query, Record, Repository, Container, SchemaTableBuilder, AbstractSchemaBuilder, IDatabaseAdapter, IStatementAdapter, IController, IMigration, ISchemaBuilder, };
58
62
  export * from "./types/index.js";
59
63
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6CG;AAEH,OAAO,QAAQ,MAAM,eAAe,CAAC;AACrC,OAAO,KAAK,MAAM,YAAY,CAAC;AAC/B,OAAO,MAAM,MAAM,aAAa,CAAC;AACjC,OAAO,KAAK,MAAM,YAAY,CAAC;AAE/B,OAAO,gBAAgB,MAAM,kCAAkC,CAAC;AAChE,OAAO,iBAAiB,MAAM,mCAAmC,CAAC;AAElE,OAAO,KAAK,MAAM,qBAAqB,CAAC;AACxC,OAAO,UAAU,MAAM,0BAA0B,CAAC;AAElD,cAAc,yBAAyB,CAAC;AACxC,cAAc,sBAAsB,CAAC;AAErC,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,CAAC;AAClG,cAAc,kBAAkB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6CG;AAEH,OAAO,QAAQ,MAAM,oBAAoB,CAAC;AAC1C,OAAO,KAAK,MAAM,iBAAiB,CAAC;AACpC,OAAO,MAAM,MAAM,kBAAkB,CAAC;AACtC,OAAO,KAAK,MAAM,iBAAiB,CAAC;AAEpC,OAAO,KAAK,MAAM,qBAAqB,CAAC;AACxC,OAAO,kBAAkB,MAAM,kCAAkC,CAAC;AAClE,OAAO,qBAAqB,MAAM,oCAAoC,CAAC;AAEvE,OAAO,UAAU,MAAM,yBAAyB,CAAC;AACjD,OAAO,SAAS,MAAM,wBAAwB,CAAC;AAE/C,OAAO,gBAAgB,MAAM,sCAAsC,CAAC;AACpE,OAAO,iBAAiB,MAAM,uCAAuC,CAAC;AACtE,OAAO,WAAW,MAAM,iCAAiC,CAAC;AAC1D,OAAO,UAAU,MAAM,gCAAgC,CAAC;AACxD,OAAO,cAAc,MAAM,oCAAoC,CAAC;AAEhE,OAAO,EACH,QAAQ,EACR,KAAK,EACL,KAAK,EACL,KAAK,EACL,MAAM,EACN,UAAU,EACV,SAAS,EAET,kBAAkB,EAClB,qBAAqB,EAErB,gBAAgB,EAChB,iBAAiB,EACjB,WAAW,EACX,UAAU,EACV,cAAc,GACjB,CAAC;AAEF,cAAc,kBAAkB,CAAC"}
package/dist/index.js CHANGED
@@ -44,13 +44,13 @@
44
44
  *
45
45
  * @packageDocumentation
46
46
  */
47
- import Database from "./Database.js";
48
- import Table from "./Table.js";
49
- import Record from "./Record.js";
50
- import Query from "./Query.js";
47
+ import Database from "./base/Database.js";
48
+ import Table from "./base/Table.js";
49
+ import Record from "./base/Record.js";
50
+ import Query from "./base/Query.js";
51
51
  import Model from "./abstract/Model.js";
52
- import Controller from "./abstract/Controller.js";
53
- export * from "./abstract/Migration.js";
54
- export * from "./abstract/Schema.js";
55
- export { Database, Model, Table, Query, Record, Controller };
52
+ import SchemaTableBuilder from "./abstract/SchemaTableBuilder.js";
53
+ import Repository from "./runtime/Repository.js";
54
+ import Container from "./runtime/Container.js";
55
+ export { Database, Model, Table, Query, Record, Repository, Container, SchemaTableBuilder, };
56
56
  export * from "./types/index.js";
@@ -0,0 +1,8 @@
1
+ export default interface IController<M> {
2
+ index(): Promise<M[]>;
3
+ show(id: string): Promise<M | undefined>;
4
+ create(data: object): Promise<M>;
5
+ update(id: string, data: object): Promise<void>;
6
+ delete(id: string): Promise<void>;
7
+ }
8
+ //# sourceMappingURL=IController.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"IController.d.ts","sourceRoot":"","sources":["../../src/interfaces/IController.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,OAAO,WAAW,WAAW,CAAC,CAAC;IAClC,KAAK,IAAI,OAAO,CAAC,CAAC,EAAE,CAAC,CAAC;IACtB,IAAI,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC,CAAC;IACzC,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;IACjC,MAAM,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAChD,MAAM,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACrC"}
@@ -0,0 +1 @@
1
+ export {};
@@ -1 +1 @@
1
- {"version":3,"file":"IDatabaseAdapter.d.ts","sourceRoot":"","sources":["../../src/interfaces/IDatabaseAdapter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,iBAAiB,MAAM,wBAAwB,CAAC;AAEvD,MAAM,CAAC,OAAO,WAAW,gBAAgB;IACrC,OAAO,CAAC,MAAM,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACxC,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAAC;IACnD,IAAI,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACnC,WAAW,CAAC,EAAE,EAAE,CAAC,KAAK,EAAE,GAAG,EAAE,KAAK,IAAI,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;IAC3D,sBAAsB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,EAAE,CAAC,CAAC;IACtE,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CAC1B"}
1
+ {"version":3,"file":"IDatabaseAdapter.d.ts","sourceRoot":"","sources":["../../src/interfaces/IDatabaseAdapter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,iBAAiB,MAAM,wBAAwB,CAAC;AAEvD,MAAM,CAAC,OAAO,WAAW,gBAAgB;IACrC,OAAO,CAAC,MAAM,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACxC,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAAC;IACnD,IAAI,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACnC,WAAW,CAAC,EAAE,EAAE,CAAC,KAAK,EAAE,GAAG,EAAE,KAAK,IAAI,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;IAC3D,sBAAsB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,EAAE,CAAC,CAAC;IACtE,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CAC1B"}
@@ -0,0 +1,6 @@
1
+ import IDatabaseAdapter from "./IDatabaseAdapter.js";
2
+ export default interface IMigration {
3
+ up(db: IDatabaseAdapter): Promise<void>;
4
+ down(db: IDatabaseAdapter): Promise<void>;
5
+ }
6
+ //# sourceMappingURL=IMigration.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"IMigration.d.ts","sourceRoot":"","sources":["../../src/interfaces/IMigration.ts"],"names":[],"mappings":"AAAA,OAAO,gBAAgB,MAAM,uBAAuB,CAAC;AAErD,MAAM,CAAC,OAAO,WAAW,UAAU;IAC/B,EAAE,CAAC,EAAE,EAAE,gBAAgB,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACxC,IAAI,CAAC,EAAE,EAAE,gBAAgB,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAC7C"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,7 @@
1
+ import SchemaTableBuilder from "../abstract/SchemaTableBuilder.js";
2
+ export default interface AbstractSchemaBuilder {
3
+ createTable(name: string, callback: (table: SchemaTableBuilder) => void): Promise<void>;
4
+ dropTable(name: string): Promise<void>;
5
+ alterTable(oldName: string, callback: (table: SchemaTableBuilder) => void): Promise<void>;
6
+ }
7
+ //# sourceMappingURL=ISchemaBuilder.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ISchemaBuilder.d.ts","sourceRoot":"","sources":["../../src/interfaces/ISchemaBuilder.ts"],"names":[],"mappings":"AAAA,OAAO,kBAAkB,MAAM,sCAAsC,CAAC;AAEtE,MAAM,CAAC,OAAO,WAAW,qBAAqB;IAC1C,WAAW,CACP,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,CAAC,KAAK,EAAE,kBAAkB,KAAK,IAAI,GAC9C,OAAO,CAAC,IAAI,CAAC,CAAC;IAEjB,SAAS,CACL,IAAI,EAAE,MAAM,GACb,OAAO,CAAC,IAAI,CAAC,CAAC;IAEjB,UAAU,CACN,OAAO,EAAE,MAAM,EACf,QAAQ,EAAE,CAAC,KAAK,EAAE,kBAAkB,KAAK,IAAI,GAC9C,OAAO,CAAC,IAAI,CAAC,CAAC;CACpB"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,12 @@
1
+ import IDatabaseAdapter from "../interfaces/IDatabaseAdapter.js";
2
+ declare class Container {
3
+ private static _instance;
4
+ private _adapters;
5
+ private _defaultAdapter?;
6
+ private constructor();
7
+ static getInstance(): Container;
8
+ registerAdapter(name: string, adapter: IDatabaseAdapter, isDefault?: boolean): void;
9
+ getAdapter(name?: string): IDatabaseAdapter;
10
+ }
11
+ export default Container;
12
+ //# sourceMappingURL=Container.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Container.d.ts","sourceRoot":"","sources":["../../src/runtime/Container.ts"],"names":[],"mappings":"AAAA,OAAO,gBAAgB,MAAM,sCAAsC,CAAC;AAEpE,cAAM,SAAS;IACX,OAAO,CAAC,MAAM,CAAC,SAAS,CAAY;IACpC,OAAO,CAAC,SAAS,CAA4C;IAC7D,OAAO,CAAC,eAAe,CAAC,CAAmB;IAE3C,OAAO;WAEO,WAAW,IAAI,SAAS;IAO/B,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,gBAAgB,EAAE,SAAS,UAAQ,GAAG,IAAI;IAOjF,UAAU,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,gBAAgB;CASrD;AAED,eAAe,SAAS,CAAC"}
@@ -0,0 +1,29 @@
1
+ class Container {
2
+ constructor() {
3
+ this._adapters = new Map();
4
+ }
5
+ static getInstance() {
6
+ if (!Container._instance) {
7
+ Container._instance = new Container();
8
+ }
9
+ return Container._instance;
10
+ }
11
+ registerAdapter(name, adapter, isDefault = false) {
12
+ this._adapters.set(name, adapter);
13
+ if (isDefault || !this._defaultAdapter) {
14
+ this._defaultAdapter = adapter;
15
+ }
16
+ }
17
+ getAdapter(name) {
18
+ if (name) {
19
+ const adapter = this._adapters.get(name);
20
+ if (!adapter)
21
+ throw new Error(`Adapter '${name}' not found`);
22
+ return adapter;
23
+ }
24
+ if (!this._defaultAdapter)
25
+ throw new Error("No default adapter set");
26
+ return this._defaultAdapter;
27
+ }
28
+ }
29
+ export default Container;
@@ -0,0 +1,17 @@
1
+ import type Model from "../abstract/Model.js";
2
+ import { columnType, QueryCondition } from "../types/index";
3
+ export default class Repository<Type extends columnType, ModelType extends Model<Type>> {
4
+ private static _instances;
5
+ private models;
6
+ private Table;
7
+ constructor(tableName: string, ModelClass: ModelType);
8
+ static getInstance<ModelType extends columnType>(ModelClass: new () => Model<ModelType>, tableName: string): Repository<ModelType, Model<ModelType>>;
9
+ syncModel(model: ModelType): void;
10
+ getModel(name: string): ModelType;
11
+ save(attributes: Partial<Type>, oldAttributes: Partial<Type>): Promise<void>;
12
+ get(conditions: QueryCondition, Model: Model<Type>): Promise<Type | null>;
13
+ update(attributes: Partial<Type>): Promise<this>;
14
+ all(Model: Model<Type>): Promise<Type[]>;
15
+ private join;
16
+ }
17
+ //# sourceMappingURL=Repository.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Repository.d.ts","sourceRoot":"","sources":["../../src/runtime/Repository.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,yBAAyB,CAAC;AAEjD,OAAO,EAAE,UAAU,EAAQ,cAAc,EAAY,MAAM,mBAAmB,CAAC;AAE/E,MAAM,CAAC,OAAO,OAAO,UAAU,CAAC,IAAI,SAAS,UAAU,EAAE,SAAS,SAAS,KAAK,CAAC,IAAI,CAAC;IAClF,OAAO,CAAC,MAAM,CAAC,UAAU,CAAqE;IAC9F,OAAO,CAAC,MAAM,CAAqC;IACnD,OAAO,CAAC,KAAK,CAAO;gBAER,SAAS,EAAE,MAAM,EAAE,UAAU,EAAE,SAAS;WAMtC,WAAW,CAAC,SAAS,SAAS,UAAU,EAClD,UAAU,EAAE,UAAU,KAAK,CAAC,SAAS,CAAC,EACtC,SAAS,EAAE,MAAM,GAClB,UAAU,CAAC,SAAS,EAAE,KAAK,CAAC,SAAS,CAAC,CAAC;IAWnC,SAAS,CAAC,KAAK,EAAE,SAAS,GAAG,IAAI;IAKjC,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS;IAI3B,IAAI,CAAC,UAAU,EAAE,OAAO,CAAC,IAAI,CAAC,EAAE,aAAa,EAAE,OAAO,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAK5E,GAAG,CAAC,UAAU,EAAE,cAAc,EAAE,KAAK,EAAE,KAAK,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,IAAI,GAAG,IAAI,CAAC;IAWzE,MAAM,CAAC,UAAU,EAAE,OAAO,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAehD,GAAG,CAAC,KAAK,EAAE,KAAK,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC;YAQvC,IAAI;CAoBrB"}
@@ -0,0 +1,101 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import Table from "../base/Table.js";
11
+ class Repository {
12
+ constructor(tableName, ModelClass) {
13
+ var _a;
14
+ this.models = new Map();
15
+ const modelPk = ((_a = ModelClass.primaryKey) === null || _a === void 0 ? void 0 : _a.toString()) || ModelClass.constructor.name;
16
+ this.models.set(modelPk, ModelClass);
17
+ this.Table = new Table(tableName);
18
+ }
19
+ static getInstance(ModelClass, tableName) {
20
+ const className = ModelClass.name;
21
+ if (!this._instances.has(className)) {
22
+ const instance = new Repository(tableName, new ModelClass());
23
+ this._instances.set(className, instance);
24
+ return instance;
25
+ }
26
+ return this._instances.get(className);
27
+ }
28
+ syncModel(model) {
29
+ var _a;
30
+ const modelPk = ((_a = model.primaryKey) === null || _a === void 0 ? void 0 : _a.toString()) || model.constructor.name;
31
+ this.models.set(modelPk, model);
32
+ }
33
+ getModel(name) {
34
+ return this.models.get(name);
35
+ }
36
+ save(attributes, oldAttributes) {
37
+ return __awaiter(this, void 0, void 0, function* () {
38
+ const dataToSave = Object.assign(Object.assign({}, oldAttributes), attributes);
39
+ yield this.Table.Insert(dataToSave);
40
+ });
41
+ }
42
+ get(conditions, Model) {
43
+ return __awaiter(this, void 0, void 0, function* () {
44
+ let record;
45
+ if (Model.JoinedEntities.length > 0) {
46
+ record = yield this.join(Model, conditions);
47
+ }
48
+ else {
49
+ record = yield this.Table.Record({ where: conditions });
50
+ }
51
+ return record ? record.values : null;
52
+ });
53
+ }
54
+ update(attributes) {
55
+ return __awaiter(this, void 0, void 0, function* () {
56
+ const primaryKey = this.models.values().next().value.Configuration.primaryKey;
57
+ const pkValue = attributes[primaryKey];
58
+ if (pkValue) {
59
+ const record = yield this.Table.Record({ where: { [primaryKey]: pkValue } });
60
+ if (record) {
61
+ yield record.Update(attributes);
62
+ }
63
+ }
64
+ else {
65
+ throw new Error("Primary key value is required for update.");
66
+ }
67
+ return this;
68
+ });
69
+ }
70
+ all(Model) {
71
+ return __awaiter(this, void 0, void 0, function* () {
72
+ if (Model.JoinedEntities.length > 0) {
73
+ return yield this.join(Model);
74
+ }
75
+ else {
76
+ return yield this.Table.Records().then(records => records.map(record => record.values));
77
+ }
78
+ });
79
+ }
80
+ join(Model, conditions) {
81
+ return __awaiter(this, void 0, void 0, function* () {
82
+ const Join = Model.JoinedEntities.map(join => {
83
+ const relation = Model.Relations.find(rel => rel.model.Configuration.table.toLowerCase() === join.toLowerCase());
84
+ if (!relation) {
85
+ throw new Error(`Relation for joined entity ${join} not found.`);
86
+ }
87
+ const JoinType = relation.type === 'hasOne' || relation.type === 'belongsTo' ? 'INNER' : 'LEFT';
88
+ return {
89
+ fromTable: new Table(relation.model.Configuration.table),
90
+ joinType: JoinType,
91
+ on: [
92
+ { [relation.foreignKey]: relation.localKey }
93
+ ]
94
+ };
95
+ });
96
+ return (yield this.Table.Join(Join, { where: conditions })).map(record => record.values);
97
+ });
98
+ }
99
+ }
100
+ Repository._instances = new Map();
101
+ export default Repository;
@@ -1,10 +1,7 @@
1
1
  export type RequireAtLeastOne<T, Keys extends keyof T = keyof T> = Pick<T, Exclude<keyof T, Keys>> & {
2
2
  [K in Keys]-?: Required<Pick<T, K>> & Partial<Pick<T, Exclude<Keys, K>>>;
3
3
  }[Keys];
4
- export type ModelWithTimestamps = {
5
- created_at?: string;
6
- updated_at?: string;
7
- };
8
4
  export * from './query.js';
9
5
  export * from './table.js';
6
+ export * from './model.js';
10
7
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAIA,MAAM,MAAM,iBAAiB,CAAC,CAAC,EAAE,IAAI,SAAS,MAAM,CAAC,GAAG,MAAM,CAAC,IAC3D,IAAI,CAAC,CAAC,EAAE,OAAO,CAAC,MAAM,CAAC,EAAE,IAAI,CAAC,CAAC,GAC7B;KACG,CAAC,IAAI,IAAI,CAAC,CAAC,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,EAAE,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;CAC3E,CAAC,IAAI,CAAC,CAAA;AAEX,MAAM,MAAM,mBAAmB,GAAG;IAC9B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,UAAU,CAAC,EAAE,MAAM,CAAC;CACvB,CAAA;AAED,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAIA,MAAM,MAAM,iBAAiB,CAAC,CAAC,EAAE,IAAI,SAAS,MAAM,CAAC,GAAG,MAAM,CAAC,IAC3D,IAAI,CAAC,CAAC,EAAE,OAAO,CAAC,MAAM,CAAC,EAAE,IAAI,CAAC,CAAC,GAC7B;KACG,CAAC,IAAI,IAAI,CAAC,CAAC,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,EAAE,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;CAC3E,CAAC,IAAI,CAAC,CAAA;AAEX,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC"}
@@ -3,3 +3,4 @@
3
3
  // Retrieved 2025-11-19, License - CC BY-SA 4.0
4
4
  export * from './query.js';
5
5
  export * from './table.js';
6
+ export * from './model.js';
@@ -0,0 +1,71 @@
1
+ /** Model configuration and types */
2
+ import Model from "../abstract/Model";
3
+ import { columnType } from "./index";
4
+ export type ModelEventType = 'retrieved' | 'creating' | 'created' | 'updating' | 'updated' | 'saving' | 'saved' | 'deleting' | 'deleted' | 'restoring' | 'restored' | 'forceDeleting' | 'forceDeleted';
5
+ export type ModelEventHandler<T> = (model: T) => void | Promise<void>;
6
+ export interface ModelObserver<T> {
7
+ retrieved?(model: T): void | Promise<void>;
8
+ creating?(model: T): void | Promise<void>;
9
+ created?(model: T): void | Promise<void>;
10
+ updating?(model: T): void | Promise<void>;
11
+ updated?(model: T): void | Promise<void>;
12
+ saving?(model: T): void | Promise<void>;
13
+ saved?(model: T): void | Promise<void>;
14
+ deleting?(model: T): void | Promise<void>;
15
+ deleted?(model: T): void | Promise<void>;
16
+ restoring?(model: T): void | Promise<void>;
17
+ restored?(model: T): void | Promise<void>;
18
+ forceDeleting?(model: T): void | Promise<void>;
19
+ forceDeleted?(model: T): void | Promise<void>;
20
+ }
21
+ export interface ModelScope {
22
+ (query: any): void;
23
+ }
24
+ export interface ModelConfig {
25
+ /** Table name - defaults to lowercase class name */
26
+ table: string;
27
+ /** Primary key column - defaults to 'id' */
28
+ primaryKey: string;
29
+ /** Whether to auto-increment primary key - defaults to true */
30
+ incrementing?: boolean;
31
+ /** Primary key type - defaults to 'number' */
32
+ keyType?: 'string' | 'number';
33
+ /** Enable automatic timestamp management - defaults to true */
34
+ timestamps?: boolean;
35
+ /** Created at column name - defaults to 'created_at' */
36
+ createdAtColumn?: string;
37
+ /** Updated at column name - defaults to 'updated_at' */
38
+ updatedAtColumn?: string;
39
+ /** Deleted at column name for soft deletes - defaults to 'deleted_at' */
40
+ deletedAtColumn?: string;
41
+ /** Database connection name */
42
+ connection?: string;
43
+ /** Mass assignable attributes (whitelist) */
44
+ fillable?: string[];
45
+ /** Guarded attributes (blacklist) - defaults to ['*'] if fillable is empty */
46
+ guarded?: string[];
47
+ /** Hidden attributes when serializing */
48
+ hidden?: string[];
49
+ /** Visible attributes when serializing (overrides hidden) */
50
+ visible?: string[];
51
+ /** Append computed attributes when serializing */
52
+ appends?: string[];
53
+ /** Default attribute values */
54
+ attributes?: Record<string, any>;
55
+ /** Date format for serialization */
56
+ dateFormat?: string;
57
+ }
58
+ export type relation = {
59
+ type: 'hasOne' | 'hasMany' | 'belongsTo';
60
+ model: unknown & Model<columnType>;
61
+ foreignKey: string;
62
+ localKey?: string;
63
+ };
64
+ export interface SoftDeletable {
65
+ deleted_at?: string | Date | null;
66
+ }
67
+ export type ModelWithTimestamps = {
68
+ created_at?: string;
69
+ updated_at?: string;
70
+ };
71
+ //# sourceMappingURL=model.d.ts.map