duckdb-tinyorm 1.0.0 → 1.0.2

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.
@@ -0,0 +1,6 @@
1
+ import 'reflect-metadata';
2
+ export declare function DataTypeDecorator(dataType: string): PropertyDecorator;
3
+ export declare function Id(): PropertyDecorator;
4
+ export declare function Unique(): PropertyDecorator;
5
+ export declare function Entity(target: Function): void;
6
+ export declare function Repository(entity: new () => any): (target: Function) => void;
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DataTypeDecorator = DataTypeDecorator;
4
+ exports.Id = Id;
5
+ exports.Unique = Unique;
6
+ exports.Entity = Entity;
7
+ exports.Repository = Repository;
8
+ /* eslint-disable @typescript-eslint/no-explicit-any */
9
+ require("reflect-metadata");
10
+ function DataTypeDecorator(dataType) {
11
+ return function (target, propertyKey) {
12
+ let propertyValue;
13
+ const descriptor = Object.getOwnPropertyDescriptor(target, propertyKey);
14
+ if (descriptor) {
15
+ // Modify the descriptor to include the specified data type
16
+ descriptor.value = propertyValue;
17
+ descriptor.writable = true;
18
+ descriptor.enumerable = true;
19
+ descriptor.configurable = true;
20
+ Object.defineProperty(target, propertyKey, descriptor);
21
+ }
22
+ else {
23
+ // If the property doesn't exist, create it with the specified data type
24
+ Object.defineProperty(target, propertyKey, {
25
+ value: propertyValue,
26
+ writable: true,
27
+ enumerable: true,
28
+ configurable: true,
29
+ });
30
+ }
31
+ // Set the data type as metadata using Reflect.defineMetadata
32
+ Reflect.defineMetadata('FieldType', dataType, target, propertyKey);
33
+ };
34
+ }
35
+ function Id() {
36
+ return function (target, propertyKey) {
37
+ Reflect.defineMetadata('PrimaryKey', true, target, propertyKey);
38
+ };
39
+ }
40
+ function Unique() {
41
+ return function (target, propertyKey) {
42
+ Reflect.defineMetadata('Unique', true, target, propertyKey);
43
+ };
44
+ }
45
+ function Entity(target) {
46
+ // Add metadata to the class using the 'entityType' key
47
+ Reflect.defineMetadata('entityType', target, target);
48
+ }
49
+ // Apply this decorator to the repository class, not the entity
50
+ function Repository(entity) {
51
+ return function (target) {
52
+ Reflect.defineMetadata('entityType', entity, target);
53
+ };
54
+ }
55
+ //# sourceMappingURL=data-type.decorator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"data-type.decorator.js","sourceRoot":"","sources":["../../src/constants/data-type.decorator.ts"],"names":[],"mappings":";;AAGA,8CAyBC;AAGD,gBAIC;AAED,wBAIC;AAGD,wBAGC;AAGD,gCAIC;AAtDD,uDAAuD;AACvD,4BAA0B;AAE1B,SAAgB,iBAAiB,CAAC,QAAgB;IAC9C,OAAO,UAAU,MAAW,EAAE,WAA4B;QACtD,IAAI,aAAkB,CAAC;QACvB,MAAM,UAAU,GAAG,MAAM,CAAC,wBAAwB,CAAC,MAAM,EAAE,WAAqB,CAAC,CAAC;QAElF,IAAI,UAAU,EAAE,CAAC;YACb,2DAA2D;YAC3D,UAAU,CAAC,KAAK,GAAG,aAAa,CAAC;YACjC,UAAU,CAAC,QAAQ,GAAG,IAAI,CAAC;YAC3B,UAAU,CAAC,UAAU,GAAG,IAAI,CAAC;YAC7B,UAAU,CAAC,YAAY,GAAG,IAAI,CAAC;YAC/B,MAAM,CAAC,cAAc,CAAC,MAAM,EAAE,WAAW,EAAE,UAAU,CAAC,CAAC;QAC3D,CAAC;aAAM,CAAC;YACJ,wEAAwE;YACxE,MAAM,CAAC,cAAc,CAAC,MAAM,EAAE,WAAW,EAAE;gBACvC,KAAK,EAAE,aAAa;gBACpB,QAAQ,EAAE,IAAI;gBACd,UAAU,EAAE,IAAI;gBAChB,YAAY,EAAE,IAAI;aACrB,CAAC,CAAC;QACP,CAAC;QAED,6DAA6D;QAC7D,OAAO,CAAC,cAAc,CAAC,WAAW,EAAE,QAAQ,EAAE,MAAM,EAAE,WAAW,CAAC,CAAC;IACvE,CAAC,CAAC;AACN,CAAC;AAGD,SAAgB,EAAE;IACd,OAAO,UAAU,MAAW,EAAE,WAA4B;QACtD,OAAO,CAAC,cAAc,CAAC,YAAY,EAAE,IAAI,EAAE,MAAM,EAAE,WAAW,CAAC,CAAC;IACpE,CAAC,CAAC;AACN,CAAC;AAED,SAAgB,MAAM;IAClB,OAAO,UAAU,MAAW,EAAE,WAA4B;QACtD,OAAO,CAAC,cAAc,CAAC,QAAQ,EAAE,IAAI,EAAE,MAAM,EAAE,WAAW,CAAC,CAAC;IAChE,CAAC,CAAC;AACN,CAAC;AAGD,SAAgB,MAAM,CAAC,MAAgB;IACnC,uDAAuD;IACvD,OAAO,CAAC,cAAc,CAAC,YAAY,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;AACzD,CAAC;AAED,+DAA+D;AAC/D,SAAgB,UAAU,CAAC,MAAqB;IAC5C,OAAO,UAAU,MAAgB;QAC7B,OAAO,CAAC,cAAc,CAAC,YAAY,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;IACzD,CAAC,CAAC;AACN,CAAC"}
@@ -0,0 +1,8 @@
1
+ import { Connection } from 'duckdb';
2
+ export declare function executeDuckDbQuery(connection?: Connection, query?: string): Promise<void>;
3
+ export declare function bulkInsert(connection?: Connection, query?: string): Promise<void>;
4
+ export declare function dropTable(connection?: Connection, tableName?: string): Promise<void>;
5
+ export declare function saveToParquet(connection?: Connection, fileName?: string, tableName?: string, folder?: string): Promise<void>;
6
+ export declare function deleteTableData(connection?: Connection, fileName?: string): Promise<any[]>;
7
+ export declare function executeQuery(connection?: Connection, query?: string): Promise<any[]>;
8
+ export declare function saveQueryToParquet(connection?: Connection, fileName?: string, query?: string, folder?: string): Promise<void>;
@@ -0,0 +1,102 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.executeDuckDbQuery = executeDuckDbQuery;
4
+ exports.bulkInsert = bulkInsert;
5
+ exports.dropTable = dropTable;
6
+ exports.saveToParquet = saveToParquet;
7
+ exports.deleteTableData = deleteTableData;
8
+ exports.executeQuery = executeQuery;
9
+ exports.saveQueryToParquet = saveQueryToParquet;
10
+ async function executeDuckDbQuery(connection, query) {
11
+ return new Promise((resolve, reject) => {
12
+ connection?.run(query ?? "", (err, response) => {
13
+ if (err) {
14
+ return reject(err);
15
+ }
16
+ return resolve(response);
17
+ });
18
+ });
19
+ }
20
+ async function bulkInsert(connection, query) {
21
+ try {
22
+ await executeDuckDbQuery(connection, query);
23
+ }
24
+ catch (err) {
25
+ console.error('Error bulk inserting!', err);
26
+ }
27
+ }
28
+ async function dropTable(connection, tableName) {
29
+ const query = `DROP TABLE IF EXISTS ${tableName}`;
30
+ try {
31
+ await executeDuckDbQuery(connection, query);
32
+ }
33
+ catch (err) {
34
+ console.error(`Error dropping table "${tableName}":`, err);
35
+ }
36
+ }
37
+ async function saveToParquet(connection, fileName, tableName, folder) {
38
+ return new Promise((resolve, reject) => {
39
+ connection?.run(`COPY ${tableName} TO '${fileName}' (FORMAT PARQUET, COMPRESSION ZSTD)`, async function (err) {
40
+ if (err) {
41
+ console.log('dump failed', err);
42
+ reject(err);
43
+ }
44
+ else {
45
+ console.log(`Dumped table ${tableName} into ${fileName}`);
46
+ try {
47
+ // await fs.unlink(fileName);
48
+ resolve();
49
+ }
50
+ catch (err) {
51
+ console.log('Error uploading Parquet file to Azure Blob Storage:', err);
52
+ return Promise.reject(err);
53
+ }
54
+ }
55
+ });
56
+ });
57
+ }
58
+ async function deleteTableData(connection, fileName) {
59
+ return new Promise((resolve, reject) => {
60
+ connection?.all(`DROP TABLE ${fileName}`, (err, table) => {
61
+ if (err) {
62
+ return Promise.reject(err);
63
+ }
64
+ else {
65
+ return resolve(table);
66
+ }
67
+ });
68
+ });
69
+ }
70
+ async function executeQuery(connection, query) {
71
+ return new Promise((resolve, reject) => {
72
+ connection?.all(query ?? "", (err, table) => {
73
+ if (err) {
74
+ return Promise.reject(err);
75
+ }
76
+ else {
77
+ return resolve(table);
78
+ }
79
+ });
80
+ });
81
+ }
82
+ async function saveQueryToParquet(connection, fileName, query, folder) {
83
+ return new Promise((resolve, reject) => {
84
+ connection?.run(`COPY (${query}) TO '${fileName}' (FORMAT PARQUET, COMPRESSION ZSTD)`, async function (err) {
85
+ if (err) {
86
+ console.log('dump failed', err);
87
+ reject(err);
88
+ }
89
+ else {
90
+ try {
91
+ // await fs.unlink(fileName);
92
+ resolve();
93
+ }
94
+ catch (err) {
95
+ console.log('Error uploading Parquet file to Azure Blob Storage:', err);
96
+ return Promise.reject(err);
97
+ }
98
+ }
99
+ });
100
+ });
101
+ }
102
+ //# sourceMappingURL=db.helper.js.map
@@ -0,0 +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;AA9FM,KAAK,UAAU,kBAAkB,CAAC,UAAuB,EAAE,KAAc;IAC5E,OAAO,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACzC,UAAU,EAAE,GAAG,CAAC,KAAK,IAAI,EAAE,EAAE,CAAC,GAAG,EAAE,QAAQ,EAAE,EAAE;YAC3C,IAAI,GAAG,EAAE,CAAC;gBACN,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC;YACvB,CAAC;YACD,OAAO,OAAO,CAAC,QAAQ,CAAC,CAAC;QAC7B,CAAC,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;AACP,CAAC;AAEM,KAAK,UAAU,UAAU,CAAC,UAAuB,EAAE,KAAc;IAEpE,IAAI,CAAC;QACD,MAAM,kBAAkB,CAAC,UAAU,EAAE,KAAK,CAAC,CAAC;IAChD,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACX,OAAO,CAAC,KAAK,CAAC,uBAAuB,EAAE,GAAG,CAAC,CAAC;IAChD,CAAC;AACL,CAAC;AAEM,KAAK,UAAU,SAAS,CAAC,UAAuB,EAAE,SAAkB;IACvE,MAA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C,GAAY,CAAC,CAAC;gBACxC,CAAC;YACL,CAAC;QACL,CAAC,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;AACP,CAAC"}
@@ -0,0 +1,3 @@
1
+ export declare function modelToArray<T>(model: T, classType: new () => T): unknown[];
2
+ export declare function mapToSQLFieldsValues<T>(model: T, classType: new () => T): string;
3
+ export declare function parseJson(input: any): any;
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+ /* eslint-disable @typescript-eslint/no-explicit-any */
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.modelToArray = modelToArray;
5
+ exports.mapToSQLFieldsValues = mapToSQLFieldsValues;
6
+ exports.parseJson = parseJson;
7
+ function modelToArray(model, classType) {
8
+ const propertyNames = Object.getOwnPropertyNames(new classType());
9
+ const array = [];
10
+ for (const propertyName of propertyNames) {
11
+ array.push(model[propertyName]);
12
+ }
13
+ return array;
14
+ }
15
+ function mapToSQLFieldsValues(model, classType) {
16
+ const values = modelToArray(model, classType);
17
+ const query = values.map(item => {
18
+ let obj = null;
19
+ switch (typeof item) {
20
+ case 'number':
21
+ obj = item;
22
+ break;
23
+ case 'string':
24
+ // eslint-disable-next-line no-control-regex
25
+ obj = `'${item.replace(/'/g, '\'\'').replace(/\u0000/g, '')}'`;
26
+ break;
27
+ case 'boolean':
28
+ obj = item ? 1 : 0;
29
+ break;
30
+ case 'object':
31
+ if (!item) {
32
+ obj = 'null';
33
+ }
34
+ else if (Array.isArray(item)) {
35
+ obj = `'${JSON.stringify(item)}'`;
36
+ }
37
+ else if (item instanceof Date) {
38
+ obj = `'${item.toISOString()}'`; // Convert date to ISO 8601 string format
39
+ }
40
+ else {
41
+ obj = `'${JSON.stringify(item)}'`;
42
+ }
43
+ break;
44
+ default:
45
+ obj = 'null';
46
+ break;
47
+ }
48
+ return obj;
49
+ }).join(',');
50
+ return `(${query})`;
51
+ }
52
+ function parseJson(input) {
53
+ return input ? JSON.parse(input) : null;
54
+ }
55
+ //# sourceMappingURL=mapping.hel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EAAE,CAAC;oBAC7B,GAAG,GAAG,IAAI,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,GAAG,CAAC;gBACtC,CAAC;qBACI,IAAI,IAAI,YAAY,IAAI,EAAE,CAAC;oBAC5B,GAAG,GAAG,IAAI,IAAI,CAAC,WAAW,EAAE,GAAG,CAAC,CAAC,yCAAyC;gBAC9E,CAAC;qBACI,CAAC;oBACF,GAAG,GAAG,IAAI,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,GAAG,CAAC;gBACtC,CAAC;gBACD,MAAM;YACV;gBACI,GAAG,GAAG,MAAM,CAAC;gBACb,MAAM;QACd,CAAC;QACD,OAAO,GAAG,CAAC;IACf,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACb,OAAO,IAAI,KAAK,GAAG,CAAC;AACxB,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"}
@@ -0,0 +1,6 @@
1
+ import 'reflect-metadata';
2
+ export declare function getClassName<T>(classType: new () => T): string;
3
+ export declare function getTableName<T>(classType: new () => T): string;
4
+ export declare function getPrimaryId<T>(classType: new () => T): string;
5
+ export declare function generateCreateTableStatement<T>(tableName: string, classType: new () => T): string;
6
+ export declare function generateInsertIntoStatement<T>(tableName: string, classType: new () => T): string;
@@ -0,0 +1,72 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getClassName = getClassName;
4
+ exports.getTableName = getTableName;
5
+ exports.getPrimaryId = getPrimaryId;
6
+ exports.generateCreateTableStatement = generateCreateTableStatement;
7
+ exports.generateInsertIntoStatement = generateInsertIntoStatement;
8
+ require("reflect-metadata");
9
+ function getClassName(classType) {
10
+ return classType.name;
11
+ }
12
+ function getTableName(classType) {
13
+ return getClassName(classType);
14
+ }
15
+ function getPrimaryId(classType) {
16
+ // Get the property names from the class using reflection
17
+ const propertyNames = Object.getOwnPropertyNames(new classType());
18
+ let primaryKeys = 0;
19
+ let columnName = "";
20
+ for (const propertyName of propertyNames) {
21
+ const primaryKey = Reflect.getMetadata('PrimaryKey', classType.prototype, propertyName);
22
+ if (primaryKey) {
23
+ primaryKeys++;
24
+ columnName = propertyName;
25
+ }
26
+ }
27
+ return primaryKeys == 1 ? columnName : "";
28
+ }
29
+ function generateCreateTableStatement(tableName, classType) {
30
+ let createTableStatement = `CREATE TABLE IF NOT EXISTS main.${tableName} (`;
31
+ // Get the property names from the class using reflection
32
+ const propertyNames = Object.getOwnPropertyNames(new classType());
33
+ let primaryKeys = 0;
34
+ for (let i = 0; i < propertyNames.length; i++) {
35
+ const propertyName = propertyNames[i];
36
+ // Retrieve the type of the property using reflection and the FieldType decorator
37
+ const propertyType = Reflect.getMetadata('FieldType', classType.prototype, propertyName);
38
+ const primaryKey = Reflect.getMetadata('PrimaryKey', classType.prototype, propertyName);
39
+ const unique = Reflect.getMetadata('Unique', classType.prototype, propertyName);
40
+ // Append the column definition to the statement
41
+ createTableStatement += `${propertyName} ${propertyType ?? 'VARCHAR'}`;
42
+ if (primaryKey) {
43
+ createTableStatement += ' PRIMARY KEY';
44
+ primaryKeys++;
45
+ }
46
+ if (unique)
47
+ createTableStatement += ' UNIQUE';
48
+ // Add a comma if it's not the last property
49
+ if (i < propertyNames.length - 1) {
50
+ createTableStatement += ', ';
51
+ }
52
+ }
53
+ // Close the CREATE TABLE statement
54
+ createTableStatement += ');';
55
+ if (primaryKeys > 1)
56
+ throw new Error('Multiple primary keys are not supported!');
57
+ return createTableStatement;
58
+ }
59
+ function generateInsertIntoStatement(tableName, classType) {
60
+ let insertIntoTableStatement = `INSERT INTO main.${tableName} (`;
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;
71
+ }
72
+ //# sourceMappingURL=table-util.helper.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"table-util.helper.js","sourceRoot":"","sources":["../../src/helpers/table-util.helper.ts"],"names":[],"mappings":";;AAEA,oCAEC;AAED,oCAEC;AAED,oCAiBC;AAID,oEAsCC;AAED,kEAkBC;AAzFD,4BAA0B;AAE1B,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;IACjD,yDAAyD;IACzD,MAAM,aAAa,GAAG,MAAM,CAAC,mBAAmB,CAAC,IAAI,SAAS,EAAE,CAAC,CAAC;IAClE,IAAI,WAAW,GAAG,CAAC,CAAC;IACpB,IAAI,UAAU,GAAG,EAAE,CAAC;IAEpB,KAAK,MAAM,YAAY,IAAI,aAAa,EAAE,CAAC;QAEvC,MAAM,UAAU,GAAG,OAAO,CAAC,WAAW,CAAC,YAAY,EAAE,SAAS,CAAC,SAAS,EAAE,YAAY,CAAC,CAAC;QAExF,IAAI,UAAU,EAAE,CAAC;YACb,WAAW,EAAE,CAAC;YACd,UAAU,GAAG,YAAY,CAAC;QAC9B,CAAC;IACL,CAAC;IAED,OAAO,WAAW,IAAE,CAAC,CAAC,CAAC,CAAC,UAAU,CAAA,CAAC,CAAC,EAAE,CAAC;AAC3C,CAAC;AAID,SAAgB,4BAA4B,CAAI,SAAiB,EAAE,SAAqB;IACpF,IAAI,oBAAoB,GAAG,mCAAmC,SAAS,IAAI,CAAC;IAE5E,yDAAyD;IACzD,MAAM,aAAa,GAAG,MAAM,CAAC,mBAAmB,CAAC,IAAI,SAAS,EAAE,CA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EAAE,CAAC,CAAC;IAElE,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,aAAa,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QAC5C,MAAM,YAAY,GAAG,aAAa,CAAC,CAAC,CAAC,CAAC;QAEtC,wBAAwB,IAAI,GAAG,YAAY,EAAE,CAAC;QAE9C,IAAI,CAAC,GAAG,aAAa,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAC/B,wBAAwB,IAAI,IAAI,CAAC;QACrC,CAAC;IACL,CAAC;IAED,wBAAwB,IAAI,WAAW,CAAC;IAExC,OAAO,wBAAwB,CAAC;AACpC,CAAC"}
@@ -0,0 +1,6 @@
1
+ import 'reflect-metadata';
2
+ import { DataTypeDecorator, Entity, Id, Repository, Unique } from "./constants/data-type.decorator";
3
+ import { BaseRepository } from "./repositories/base.repository";
4
+ import { DuckDbRepository } from "./repositories/duckdb.repository";
5
+ import { IRepository } from './repositories/base.interface';
6
+ export { DataTypeDecorator, Id, Unique, BaseRepository, Entity, Repository, DuckDbRepository, IRepository };
package/dist/index.js ADDED
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DuckDbRepository = exports.Repository = exports.Entity = exports.BaseRepository = exports.Unique = exports.Id = exports.DataTypeDecorator = void 0;
4
+ require("reflect-metadata");
5
+ const data_type_decorator_1 = require("./constants/data-type.decorator");
6
+ Object.defineProperty(exports, "DataTypeDecorator", { enumerable: true, get: function () { return data_type_decorator_1.DataTypeDecorator; } });
7
+ Object.defineProperty(exports, "Entity", { enumerable: true, get: function () { return data_type_decorator_1.Entity; } });
8
+ Object.defineProperty(exports, "Id", { enumerable: true, get: function () { return data_type_decorator_1.Id; } });
9
+ Object.defineProperty(exports, "Repository", { enumerable: true, get: function () { return data_type_decorator_1.Repository; } });
10
+ Object.defineProperty(exports, "Unique", { enumerable: true, get: function () { return data_type_decorator_1.Unique; } });
11
+ const base_repository_1 = require("./repositories/base.repository");
12
+ Object.defineProperty(exports, "BaseRepository", { enumerable: true, get: function () { return base_repository_1.BaseRepository; } });
13
+ const duckdb_repository_1 = require("./repositories/duckdb.repository");
14
+ Object.defineProperty(exports, "DuckDbRepository", { enumerable: true, get: function () { return duckdb_repository_1.DuckDbRepository; } });
15
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,4BAA0B;AAC1B,yEAAoG;AAQhG,kGARK,uCAAiB,OAQL;AAIjB,uFAZwB,4BAAM,OAYxB;AAHN,mFATgC,wBAAE,OAShC;AAIF,2FAboC,gCAAU,OAapC;AAHV,uFAVgD,4BAAM,OAUhD;AATV,oEAAgE;AAU5D,+FAVK,gCAAc,OAUL;AATlB,wEAAoE;AAYhE,iGAZK,oCAAgB,OAYL"}
@@ -0,0 +1,6 @@
1
+ export interface IRepository<T, Tid> {
2
+ save(entity: T): Promise<T>;
3
+ findAll(): Promise<T[]>;
4
+ findById(id: Tid): Promise<T>;
5
+ findBy(entity: T, columns: string[]): Promise<T[]>;
6
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=base.interface.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"base.interface.js","sourceRoot":"","sources":["../../src/repositories/base.interface.ts"],"names":[],"mappings":""}
@@ -0,0 +1,13 @@
1
+ import 'reflect-metadata';
2
+ import { DuckDbRepository } from './duckdb.repository';
3
+ import { IRepository } from './base.interface';
4
+ export declare class BaseRepository<T, Tid> implements IRepository<T, Tid> {
5
+ protected repository: DuckDbRepository;
6
+ protected classType: new () => T;
7
+ private primaryColumnId;
8
+ constructor(repository: DuckDbRepository);
9
+ save(entity: T): Promise<T>;
10
+ findAll(): Promise<T[]>;
11
+ findById(id: Tid): Promise<T>;
12
+ findBy(entity: T, columns: string[]): Promise<T[]>;
13
+ }
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BaseRepository = void 0;
4
+ require("reflect-metadata");
5
+ const table_util_helper_1 = require("../helpers/table-util.helper");
6
+ class BaseRepository {
7
+ repository;
8
+ classType;
9
+ primaryColumnId = '';
10
+ constructor(repository) {
11
+ this.repository = repository;
12
+ // Retrieve the class type from the subclass's constructor using reflection
13
+ this.classType = Reflect.getMetadata('entityType', this.constructor);
14
+ if (!this.classType) {
15
+ throw new Error('Class type is not defined!');
16
+ }
17
+ }
18
+ async save(entity) {
19
+ console.log('Saving entity:', entity);
20
+ console.log('Class type:', this.classType.name);
21
+ // Create the table if it doesn't exist
22
+ await this.repository.createTableIfNotExists(this.classType.name, this.classType);
23
+ // Save the entity to DuckDB
24
+ await this.repository.saveToDuckDB(this.classType.name, this.classType, [entity]);
25
+ return entity;
26
+ }
27
+ async findAll() {
28
+ const query = `SELECT * FROM main.${this.classType.name}`;
29
+ const result = await this.repository.executeQuery(query);
30
+ return result;
31
+ }
32
+ async findById(id) {
33
+ // Get the property names from the class using reflection
34
+ if (!this.primaryColumnId)
35
+ this.primaryColumnId = (0, table_util_helper_1.getPrimaryId)(this.classType);
36
+ const query = `SELECT * FROM main.${this.classType.name} WHERE ${this.primaryColumnId}='${id}'`;
37
+ const result = await this.repository.executeQuery(query);
38
+ return result?.length ? result[0] : undefined;
39
+ }
40
+ async findBy(entity, columns) {
41
+ let query = `SELECT * FROM main.${this.classType.name} WHERE `;
42
+ for (const column of columns) {
43
+ query += `${column}='${entity[column]}' AND `;
44
+ }
45
+ query = query.slice(0, query.length - 5);
46
+ const result = await this.repository.executeQuery(query);
47
+ return result;
48
+ }
49
+ }
50
+ exports.BaseRepository = BaseRepository;
51
+ //# sourceMappingURL=base.repository.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"base.repository.js","sourceRoot":"","sources":["../../src/repositories/base.repository.ts"],"names":[],"mappings":";;;AAAA,4BAA0B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AAC,IAAI,CAAC,SAAS,CAAC,CAAC;QACxD,MAAM,KAAK,GAAG,sBAAsB,IAAI,CAAC,SAAS,CAAC,IAAI,UAAU,IAAI,CAAC,eAAe,KAAK,EAAE,GAAG,CAAC;QAChG,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,YAAY,CAAC,KAAK,CAAC,CAAA;QACxD,OAAO,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IAClD,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,MAAS,EAAE,OAAiB;QACrC,IAAI,KAAK,GAAG,sBAAsB,IAAI,CAAC,SAAS,CAAC,IAAI,SAAS,CAAC;QAC/D,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE,CAAC;YAC3B,KAAK,IAAI,GAAG,MAAM,KAAM,MAAc,CAAC,MAAM,CAAC,QAAQ,CAAC;QAC3D,CAAC;QACD,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;QACzC,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC;QACzD,OAAO,MAAM,CAAC;IAClB,CAAC;CACJ;AAlDD,wCAkDC"}
@@ -0,0 +1,21 @@
1
+ export declare class DuckDbRepository {
2
+ private db?;
3
+ private connection?;
4
+ private tables;
5
+ private isClosed;
6
+ private static instance;
7
+ static getInstances(): DuckDbRepository;
8
+ protected constructor();
9
+ connect(): void;
10
+ createTableIfNotExists<T>(tableName: string, classType: new () => T): Promise<void>;
11
+ getDuckDbExtension(extension_name: string): Promise<any[]>;
12
+ executeQuery(query: string): Promise<any[]>;
13
+ pushToDuckDb<T>(tableName: string, classType: new () => T, data?: T[]): Promise<void>;
14
+ saveToDuckDB<T>(tableName: string, classType: new () => T, data?: T[]): Promise<void>;
15
+ saveToParquet(name: string, mainFolder?: string): Promise<void>;
16
+ saveToParquetByName(parquetFileName: string, duckDBTableName: string, mainFolder?: string): Promise<void>;
17
+ dropTablesFromMemory(): Promise<void>;
18
+ dropTable(tableName: string): Promise<void>;
19
+ deleteTableData(tableName: string): Promise<any[]>;
20
+ saveQueryToParquet(name: string, query: string, folder: string): Promise<void>;
21
+ }
@@ -0,0 +1,106 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DuckDbRepository = void 0;
4
+ /* eslint-disable @typescript-eslint/no-explicit-any */
5
+ const duckdb_1 = require("duckdb");
6
+ const mapping_helper_1 = require("../helpers/mapping.helper");
7
+ const table_util_helper_1 = require("../helpers/table-util.helper");
8
+ const db_helper_1 = require("../helpers/db.helper");
9
+ class DuckDbRepository {
10
+ db = undefined;
11
+ connection = undefined;
12
+ // private statement: Statement;
13
+ // private toDropTable: boolean = true;
14
+ tables = new Map();
15
+ isClosed = true;
16
+ // private readonly tableName: string;
17
+ // private readonly fileName: string;
18
+ static instance;
19
+ static getInstances() {
20
+ if (!this.instance) {
21
+ this.instance = new DuckDbRepository();
22
+ }
23
+ return this.instance;
24
+ }
25
+ constructor() {
26
+ if (!this.db) {
27
+ this.db = new duckdb_1.Database(':memory:');
28
+ this.connect();
29
+ }
30
+ }
31
+ connect() {
32
+ if (this.isClosed) {
33
+ this.connection = this.db?.connect();
34
+ this.isClosed = false;
35
+ }
36
+ }
37
+ async createTableIfNotExists(tableName, classType) {
38
+ return new Promise((resolve, reject) => {
39
+ this.connection?.run((0, table_util_helper_1.generateCreateTableStatement)(tableName, classType), err => {
40
+ if (err) {
41
+ console.log('ERROR CREATING: ', err);
42
+ reject(err);
43
+ }
44
+ else {
45
+ // console.info('DuckDB table main.' + tableName + ' was created or already exists!');
46
+ resolve();
47
+ }
48
+ });
49
+ });
50
+ }
51
+ async getDuckDbExtension(extension_name) {
52
+ return this.executeQuery(`select extension_name, loaded, installed from duckdb_extensions() where extension_name='${extension_name}';`);
53
+ }
54
+ async executeQuery(query) {
55
+ return await (0, db_helper_1.executeQuery)(this.connection, query);
56
+ }
57
+ async pushToDuckDb(tableName, classType, data) {
58
+ if (!this.tables.get(tableName)) {
59
+ this.tables.set(tableName, false);
60
+ }
61
+ await this.saveToDuckDB(tableName, classType, data);
62
+ }
63
+ async saveToDuckDB(tableName, classType, data) {
64
+ if (!(data?.length))
65
+ return;
66
+ await this.createTableIfNotExists(tableName, classType);
67
+ const query = data.map(item => (0, mapping_helper_1.mapToSQLFieldsValues)(item, classType)).join(', ');
68
+ await (0, db_helper_1.bulkInsert)(this.connection, (0, table_util_helper_1.generateInsertIntoStatement)(tableName, classType) + query);
69
+ }
70
+ async saveToParquet(name, mainFolder) {
71
+ const fileName = `${name}.parquet`;
72
+ const tableName = `main.${name}`;
73
+ await (0, db_helper_1.saveToParquet)(this.connection, fileName, tableName, mainFolder);
74
+ this.tables.set(name, true);
75
+ }
76
+ async saveToParquetByName(parquetFileName, duckDBTableName, mainFolder) {
77
+ const fileName = `${parquetFileName}.parquet`;
78
+ await (0, db_helper_1.saveToParquet)(this.connection, fileName, `main.${duckDBTableName}`, mainFolder);
79
+ this.tables.set(parquetFileName, true);
80
+ }
81
+ async dropTablesFromMemory() {
82
+ const promiseDropTables = [];
83
+ this.tables.forEach((value, key) => {
84
+ if (value)
85
+ promiseDropTables.push(this.dropTable(key).then(() => {
86
+ console.log(`Dropped table main.${key} from DuckDb!`);
87
+ }));
88
+ });
89
+ await Promise.all(promiseDropTables);
90
+ }
91
+ async dropTable(tableName) {
92
+ await (0, db_helper_1.dropTable)(this.connection, 'main.' + tableName);
93
+ if (this.tables.get(tableName)) {
94
+ this.tables.delete(tableName);
95
+ }
96
+ }
97
+ async deleteTableData(tableName) {
98
+ return await (0, db_helper_1.deleteTableData)(this.connection, tableName);
99
+ }
100
+ async saveQueryToParquet(name, query, folder) {
101
+ const fileName = `${name}.parquet`;
102
+ await (0, db_helper_1.saveQueryToParquet)(this.connection, fileName, query, folder);
103
+ }
104
+ }
105
+ exports.DuckDbRepository = DuckDbRepository;
106
+ //# sourceMappingURL=duckdb.repository.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"duckdb.repository.js","sourceRoot":"","sources":["../../src/repositories/duckdb.repository.ts"],"names":[],"mappings":";;;AAAA,uDAAuD;AACvD,mCAA8C;AAE9C,8DAAiE;AACjE,oEAAyG;AACzG,oDAA+H;AAG/H,MAAa,gBAAgB;IACjB,EAAE,GAAc,SAAS,CAAC;IAC1B,UAAU,GAAgB,SAAS,CAAC;IAC5C,gCAAgC;IAChC,uCAAuC;IAG/B,MAAM,GAAyB,IAAI,GAAG,EAAE,CAAC;IACzC,QAAQ,GAAG,IAAI,CAAC;IAExB,sCAAsC;IACtC,qCAAqC;IAC7B,MAAM,CAAC,QAAQ,CAAmB;IAGnC,MAAM,CAAC,YAAY;QACtB,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC;YACjB,IAAI,CAAC,QAAQ,GAAG,IAAI,gBAAgB,EAAE,CAAC;QAE3C,CAAC;QACD,OAAO,IAAI,CAAC,QAAQ,CAAC;IACzB,CAAC;IAED;QACI,IAAI,CAAC,IAAI,CAAC,EAAE,EAAE,CAAC;YACX,IAAI,CAAC,EAAE,GAAG,IAAI,iBAAQ,CAAC,UAAU,CAAC,CAAC;YACnC,IAAI,CAAC,OAAO,EAAE,CAAC;QACnB,CAAC;IACL,CAAC;IAEM,OAAO;QACV,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;YAChB,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,EAAE,EAAE,OAAO,EAAE,CAAC;YACrC,IAAI,CAAC,QAAQ,GAAG,KAAK,CAAC;QAC1B,CAAC;IACL,CAAC;IAEM,KAAK,CAAC,sBAAsB,CAAI,SAAiB,EAAE,SAAqB;QAE3E,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YACnC,IAAI,CAAC,UAAU,EAAE,GAAG,CAAC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AiB,CAAC,CAAC;IACzC,CAAC;IAEM,KAAK,CAAC,SAAS,CAAC,SAAiB;QACpC,MAAM,IAAA,qBAAS,EAAC,IAAI,CAAC,UAAU,EAAE,OAAO,GAAG,SAAS,CAAC,CAAC;QACtD,IAAI,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,SAAS,CAAC,EAAE,CAAC;YAC7B,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;QAClC,CAAC;IACL,CAAC;IAEM,KAAK,CAAC,eAAe,CAAC,SAAiB;QAC1C,OAAO,MAAM,IAAA,2BAAe,EAAC,IAAI,CAAC,UAAU,EAAE,SAAS,CAAC,CAAC;IAC7D,CAAC;IAEM,KAAK,CAAC,kBAAkB,CAAC,IAAY,EAAE,KAAa,EAAE,MAAc;QACvE,MAAM,QAAQ,GAAG,GAAG,IAAI,UAAU,CAAC;QACnC,MAAM,IAAA,8BAAkB,EAAC,IAAI,CAAC,UAAU,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC;IACvE,CAAC;CAEJ;AArHD,4CAqHC"}
package/dist/test.d.ts ADDED
@@ -0,0 +1 @@
1
+ export {};
package/dist/test.js ADDED
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ // @Entity
3
+ // export class Amenity {
4
+ Object.defineProperty(exports, "__esModule", { value: true });
5
+ // @DataTypeDecorator('VARCHAR(255)')
6
+ // Name?: string = null;
7
+ // @Id()
8
+ // @DataTypeDecorator('VARCHAR(255)')
9
+ // Type?: string = null;
10
+ // @DataTypeDecorator('VARCHAR(255)')
11
+ // PropertyId?: string = null;
12
+ // }
13
+ // // @Entity // Use the Entity decorator to register metadata
14
+ // @Repository(Amenity)
15
+ // class AmenityRepository extends BaseRepository<Amenity, string> {
16
+ // constructor() {
17
+ // super(DuckDbRepository.getInstances());
18
+ // }
19
+ // }
20
+ // async function test() {
21
+ // const amenityRepository = new AmenityRepository();
22
+ // const amenity = new Amenity();
23
+ // amenity.Name = "Naim";
24
+ // amenity.PropertyId = "1";
25
+ // amenity.Type = "Type1";
26
+ // const amenity1= new Amenity();
27
+ // amenity1.Name = "Naim";
28
+ // amenity1.PropertyId = "2";
29
+ // amenity1.Type = "Type2";
30
+ // // Save the entity dynamically using metadata
31
+ // await amenityRepository.save(amenity);
32
+ // await amenityRepository.save(amenity1);
33
+ // const result = await amenityRepository.findAll();
34
+ // console.table(result);
35
+ // const amenityFound:Amenity = await amenityRepository.findById("Type1");
36
+ // console.info(amenityFound);
37
+ // const amenityFound1: Amenity = await amenityRepository.findById("Type1");
38
+ // console.info(amenityFound1);
39
+ // const amenities = await amenityRepository.findBy(amenity, ["Type", "Name"]);
40
+ // console.table(amenities);
41
+ // }
42
+ // test();
43
+ //# sourceMappingURL=test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"test.js","sourceRoot":"","sources":["../src/test.ts"],"names":[],"mappings":";AACA,UAAU;AACV,yBAAyB;;AAEzB,yCAAyC;AACzC,4BAA4B;AAE5B,YAAY;AACZ,yCAAyC;AACzC,4BAA4B;AAE5B,yCAAyC;AACzC,kCAAkC;AAClC,IAAI;AAKJ,+DAA+D;AAC/D,uBAAuB;AACvB,oEAAoE;AACpE,sBAAsB;AACtB,kDAAkD;AAClD,QAAQ;AACR,IAAI;AAMJ,0BAA0B;AAC1B,yDAAyD;AAEzD,qCAAqC;AACrC,6BAA6B;AAC7B,gCAAgC;AAChC,8BAA8B;AAE9B,qCAAqC;AACrC,8BAA8B;AAC9B,iCAAiC;AACjC,+BAA+B;AAI/B,oDAAoD;AACpD,6CAA6C;AAC7C,8CAA8C;AAC9C,wDAAwD;AACxD,6BAA6B;AAC7B,8EAA8E;AAC9E,kCAAkC;AAClC,gFAAgF;AAChF,mCAAmC;AAEnC,mFAAmF;AACnF,gCAAgC;AAChC,IAAI;AAEJ,UAAU"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "duckdb-tinyorm",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "description": "TinyORM for Duckdb, easy setup",
5
5
  "main": "node dist/index.js",
