duckdb-tinyorm 1.0.43 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +387 -46
- package/dist/constants/data-type.decorator.d.ts +20 -1
- package/dist/constants/data-type.decorator.js +62 -14
- package/dist/constants/data-type.decorator.js.map +1 -1
- package/dist/errors/orm-errors.d.ts +27 -0
- package/dist/errors/orm-errors.js +80 -0
- package/dist/errors/orm-errors.js.map +1 -0
- package/dist/helpers/bulk-insert.helper.d.ts +1 -0
- package/dist/helpers/bulk-insert.helper.js +19 -0
- package/dist/helpers/bulk-insert.helper.js.map +1 -0
- package/dist/helpers/db.helper.d.ts +10 -0
- package/dist/helpers/db.helper.js +62 -0
- package/dist/helpers/db.helper.js.map +1 -1
- package/dist/helpers/mapping.helper.d.ts +1 -1
- package/dist/helpers/mapping.helper.js +35 -35
- package/dist/helpers/mapping.helper.js.map +1 -1
- package/dist/helpers/table-util.helper.js +46 -19
- package/dist/helpers/table-util.helper.js.map +1 -1
- package/dist/index.d.ts +9 -3
- package/dist/index.js +24 -1
- package/dist/index.js.map +1 -1
- package/dist/migration/migration.d.ts +22 -0
- package/dist/migration/migration.js +143 -0
- package/dist/migration/migration.js.map +1 -0
- package/dist/pagination/pagination.d.ts +10 -0
- package/dist/pagination/pagination.js +3 -0
- package/dist/pagination/pagination.js.map +1 -0
- package/dist/query/query-builder.d.ts +27 -0
- package/dist/query/query-builder.js +113 -0
- package/dist/query/query-builder.js.map +1 -0
- package/dist/repositories/base.interface.d.ts +19 -2
- package/dist/repositories/base.repository.d.ts +18 -2
- package/dist/repositories/base.repository.js +159 -14
- package/dist/repositories/base.repository.js.map +1 -1
- package/dist/repositories/duckdb.repository.d.ts +18 -0
- package/dist/repositories/duckdb.repository.js +91 -16
- package/dist/repositories/duckdb.repository.js.map +1 -1
- package/dist/repositories/transaction.d.ts +9 -0
- package/dist/repositories/transaction.js +48 -0
- package/dist/repositories/transaction.js.map +1 -0
- package/dist/test.d.ts +4 -3
- package/dist/test.js +126 -28
- package/dist/test.js.map +1 -1
- package/package.json +3 -2
- package/tsconfig.json +9 -1
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MigrationError = exports.ValidationError = exports.TransactionError = exports.QueryExecutionError = exports.TableCreationError = exports.PrimaryKeyError = exports.EntityNotFoundError = exports.ConnectionError = exports.OrmBaseError = void 0;
|
|
4
|
+
class OrmBaseError extends Error {
|
|
5
|
+
constructor(message) {
|
|
6
|
+
super(message);
|
|
7
|
+
this.name = this.constructor.name;
|
|
8
|
+
Object.setPrototypeOf(this, OrmBaseError.prototype);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
exports.OrmBaseError = OrmBaseError;
|
|
12
|
+
class ConnectionError extends OrmBaseError {
|
|
13
|
+
constructor(entityName) {
|
|
14
|
+
super("Error connecting to database: " + entityName);
|
|
15
|
+
Object.setPrototypeOf(this, ConnectionError.prototype);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
exports.ConnectionError = ConnectionError;
|
|
19
|
+
class EntityNotFoundError extends OrmBaseError {
|
|
20
|
+
constructor(entityName, id) {
|
|
21
|
+
super(`Entity ${entityName} with id ${id} not found`);
|
|
22
|
+
Object.setPrototypeOf(this, EntityNotFoundError.prototype);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
exports.EntityNotFoundError = EntityNotFoundError;
|
|
26
|
+
class PrimaryKeyError extends OrmBaseError {
|
|
27
|
+
constructor(message) {
|
|
28
|
+
super(message);
|
|
29
|
+
Object.setPrototypeOf(this, PrimaryKeyError.prototype);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
exports.PrimaryKeyError = PrimaryKeyError;
|
|
33
|
+
class TableCreationError extends OrmBaseError {
|
|
34
|
+
constructor(tableName, originalError) {
|
|
35
|
+
const errorMsg = originalError
|
|
36
|
+
? `Failed to create table ${tableName}: ${originalError.message}`
|
|
37
|
+
: `Failed to create table ${tableName}`;
|
|
38
|
+
super(errorMsg);
|
|
39
|
+
Object.setPrototypeOf(this, TableCreationError.prototype);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
exports.TableCreationError = TableCreationError;
|
|
43
|
+
class QueryExecutionError extends OrmBaseError {
|
|
44
|
+
constructor(query, originalError) {
|
|
45
|
+
const errorMsg = originalError
|
|
46
|
+
? `Error executing query: ${query.substring(0, 100)}...\nDetails: ${originalError.message}`
|
|
47
|
+
: `Error executing query: ${query.substring(0, 100)}...`;
|
|
48
|
+
super(errorMsg);
|
|
49
|
+
Object.setPrototypeOf(this, QueryExecutionError.prototype);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
exports.QueryExecutionError = QueryExecutionError;
|
|
53
|
+
class TransactionError extends OrmBaseError {
|
|
54
|
+
constructor(operation, originalError) {
|
|
55
|
+
const errorMsg = originalError
|
|
56
|
+
? `Transaction ${operation} failed: ${originalError.message}`
|
|
57
|
+
: `Transaction ${operation} failed`;
|
|
58
|
+
super(errorMsg);
|
|
59
|
+
Object.setPrototypeOf(this, TransactionError.prototype);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
exports.TransactionError = TransactionError;
|
|
63
|
+
class ValidationError extends OrmBaseError {
|
|
64
|
+
constructor(entityName, propertyName, value, constraint) {
|
|
65
|
+
super(`Validation failed for ${entityName}.${propertyName}: ${value} violates constraint ${constraint}`);
|
|
66
|
+
Object.setPrototypeOf(this, ValidationError.prototype);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
exports.ValidationError = ValidationError;
|
|
70
|
+
class MigrationError extends OrmBaseError {
|
|
71
|
+
constructor(version, operation, originalError) {
|
|
72
|
+
const errorMsg = originalError
|
|
73
|
+
? `Migration ${version} ${operation} failed: ${originalError.message}`
|
|
74
|
+
: `Migration ${version} ${operation} failed`;
|
|
75
|
+
super(errorMsg);
|
|
76
|
+
Object.setPrototypeOf(this, MigrationError.prototype);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
exports.MigrationError = MigrationError;
|
|
80
|
+
//# sourceMappingURL=orm-errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"orm-errors.js","sourceRoot":"","sources":["../../src/errors/orm-errors.ts"],"names":[],"mappings":";;;AAAA,MAAa,YAAa,SAAQ,KAAK;IACrC,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC;QAClC,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,YAAY,CAAC,SAAS,CAAC,CAAC;IACtD,CAAC;CACF;AAND,oCAMC;AAED,MAAa,eAAgB,SAAQ,YAAY;IAC/C,YAAY,UAAkB;QAC5B,KAAK,CAAC,gCAAgC,GAAG,UAAU,CAAC,CAAC;QACrD,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,eAAe,CAAC,SAAS,CAAC,CAAC;IACzD,CAAC;CACF;AALD,0CAKC;AAED,MAAa,mBAAoB,SAAQ,YAAY;IACnD,YAAY,UAAkB,EAAE,EAAO;QACrC,KAAK,CAAC,UAAU,UAAU,YAAY,EAAE,YAAY,CAAC,CAAC;QACtD,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,mBAAmB,CAAC,SAAS,CAAC,CAAC;IAC7D,CAAC;CACF;AALD,kDAKC;AAED,MAAa,eAAgB,SAAQ,YAAY;IAC/C,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,eAAe,CAAC,SAAS,CAAC,CAAC;IACzD,CAAC;CACF;AALD,0CAKC;AAED,MAAa,kBAAmB,SAAQ,YAAY;IAClD,YAAY,SAAiB,EAAE,aAAqB;QAClD,MAAM,QAAQ,GAAG,aAAa;YAC5B,CAAC,CAAC,0BAA0B,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AC,SAAS,CAAC,CAAC;IACzD,CAAC;CACF;AALD,0CAKC;AAED,MAAa,cAAe,SAAQ,YAAY;IAC9C,YAAY,OAAe,EAAE,SAAiB,EAAE,aAAqB;QACnE,MAAM,QAAQ,GAAG,aAAa;YAC5B,CAAC,CAAC,aAAa,OAAO,IAAI,SAAS,YAAY,aAAa,CAAC,OAAO,EAAE;YACtE,CAAC,CAAC,aAAa,OAAO,IAAI,SAAS,SAAS,CAAC;QAC/C,KAAK,CAAC,QAAQ,CAAC,CAAC;QAChB,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,cAAc,CAAC,SAAS,CAAC,CAAC;IACxD,CAAC;CACF;AARD,wCAQC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function bulkInsert(connection: any, query: string): Promise<void>;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.bulkInsert = bulkInsert;
|
|
4
|
+
async function bulkInsert(connection, query) {
|
|
5
|
+
return new Promise((resolve, reject) => {
|
|
6
|
+
// Add logging to see the exact query being executed
|
|
7
|
+
console.log("Executing bulk insert query:", query);
|
|
8
|
+
connection.run(query, (err) => {
|
|
9
|
+
if (err) {
|
|
10
|
+
console.error("Error bulk inserting!", err);
|
|
11
|
+
reject(err);
|
|
12
|
+
}
|
|
13
|
+
else {
|
|
14
|
+
resolve();
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=bulk-insert.helper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bulk-insert.helper.js","sourceRoot":"","sources":["../../src/helpers/bulk-insert.helper.ts"],"names":[],"mappings":";;AAAA,gCAcC;AAdM,KAAK,UAAU,UAAU,CAAC,UAAe,EAAE,KAAa;IAC3D,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACnC,oDAAoD;QACpD,OAAO,CAAC,GAAG,CAAC,8BAA8B,EAAE,KAAK,CAAC,CAAC;QAEnD,UAAU,CAAC,GAAG,CAAC,KAAK,EAAE,CAAC,GAAQ,EAAE,EAAE;YAC/B,IAAI,GAAG,EAAE,CAAC;gBACN,OAAO,CAAC,KAAK,CAAC,uBAAuB,EAAE,GAAG,CAAC,CAAC;gBAC5C,MAAM,CAAC,GAAG,CAAC,CAAC;YAChB,CAAC;iBAAM,CAAC;gBACJ,OAAO,EAAE,CAAC;YACd,CAAC;QACL,CAAC,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;AACP,CAAC"}
|
|
@@ -6,3 +6,13 @@ export declare function saveToParquet(connection?: Connection, fileName?: string
|
|
|
6
6
|
export declare function deleteTableData(connection?: Connection, fileName?: string): Promise<any[]>;
|
|
7
7
|
export declare function executeQuery(connection?: Connection, query?: string): Promise<any[]>;
|
|
8
8
|
export declare function saveQueryToParquet(connection?: Connection, fileName?: string, query?: string, folder?: string): Promise<void>;
|
|
9
|
+
export declare function exportToCSV(connection: Connection, source: string, fileName: string, options?: {
|
|
10
|
+
header?: boolean;
|
|
11
|
+
delimiter?: string;
|
|
12
|
+
}): Promise<void>;
|
|
13
|
+
export declare function exportToJSON(connection: Connection, source: string, fileName: string, options?: {
|
|
14
|
+
pretty?: boolean;
|
|
15
|
+
}): Promise<void>;
|
|
16
|
+
export declare function exportToParquet(connection: Connection, source: string, fileName: string, options?: {
|
|
17
|
+
compression?: string;
|
|
18
|
+
}): Promise<void>;
|
|
@@ -7,6 +7,9 @@ exports.saveToParquet = saveToParquet;
|
|
|
7
7
|
exports.deleteTableData = deleteTableData;
|
|
8
8
|
exports.executeQuery = executeQuery;
|
|
9
9
|
exports.saveQueryToParquet = saveQueryToParquet;
|
|
10
|
+
exports.exportToCSV = exportToCSV;
|
|
11
|
+
exports.exportToJSON = exportToJSON;
|
|
12
|
+
exports.exportToParquet = exportToParquet;
|
|
10
13
|
async function executeDuckDbQuery(connection, query) {
|
|
11
14
|
return new Promise((resolve, reject) => {
|
|
12
15
|
connection?.run(query ?? "", (err, response) => {
|
|
@@ -99,4 +102,63 @@ async function saveQueryToParquet(connection, fileName, query, folder) {
|
|
|
99
102
|
});
|
|
100
103
|
});
|
|
101
104
|
}
|
|
105
|
+
// Add these export helper functions
|
|
106
|
+
async function exportToCSV(connection, source, fileName, options) {
|
|
107
|
+
const header = options?.header !== false ? 'HEADER' : 'NO_HEADER';
|
|
108
|
+
const delimiter = options?.delimiter ?? ',';
|
|
109
|
+
return new Promise((resolve, reject) => {
|
|
110
|
+
const isQuery = source.trim().toUpperCase().startsWith('SELECT');
|
|
111
|
+
const copyCommand = isQuery
|
|
112
|
+
? `COPY (${source}) TO '${fileName}' (FORMAT CSV, ${header}, DELIMITER '${delimiter}')`
|
|
113
|
+
: `COPY ${source} TO '${fileName}' (FORMAT CSV, ${header}, DELIMITER '${delimiter}')`;
|
|
114
|
+
connection?.run(copyCommand, (err) => {
|
|
115
|
+
if (err) {
|
|
116
|
+
console.error('CSV export failed:', err);
|
|
117
|
+
reject(err);
|
|
118
|
+
}
|
|
119
|
+
else {
|
|
120
|
+
console.log(`Exported to CSV: ${fileName}`);
|
|
121
|
+
resolve();
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
async function exportToJSON(connection, source, fileName, options) {
|
|
127
|
+
const formatOption = options?.pretty ? 'FORMAT JSON, ARRAY TRUE' : 'FORMAT JSON';
|
|
128
|
+
return new Promise((resolve, reject) => {
|
|
129
|
+
const isQuery = source.trim().toUpperCase().startsWith('SELECT');
|
|
130
|
+
const copyCommand = isQuery
|
|
131
|
+
? `COPY (${source}) TO '${fileName}' (${formatOption})`
|
|
132
|
+
: `COPY ${source} TO '${fileName}' (${formatOption})`;
|
|
133
|
+
connection?.run(copyCommand, (err) => {
|
|
134
|
+
if (err) {
|
|
135
|
+
console.error('JSON export failed:', err);
|
|
136
|
+
reject(err);
|
|
137
|
+
}
|
|
138
|
+
else {
|
|
139
|
+
console.log(`Exported to JSON: ${fileName}`);
|
|
140
|
+
resolve();
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
async function exportToParquet(connection, source, fileName, options) {
|
|
146
|
+
const compression = options?.compression ?? 'ZSTD'; // Default to ZSTD compression
|
|
147
|
+
return new Promise((resolve, reject) => {
|
|
148
|
+
const isQuery = source.trim().toUpperCase().startsWith('SELECT');
|
|
149
|
+
const copyCommand = isQuery
|
|
150
|
+
? `COPY (${source}) TO '${fileName}' (FORMAT PARQUET, COMPRESSION ${compression})`
|
|
151
|
+
: `COPY ${source} TO '${fileName}' (FORMAT PARQUET, COMPRESSION ${compression})`;
|
|
152
|
+
connection?.run(copyCommand, (err) => {
|
|
153
|
+
if (err) {
|
|
154
|
+
console.error('Parquet export failed:', err);
|
|
155
|
+
reject(err);
|
|
156
|
+
}
|
|
157
|
+
else {
|
|
158
|
+
console.log(`Exported to Parquet: ${fileName}`);
|
|
159
|
+
resolve();
|
|
160
|
+
}
|
|
161
|
+
});
|
|
162
|
+
});
|
|
163
|
+
}
|
|
102
164
|
//# sourceMappingURL=db.helper.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"db.helper.js","sourceRoot":"","sources":["../../src/helpers/db.helper.ts"],"names":[],"mappings":";;AAIA,gDASC;AAED,gCAOC;AAED,8BAOC;AAED,sCAmBC;AAED,0CAWC;AAED,oCAWC;AAED,gDAkBC;
|
|
1
|
+
{"version":3,"file":"db.helper.js","sourceRoot":"","sources":["../../src/helpers/db.helper.ts"],"names":[],"mappings":";;AAIA,gDASC;AAED,gCAOC;AAED,8BAOC;AAED,sCAmBC;AAED,0CAWC;AAED,oCAWC;AAED,gDAkBC;AAID,kCAoBC;AAED,oCAmBC;AAED,0CAmBC;AAhKM,KAAK,UAAU,kBAAkB,CAAC,UAAuB,EAAE,KAAc;IAC5E,OAAO,IAAI,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BAAM,CAAC;gBACJ,OAAO,CAAC,GAAG,CAAC,qBAAqB,QAAQ,EAAE,CAAC,CAAC;gBAC7C,OAAO,EAAE,CAAC;YACd,CAAC;QACL,CAAC,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;AACP,CAAC;AAEM,KAAK,UAAU,eAAe,CAAC,UAAsB,EAAE,MAAc,EAAE,QAAgB,EAAE,OAAkC;IAC9H,MAAM,WAAW,GAAG,OAAO,EAAE,WAAW,IAAI,MAAM,CAAC,CAAC,8BAA8B;IAElF,OAAO,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACzC,MAAM,OAAO,GAAG,MAAM,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC;QACjE,MAAM,WAAW,GAAG,OAAO;YACvB,CAAC,CAAC,SAAS,MAAM,SAAS,QAAQ,kCAAkC,WAAW,GAAG;YAClF,CAAC,CAAC,QAAQ,MAAM,QAAQ,QAAQ,kCAAkC,WAAW,GAAG,CAAC;QAErF,UAAU,EAAE,GAAG,CAAC,WAAW,EAAE,CAAC,GAAG,EAAE,EAAE;YACjC,IAAI,GAAG,EAAE,CAAC;gBACN,OAAO,CAAC,KAAK,CAAC,wBAAwB,EAAE,GAAG,CAAC,CAAC;gBAC7C,MAAM,CAAC,GAAG,CAAC,CAAC;YAChB,CAAC;iBAAM,CAAC;gBACJ,OAAO,CAAC,GAAG,CAAC,wBAAwB,QAAQ,EAAE,CAAC,CAAC;gBAChD,OAAO,EAAE,CAAC;YACd,CAAC;QACL,CAAC,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;AACP,CAAC"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export declare function modelToArray<T>(model: T, classType: new () => T): unknown[];
|
|
2
|
-
export declare function mapToSQLFieldsValues<T>(
|
|
2
|
+
export declare function mapToSQLFieldsValues<T>(data: T, classType: new () => T): string;
|
|
3
3
|
export declare function parseJson(input: any): any;
|
|
@@ -12,42 +12,42 @@ function modelToArray(model, classType) {
|
|
|
12
12
|
}
|
|
13
13
|
return array;
|
|
14
14
|
}
|
|
15
|
-
function mapToSQLFieldsValues(
|
|
16
|
-
const
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
obj = `'${JSON.stringify(item)}'`;
|
|
42
|
-
}
|
|
43
|
-
break;
|
|
44
|
-
default:
|
|
45
|
-
obj = 'null';
|
|
46
|
-
break;
|
|
15
|
+
function mapToSQLFieldsValues(data, classType) {
|
|
16
|
+
const fields = [];
|
|
17
|
+
const values = [];
|
|
18
|
+
// Get property names from the entity
|
|
19
|
+
const propertyNames = Object.getOwnPropertyNames(data);
|
|
20
|
+
for (const propertyName of propertyNames) {
|
|
21
|
+
// Skip auto-increment primary keys
|
|
22
|
+
const autoIncrement = Reflect.getMetadata('AutoIncrement', classType.prototype, propertyName);
|
|
23
|
+
const isPrimaryKey = Reflect.getMetadata('PrimaryKey', classType.prototype, propertyName);
|
|
24
|
+
if (autoIncrement && isPrimaryKey) {
|
|
25
|
+
continue; // Skip this field in the INSERT statement
|
|
26
|
+
}
|
|
27
|
+
// Get the value
|
|
28
|
+
const value = data[propertyName];
|
|
29
|
+
// Add field name
|
|
30
|
+
fields.push(propertyName);
|
|
31
|
+
// Format value based on its type
|
|
32
|
+
if (value === undefined || value === null) {
|
|
33
|
+
values.push('NULL');
|
|
34
|
+
}
|
|
35
|
+
else if (typeof value === 'string') {
|
|
36
|
+
const escapedValue = value.replace(/'/g, "''");
|
|
37
|
+
values.push(`'${escapedValue}'`);
|
|
38
|
+
}
|
|
39
|
+
else if (typeof value === 'boolean') {
|
|
40
|
+
values.push(value ? 'TRUE' : 'FALSE');
|
|
47
41
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
42
|
+
else {
|
|
43
|
+
values.push(`${value}`);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
// Make sure we have fields to insert
|
|
47
|
+
if (fields.length === 0) {
|
|
48
|
+
throw new Error("No fields available for insert after excluding auto-increment fields");
|
|
49
|
+
}
|
|
50
|
+
return `(${fields.join(', ')}) VALUES (${values.join(', ')})`;
|
|
51
51
|
}
|
|
52
52
|
function parseJson(input) {
|
|
53
53
|
return input ? JSON.parse(input) : null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mapping.helper.js","sourceRoot":"","sources":["../../src/helpers/mapping.helper.ts"],"names":[],"mappings":";AAAA,uDAAuD;;AAEvD,oCAOC;AAED,
|
|
1
|
+
{"version":3,"file":"mapping.helper.js","sourceRoot":"","sources":["../../src/helpers/mapping.helper.ts"],"names":[],"mappings":";AAAA,uDAAuD;;AAEvD,oCAOC;AAED,oDAyCC;AAED,8BAEC;AAtDD,SAAgB,YAAY,CAAI,KAAQ,EAAE,SAAqB;IAC3D,MAAM,aAAa,GAAG,MAAM,CAAC,mBAAmB,CAAC,IAAI,SAAS,EAAE,CAAC,CAAC;IAClE,MAAM,KAAK,GAAG,EAAE,CAAC;IACjB,KAAK,MAAM,YAAY,IAAI,aAAa,EAAE,CAAC;QACvC,KAAK,CAAC,IAAI,CAAE,KAAa,CAAC,YAAY,CAAC,CAAC,CAAC;IAC7C,CAAC;IACD,OAAO,KAAK,CAAC;AACjB,CAAC;AAED,SAAgB,oBAAoB,CAAI,IAAO,EAAE,SAAsB;IACnE,MAAM,MAAM,GAAa,EAAE,CAAC;IAC5B,MAAM,MAAM,GAAa,EAAE,CAAC;IAE5B,qCAAqC;IACrC,MAAM,aAAa,GAAG,MAAM,CAAC,mBA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5F,CAAC;IAED,OAAO,IAAI,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,aAAa,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC;AAClE,CAAC;AAED,SAAgB,SAAS,CAAC,KAAU;IAChC,OAAO,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;AAC5C,CAAC"}
|
|
@@ -6,6 +6,7 @@ exports.getPrimaryId = getPrimaryId;
|
|
|
6
6
|
exports.generateCreateTableStatement = generateCreateTableStatement;
|
|
7
7
|
exports.generateInsertIntoStatement = generateInsertIntoStatement;
|
|
8
8
|
require("reflect-metadata");
|
|
9
|
+
const orm_errors_1 = require("../errors/orm-errors");
|
|
9
10
|
function getClassName(classType) {
|
|
10
11
|
return classType.name;
|
|
11
12
|
}
|
|
@@ -31,42 +32,68 @@ function generateCreateTableStatement(tableName, classType) {
|
|
|
31
32
|
// Get the property names from the class using reflection
|
|
32
33
|
const propertyNames = Object.getOwnPropertyNames(new classType());
|
|
33
34
|
let primaryKeys = 0;
|
|
35
|
+
const constraints = [];
|
|
36
|
+
// Get sequences that were already created
|
|
37
|
+
const sequences = Reflect.getMetadata('Sequences', classType) || {};
|
|
34
38
|
for (let i = 0; i < propertyNames.length; i++) {
|
|
35
39
|
const propertyName = propertyNames[i];
|
|
36
|
-
// Retrieve
|
|
37
|
-
const propertyType = Reflect.getMetadata('FieldType', classType.prototype, propertyName);
|
|
40
|
+
// Retrieve column metadata using reflection
|
|
41
|
+
const propertyType = Reflect.getMetadata('FieldType', classType.prototype, propertyName) || 'VARCHAR';
|
|
38
42
|
const primaryKey = Reflect.getMetadata('PrimaryKey', classType.prototype, propertyName);
|
|
39
43
|
const unique = Reflect.getMetadata('Unique', classType.prototype, propertyName);
|
|
44
|
+
const notNull = Reflect.getMetadata('NotNull', classType.prototype, propertyName);
|
|
45
|
+
const defaultValue = Reflect.getMetadata('DefaultValue', classType.prototype, propertyName);
|
|
46
|
+
const check = Reflect.getMetadata('Check', classType.prototype, propertyName);
|
|
47
|
+
const autoIncrement = Reflect.getMetadata('AutoIncrement', classType.prototype, propertyName);
|
|
40
48
|
// Append the column definition to the statement
|
|
41
|
-
createTableStatement += `${propertyName} ${propertyType
|
|
49
|
+
createTableStatement += `${propertyName} ${propertyType}`;
|
|
50
|
+
// Add constraints inline with the column
|
|
42
51
|
if (primaryKey) {
|
|
43
52
|
createTableStatement += ' PRIMARY KEY';
|
|
44
53
|
primaryKeys++;
|
|
45
54
|
}
|
|
46
|
-
if (
|
|
55
|
+
if (autoIncrement && sequences[propertyName]) {
|
|
56
|
+
const sequenceName = sequences[propertyName];
|
|
57
|
+
createTableStatement += ` DEFAULT nextval('${sequenceName}')`;
|
|
58
|
+
}
|
|
59
|
+
else if (defaultValue !== undefined) {
|
|
60
|
+
if (typeof defaultValue === 'string') {
|
|
61
|
+
createTableStatement += ` DEFAULT '${defaultValue}'`;
|
|
62
|
+
}
|
|
63
|
+
else if (defaultValue === null) {
|
|
64
|
+
createTableStatement += ' DEFAULT NULL';
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
createTableStatement += ` DEFAULT ${defaultValue}`;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
if (notNull) {
|
|
71
|
+
createTableStatement += ' NOT NULL';
|
|
72
|
+
}
|
|
73
|
+
if (unique) {
|
|
47
74
|
createTableStatement += ' UNIQUE';
|
|
48
|
-
|
|
49
|
-
|
|
75
|
+
}
|
|
76
|
+
// Add check constraints to a collection to add after all columns
|
|
77
|
+
if (check) {
|
|
78
|
+
constraints.push(`CHECK (${check})`);
|
|
79
|
+
}
|
|
80
|
+
// Add a comma if it's not the last property or if we have constraints to add
|
|
81
|
+
if (i < propertyNames.length - 1 || constraints.length > 0) {
|
|
50
82
|
createTableStatement += ', ';
|
|
51
83
|
}
|
|
52
84
|
}
|
|
85
|
+
// Add any additional constraints
|
|
86
|
+
if (constraints.length > 0) {
|
|
87
|
+
createTableStatement += constraints.join(', ');
|
|
88
|
+
}
|
|
53
89
|
// Close the CREATE TABLE statement
|
|
54
90
|
createTableStatement += ');';
|
|
55
|
-
if (primaryKeys > 1)
|
|
56
|
-
throw new
|
|
91
|
+
if (primaryKeys > 1) {
|
|
92
|
+
throw new orm_errors_1.PrimaryKeyError('Multiple primary keys are not supported!');
|
|
93
|
+
}
|
|
57
94
|
return createTableStatement;
|
|
58
95
|
}
|
|
59
96
|
function generateInsertIntoStatement(tableName, classType) {
|
|
60
|
-
|
|
61
|
-
const propertyNames = Object.getOwnPropertyNames(new classType());
|
|
62
|
-
for (let i = 0; i < propertyNames.length; i++) {
|
|
63
|
-
const propertyName = propertyNames[i];
|
|
64
|
-
insertIntoTableStatement += `${propertyName}`;
|
|
65
|
-
if (i < propertyNames.length - 1) {
|
|
66
|
-
insertIntoTableStatement += ', ';
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
insertIntoTableStatement += ') VALUES ';
|
|
70
|
-
return insertIntoTableStatement;
|
|
97
|
+
return `INSERT INTO main.${tableName} `;
|
|
71
98
|
}
|
|
72
99
|
//# sourceMappingURL=table-util.helper.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"table-util.helper.js","sourceRoot":"","sources":["../../src/helpers/table-util.helper.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"table-util.helper.js","sourceRoot":"","sources":["../../src/helpers/table-util.helper.ts"],"names":[],"mappings":";;AAGA,oCAEC;AAED,oCAEC;AAED,oCAiBC;AAID,oEA6EC;AAED,kEAEC;AAjHD,4BAA0B;AAC1B,qDAA2E;AAE3E,SAAgB,YAAY,CAAI,SAAqB;IACjD,OAAO,SAAS,CAAC,IAAI,CAAC;AAC1B,CAAC;AAED,SAAgB,YAAY,CAAI,SAAqB;IACjD,OAAO,YAAY,CAAC,SAAS,CAAC,CAAC;AACnC,CAAC;AAED,SAAgB,YAAY,CAAI,SAAqB;IACj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D,CAAC;QACL,CAAC;QAED,IAAI,OAAO,EAAE,CAAC;YACV,oBAAoB,IAAI,WAAW,CAAC;QACxC,CAAC;QAED,IAAI,MAAM,EAAE,CAAC;YACT,oBAAoB,IAAI,SAAS,CAAC;QACtC,CAAC;QAED,iEAAiE;QACjE,IAAI,KAAK,EAAE,CAAC;YACR,WAAW,CAAC,IAAI,CAAC,UAAU,KAAK,GAAG,CAAC,CAAC;QACzC,CAAC;QAED,6EAA6E;QAC7E,IAAI,CAAC,GAAG,aAAa,CAAC,MAAM,GAAG,CAAC,IAAI,WAAW,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACzD,oBAAoB,IAAI,IAAI,CAAC;QACjC,CAAC;IACL,CAAC;IAED,iCAAiC;IACjC,IAAI,WAAW,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACzB,oBAAoB,IAAI,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACnD,CAAC;IAED,mCAAmC;IACnC,oBAAoB,IAAI,IAAI,CAAC;IAE7B,IAAI,WAAW,GAAG,CAAC,EAAE,CAAC;QAClB,MAAM,IAAI,4BAAe,CAAC,0CAA0C,CAAC,CAAC;IAC1E,CAAC;IAED,OAAO,oBAAoB,CAAC;AAChC,CAAC;AAED,SAAgB,2BAA2B,CAAI,SAAiB,EAAE,SAAqB;IACnF,OAAO,oBAAoB,SAAS,GAAG,CAAC;AAC5C,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
import 'reflect-metadata';
|
|
2
|
-
import { DataTypeDecorator, Entity, Id, Repository, Unique } from "./constants/data-type.decorator";
|
|
2
|
+
import { DataTypeDecorator, Entity, Id, Repository, Unique, Column, ColumnOptions, NotNull, Default, Check, AutoIncrement, TableOptions } from "./constants/data-type.decorator";
|
|
3
3
|
import { BaseRepository } from "./repositories/base.repository";
|
|
4
|
-
import { DuckDbRepository, DuckDbConfig, DuckDbLocation } from './repositories/duckdb.repository';
|
|
4
|
+
import { DuckDbRepository, DuckDbConfig, DuckDbLocation, ExportOptions } from './repositories/duckdb.repository';
|
|
5
5
|
import { IRepository } from './repositories/base.interface';
|
|
6
6
|
import { getClassName, getTableName, getPrimaryId, generateCreateTableStatement, generateInsertIntoStatement } from './helpers/table-util.helper';
|
|
7
|
-
|
|
7
|
+
import { QueryBuilder } from './query/query-builder';
|
|
8
|
+
import { Transaction } from './repositories/transaction';
|
|
9
|
+
import { Page, Pageable } from './pagination/pagination';
|
|
10
|
+
import { Migration, MigrationRunner, MigrationOptions } from './migration/migration';
|
|
11
|
+
import { ConnectionError } from './errors/orm-errors';
|
|
12
|
+
import { OrmBaseError, EntityNotFoundError, PrimaryKeyError, TableCreationError, QueryExecutionError, TransactionError, ValidationError, MigrationError } from './errors/orm-errors';
|
|
13
|
+
export { DataTypeDecorator, Id, Unique, BaseRepository, Entity, Repository, DuckDbRepository, IRepository, DuckDbConfig, DuckDbLocation, getClassName, getTableName, getPrimaryId, generateCreateTableStatement, generateInsertIntoStatement, QueryBuilder, Transaction, Page, Pageable, Migration, MigrationRunner, MigrationOptions, Column, ColumnOptions, NotNull, Default, Check, AutoIncrement, TableOptions, OrmBaseError, ConnectionError, EntityNotFoundError, PrimaryKeyError, TableCreationError, QueryExecutionError, TransactionError, ValidationError, MigrationError, ExportOptions };
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.generateInsertIntoStatement = exports.generateCreateTableStatement = exports.getPrimaryId = exports.getTableName = exports.getClassName = exports.DuckDbLocation = exports.DuckDbRepository = exports.Repository = exports.Entity = exports.BaseRepository = exports.Unique = exports.Id = exports.DataTypeDecorator = void 0;
|
|
3
|
+
exports.MigrationError = exports.ValidationError = exports.TransactionError = exports.QueryExecutionError = exports.TableCreationError = exports.PrimaryKeyError = exports.EntityNotFoundError = exports.ConnectionError = exports.OrmBaseError = exports.AutoIncrement = exports.Check = exports.Default = exports.NotNull = exports.Column = exports.MigrationRunner = exports.Migration = exports.Transaction = exports.QueryBuilder = exports.generateInsertIntoStatement = exports.generateCreateTableStatement = exports.getPrimaryId = exports.getTableName = exports.getClassName = exports.DuckDbLocation = exports.DuckDbRepository = exports.Repository = exports.Entity = exports.BaseRepository = exports.Unique = exports.Id = exports.DataTypeDecorator = void 0;
|
|
4
4
|
require("reflect-metadata");
|
|
5
5
|
const data_type_decorator_1 = require("./constants/data-type.decorator");
|
|
6
6
|
Object.defineProperty(exports, "DataTypeDecorator", { enumerable: true, get: function () { return data_type_decorator_1.DataTypeDecorator; } });
|
|
@@ -8,6 +8,11 @@ Object.defineProperty(exports, "Entity", { enumerable: true, get: function () {
|
|
|
8
8
|
Object.defineProperty(exports, "Id", { enumerable: true, get: function () { return data_type_decorator_1.Id; } });
|
|
9
9
|
Object.defineProperty(exports, "Repository", { enumerable: true, get: function () { return data_type_decorator_1.Repository; } });
|
|
10
10
|
Object.defineProperty(exports, "Unique", { enumerable: true, get: function () { return data_type_decorator_1.Unique; } });
|
|
11
|
+
Object.defineProperty(exports, "Column", { enumerable: true, get: function () { return data_type_decorator_1.Column; } });
|
|
12
|
+
Object.defineProperty(exports, "NotNull", { enumerable: true, get: function () { return data_type_decorator_1.NotNull; } });
|
|
13
|
+
Object.defineProperty(exports, "Default", { enumerable: true, get: function () { return data_type_decorator_1.Default; } });
|
|
14
|
+
Object.defineProperty(exports, "Check", { enumerable: true, get: function () { return data_type_decorator_1.Check; } });
|
|
15
|
+
Object.defineProperty(exports, "AutoIncrement", { enumerable: true, get: function () { return data_type_decorator_1.AutoIncrement; } });
|
|
11
16
|
const base_repository_1 = require("./repositories/base.repository");
|
|
12
17
|
Object.defineProperty(exports, "BaseRepository", { enumerable: true, get: function () { return base_repository_1.BaseRepository; } });
|
|
13
18
|
const duckdb_repository_1 = require("./repositories/duckdb.repository");
|
|
@@ -19,4 +24,22 @@ Object.defineProperty(exports, "getTableName", { enumerable: true, get: function
|
|
|
19
24
|
Object.defineProperty(exports, "getPrimaryId", { enumerable: true, get: function () { return table_util_helper_1.getPrimaryId; } });
|
|
20
25
|
Object.defineProperty(exports, "generateCreateTableStatement", { enumerable: true, get: function () { return table_util_helper_1.generateCreateTableStatement; } });
|
|
21
26
|
Object.defineProperty(exports, "generateInsertIntoStatement", { enumerable: true, get: function () { return table_util_helper_1.generateInsertIntoStatement; } });
|
|
27
|
+
const query_builder_1 = require("./query/query-builder");
|
|
28
|
+
Object.defineProperty(exports, "QueryBuilder", { enumerable: true, get: function () { return query_builder_1.QueryBuilder; } });
|
|
29
|
+
const transaction_1 = require("./repositories/transaction");
|
|
30
|
+
Object.defineProperty(exports, "Transaction", { enumerable: true, get: function () { return transaction_1.Transaction; } });
|
|
31
|
+
const migration_1 = require("./migration/migration");
|
|
32
|
+
Object.defineProperty(exports, "Migration", { enumerable: true, get: function () { return migration_1.Migration; } });
|
|
33
|
+
Object.defineProperty(exports, "MigrationRunner", { enumerable: true, get: function () { return migration_1.MigrationRunner; } });
|
|
34
|
+
const orm_errors_1 = require("./errors/orm-errors");
|
|
35
|
+
Object.defineProperty(exports, "ConnectionError", { enumerable: true, get: function () { return orm_errors_1.ConnectionError; } });
|
|
36
|
+
const orm_errors_2 = require("./errors/orm-errors");
|
|
37
|
+
Object.defineProperty(exports, "OrmBaseError", { enumerable: true, get: function () { return orm_errors_2.OrmBaseError; } });
|
|
38
|
+
Object.defineProperty(exports, "EntityNotFoundError", { enumerable: true, get: function () { return orm_errors_2.EntityNotFoundError; } });
|
|
39
|
+
Object.defineProperty(exports, "PrimaryKeyError", { enumerable: true, get: function () { return orm_errors_2.PrimaryKeyError; } });
|
|
40
|
+
Object.defineProperty(exports, "TableCreationError", { enumerable: true, get: function () { return orm_errors_2.TableCreationError; } });
|
|
41
|
+
Object.defineProperty(exports, "QueryExecutionError", { enumerable: true, get: function () { return orm_errors_2.QueryExecutionError; } });
|
|
42
|
+
Object.defineProperty(exports, "TransactionError", { enumerable: true, get: function () { return orm_errors_2.TransactionError; } });
|
|
43
|
+
Object.defineProperty(exports, "ValidationError", { enumerable: true, get: function () { return orm_errors_2.ValidationError; } });
|
|
44
|
+
Object.defineProperty(exports, "MigrationError", { enumerable: true, get: function () { return orm_errors_2.MigrationError; } });
|
|
22
45
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,4BAA0B;AAC1B,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,4BAA0B;AAC1B,yEAGyC;AAiBrC,kGAnBA,uCAAiB,OAmBA;AAIjB,uFAvBmB,4BAAM,OAuBnB;AAHN,mFApB2B,wBAAE,OAoB3B;AAIF,2FAxB+B,gCAAU,OAwB/B;AAHV,uFArB2C,4BAAM,OAqB3C;AAsBN,uFA1CA,4BAAM,OA0CA;AAEN,wFA5CuB,6BAAO,OA4CvB;AACP,wFA7CgC,6BAAO,OA6ChC;AACP,sFA9CyC,2BAAK,OA8CzC;AACL,8FA/CgD,mCAAa,OA+ChD;AA7CjB,oEAAgE;AAmB5D,+FAnBK,gCAAc,OAmBL;AAlBlB,wEAAiH;AAqB7G,iGArBK,oCAAgB,OAqBL;AAGhB,+FAxBqC,kCAAc,OAwBrC;AAtBlB,mEAAkJ;AAuB9I,6FAvBK,gCAAY,OAuBL;AACZ,6FAxBmB,gCAAY,OAwBnB;AACZ,6FAzBiC,gCAAY,OAyBjC;AACZ,6GA1B+C,gDAA4B,OA0B/C;AAC5B,4GA3B6E,+CAA2B,OA2B7E;AA1B/B,yDAAqD;AA2BjD,6FA3BK,4BAAY,OA2BL;AA1BhB,4DAAyD;AA2BrD,4FA3BK,yBAAW,OA2BL;AAzBf,qDAAqF;AA4BjF,0FA5BK,qBAAS,OA4BL;AACT,gGA7BgB,2BAAe,OA6BhB;AA5BnB,oDAAsD;AA0ClD,gGA1CK,4BAAe,OA0CL;AAzCnB,oDAG6B;AAqCzB,6FAvCA,yBAAY,OAuCA;AAEZ,oGAzCc,gCAAmB,OAyCd;AACnB,gGA1CmC,4BAAe,OA0CnC;AACf,mGA3CoD,+BAAkB,OA2CpD;AAClB,oGA3CA,gCAAmB,OA2CA;AACnB,iGA5CqB,6BAAgB,OA4CrB;AAChB,gGA7CuC,4BAAe,OA6CvC;AACf,+FA9CwD,2BAAc,OA8CxD"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Connection } from 'duckdb';
|
|
2
|
+
export interface MigrationOptions {
|
|
3
|
+
tableName?: string;
|
|
4
|
+
}
|
|
5
|
+
export declare abstract class Migration {
|
|
6
|
+
abstract version: string;
|
|
7
|
+
abstract up(): string;
|
|
8
|
+
abstract down(): string;
|
|
9
|
+
}
|
|
10
|
+
export declare class MigrationRunner {
|
|
11
|
+
private readonly connection;
|
|
12
|
+
private readonly migrationTableName;
|
|
13
|
+
constructor(connection: Connection, options?: MigrationOptions);
|
|
14
|
+
initialize(): Promise<void>;
|
|
15
|
+
private createMigrationTableIfNotExists;
|
|
16
|
+
applyMigrations(migrations: Migration[]): Promise<void>;
|
|
17
|
+
revertMigrations(migrations: Migration[], targetVersion?: string): Promise<void>;
|
|
18
|
+
private getAppliedMigrations;
|
|
19
|
+
private applyMigration;
|
|
20
|
+
private revertMigration;
|
|
21
|
+
private executeQuery;
|
|
22
|
+
}
|