6
6
  "scripts": {
@@ -27,8 +27,10 @@
27
27
  "@types/node": "^22.7.4",
28
28
  "dotenv": "^16.4.5",
29
29
  "duckdb": "^1.1.0",
30
+ "duckdb-tinyorm": "^1.0.0",
30
31
  "globals": "^15.9.0",
31
32
  "nodemon": "^3.1.7",
33
+ "npm": "^10.8.3",
32
34
  "reflect-metadata": "^0.2.2",
33
35
  "rimraf": "^6.0.1",
34
36
  "ts-node": "^10.9.2",
package/tsconfig.json CHANGED
@@ -4,12 +4,12 @@
4
4
  "ES2023"
5
5
  ],
6
6
  "module": "NodeNext",
7
- "target": "ES2022",
7
+ "target": "ESNext",
8
8
  "moduleResolution": "NodeNext",
9
9
  "moduleDetection": "force",
10
10
  "outDir": "./dist",
11
11
  "rootDir": "./src",
12
- "strict": false,
12
+ "strict": true, // Enabled for better type safety
13
13
  "esModuleInterop": true,
14
14
  "allowJs": true,
15
15
  "declaration": true,
@@ -19,6 +19,6 @@
19
19
  "forceConsistentCasingInFileNames": true,
20
20
  "skipDefaultLibCheck": true,
21
21
  "sourceMap": true,
22
- "emitDecoratorMetadata": true,
22
+ "emitDecoratorMetadata": true
23
23
  }
24
24
  }