@hemia/db-connector 0.0.8 → 0.0.9
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 +94 -2
- package/dist/hemia-db-connector.esm.js +5955 -451
- package/dist/hemia-db-connector.js +5982 -408
- package/dist/types/Core/DrizzleConnector.d.ts +28 -0
- package/dist/types/DBConnector.d.ts +4 -2
- package/dist/types/abstract/DrizzleSQLConnector.d.ts +44 -0
- package/dist/types/index.d.ts +5 -0
- package/dist/types/managers/DrizzleConnectionManager.d.ts +6 -0
- package/dist/types/types/CredentialsConnection.d.ts +1 -1
- package/dist/types/types/DrizzleSQLType.d.ts +3 -0
- package/package.json +8 -3
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { PostgresJsDatabase } from 'drizzle-orm/postgres-js';
|
|
2
|
+
import { PgTable } from 'drizzle-orm/pg-core';
|
|
3
|
+
import { DrizzleSqlConnector, DrizzleSelectOptions, DrizzleInsertOptions, DrizzleUpdateOptions, DrizzleDeleteOptions, DrizzleQueryOptions, DrizzleTransaction } from '../abstract/DrizzleSQLConnector';
|
|
4
|
+
import { CredentialsConnection } from '../types/CredentialsConnection';
|
|
5
|
+
export declare class DrizzlePostgresConnector extends DrizzleSqlConnector {
|
|
6
|
+
private readonly creds;
|
|
7
|
+
private db;
|
|
8
|
+
private connection;
|
|
9
|
+
private schemas;
|
|
10
|
+
constructor(creds: CredentialsConnection);
|
|
11
|
+
connect(): Promise<void>;
|
|
12
|
+
disconnect(): Promise<void>;
|
|
13
|
+
isConnected(): Promise<boolean>;
|
|
14
|
+
getDb(): PostgresJsDatabase<Record<string, any>>;
|
|
15
|
+
registerTableSchema(tableName: string, schema: PgTable<any>): void;
|
|
16
|
+
private getTableSchema;
|
|
17
|
+
select<T = any>(entity: string, options?: DrizzleSelectOptions): Promise<T[]>;
|
|
18
|
+
insert<T = any>(entity: string, values: Record<string, any>, options?: DrizzleInsertOptions): Promise<T | void>;
|
|
19
|
+
update(entity: string, filter: Record<string, any>, data: Record<string, any>, options?: DrizzleUpdateOptions): Promise<number>;
|
|
20
|
+
delete(entity: string, filter: Record<string, any>, options?: DrizzleDeleteOptions): Promise<number>;
|
|
21
|
+
query<T = any>(sql: string, options?: DrizzleQueryOptions): Promise<T[]>;
|
|
22
|
+
withTransaction<T>(fn: (tx: DrizzleTransaction) => Promise<T>): Promise<T>;
|
|
23
|
+
private buildDrizzleWhere;
|
|
24
|
+
private buildRawWhereClause;
|
|
25
|
+
private executeRawQuery;
|
|
26
|
+
private ensureConnected;
|
|
27
|
+
private createDatabaseError;
|
|
28
|
+
}
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
+
import { DrizzleSqlConnector } from "./abstract/DrizzleSQLConnector";
|
|
1
2
|
import { NoSQLConnector } from "./abstract/NoSQLConnector";
|
|
2
3
|
import { OLAPConnector } from "./abstract/OLAPConnector";
|
|
3
4
|
import { SqlConnector } from "./abstract/SQLConnector";
|
|
4
5
|
import { CredentialsConnection } from "./types/CredentialsConnection";
|
|
5
6
|
import { DBNoSQLType } from "./types/DBNoSQLTypes";
|
|
6
7
|
import { DBSQLType } from "./types/DBSQLTypes";
|
|
8
|
+
import { DrizzleSQLType } from "./types/DrizzleSQLType";
|
|
7
9
|
import { DBOLAPType } from "./types/OLAPTypes";
|
|
8
10
|
export declare class DBConnector {
|
|
9
11
|
private static instance;
|
|
@@ -13,8 +15,8 @@ export declare class DBConnector {
|
|
|
13
15
|
private dbType;
|
|
14
16
|
constructor();
|
|
15
17
|
static getInstance(): DBConnector;
|
|
16
|
-
createConnection<T extends SqlConnector | NoSQLConnector | OLAPConnector>(type: DBSQLType | DBNoSQLType | DBOLAPType, credentials: CredentialsConnection): Promise<T>;
|
|
18
|
+
createConnection<T extends SqlConnector | NoSQLConnector | OLAPConnector | DrizzleSqlConnector>(type: DBSQLType | DBNoSQLType | DBOLAPType | DrizzleSQLType, credentials: CredentialsConnection): Promise<T>;
|
|
17
19
|
getConnection<T extends NoSQLConnector | SqlConnector | OLAPConnector>(): T | null;
|
|
18
20
|
closeConnection(): Promise<void>;
|
|
19
|
-
getEngine<T extends NoSQLConnector | SqlConnector | OLAPConnector>(type: DBNoSQLType | DBSQLType | DBOLAPType, credentials: CredentialsConnection): T;
|
|
21
|
+
getEngine<T extends NoSQLConnector | SqlConnector | OLAPConnector | DrizzleSqlConnector>(type: DBNoSQLType | DBSQLType | DBOLAPType | DrizzleSQLType, credentials: CredentialsConnection): T;
|
|
20
22
|
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
export interface DrizzleSelectOptions {
|
|
2
|
+
where?: Record<string, any>;
|
|
3
|
+
limit?: number;
|
|
4
|
+
offset?: number;
|
|
5
|
+
orderBy?: Array<{
|
|
6
|
+
column: string;
|
|
7
|
+
direction?: 'asc' | 'desc';
|
|
8
|
+
}>;
|
|
9
|
+
}
|
|
10
|
+
export interface DrizzleInsertOptions {
|
|
11
|
+
returning?: boolean;
|
|
12
|
+
ignoreDuplicates?: boolean;
|
|
13
|
+
onConflict?: {
|
|
14
|
+
target: string | string[];
|
|
15
|
+
action: 'nothing' | 'update';
|
|
16
|
+
set?: Record<string, any>;
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
export interface DrizzleUpdateOptions {
|
|
20
|
+
returning?: boolean;
|
|
21
|
+
}
|
|
22
|
+
export interface DrizzleDeleteOptions {
|
|
23
|
+
limit?: number;
|
|
24
|
+
returning?: boolean;
|
|
25
|
+
}
|
|
26
|
+
export interface DrizzleQueryOptions {
|
|
27
|
+
bind?: Record<string, any>;
|
|
28
|
+
replacements?: any[];
|
|
29
|
+
}
|
|
30
|
+
export interface DrizzleTransaction {
|
|
31
|
+
commit(): Promise<void>;
|
|
32
|
+
rollback(): Promise<void>;
|
|
33
|
+
}
|
|
34
|
+
export declare abstract class DrizzleSqlConnector {
|
|
35
|
+
abstract connect(): Promise<void>;
|
|
36
|
+
abstract disconnect(): Promise<void>;
|
|
37
|
+
abstract isConnected(): Promise<boolean>;
|
|
38
|
+
abstract select<T = any>(entity: string, options?: DrizzleSelectOptions): Promise<T[]>;
|
|
39
|
+
abstract insert<T = any>(entity: string, values: Record<string, any>, options?: DrizzleInsertOptions): Promise<T | void>;
|
|
40
|
+
abstract update(entity: string, filter: Record<string, any>, data: Record<string, any>, options?: DrizzleUpdateOptions): Promise<number>;
|
|
41
|
+
abstract delete(entity: string, filter: Record<string, any>, options?: DrizzleDeleteOptions): Promise<number>;
|
|
42
|
+
abstract query<T = any>(sql: string, options?: DrizzleQueryOptions): Promise<T[]>;
|
|
43
|
+
abstract withTransaction<T>(fn: (tx: DrizzleTransaction) => Promise<T>): Promise<T>;
|
|
44
|
+
}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -8,9 +8,14 @@ export { DBOLAPType } from "./types/OLAPTypes";
|
|
|
8
8
|
export { NoSQLConnector } from "./abstract/NoSQLConnector";
|
|
9
9
|
export { SqlConnector, Filter } from "./abstract/SQLConnector";
|
|
10
10
|
export { NoSQLOptions } from "./types/NoSQLOptions";
|
|
11
|
+
export { DrizzleSqlConnector, DrizzleSelectOptions, DrizzleInsertOptions, DrizzleUpdateOptions, DrizzleDeleteOptions, DrizzleQueryOptions, DrizzleTransaction } from "./abstract/DrizzleSQLConnector";
|
|
11
12
|
export * from 'mongoose';
|
|
12
13
|
export { Model as ModelSequelize, Sequelize, DataTypes, CreateOptions, UpdateOptions, DestroyOptions, FindOptions, Attributes, WhereOptions, QueryOptions, InferAttributes, CreationAttributes, InferCreationAttributes, QueryTypes, QueryOptionsWithType, Transaction, Op, fn } from "sequelize";
|
|
13
14
|
export { DBError } from "./errors/DBError";
|
|
14
15
|
export { MySQLConnectionError } from "./errors/MySQLConnectionError";
|
|
15
16
|
export { OLAPConnector, InsertOptions, ClickHouseInsertFormat, ClickHouseInsertValues } from './abstract/OLAPConnector';
|
|
16
17
|
export { ClickHouseConnector } from './Core/ClickHouseConnector';
|
|
18
|
+
export { DrizzlePostgresConnector } from './Core/DrizzleConnector';
|
|
19
|
+
export { PostgresJsDatabase } from 'drizzle-orm/postgres-js';
|
|
20
|
+
export { sql, eq, and, or, gt, gte, lt, lte, ne, like, ilike, inArray, isNull, not } from 'drizzle-orm';
|
|
21
|
+
export { pgTable, serial, integer, text, varchar, timestamp, boolean, json, jsonb, pgEnum } from 'drizzle-orm/pg-core';
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { DrizzleSqlConnector } from "../abstract/DrizzleSQLConnector";
|
|
2
|
+
import { CredentialsConnection } from "../types/CredentialsConnection";
|
|
3
|
+
import { DrizzleSQLType } from "../types/DrizzleSQLType";
|
|
4
|
+
export declare class DrizzleConnectionManager {
|
|
5
|
+
static getInstance(type: DrizzleSQLType, credentials: CredentialsConnection): DrizzleSqlConnector;
|
|
6
|
+
}
|
|
@@ -7,7 +7,7 @@ export interface CredentialsConnection {
|
|
|
7
7
|
timeOut?: number;
|
|
8
8
|
options?: object;
|
|
9
9
|
instance?: string;
|
|
10
|
-
dialect?: 'mysql' | 'postgres' | 'sqlite' | 'mariadb' | 'mssql';
|
|
10
|
+
dialect?: 'mysql' | 'postgres' | 'postgresql' | 'sqlite' | 'mariadb' | 'mssql';
|
|
11
11
|
logging?: boolean;
|
|
12
12
|
authSource?: string;
|
|
13
13
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hemia/db-connector",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.9",
|
|
4
4
|
"description": "Hemia Database Conector",
|
|
5
5
|
"main": "dist/hemia-db-connector.js",
|
|
6
6
|
"module": "dist/hemia-db-connector.esm.js",
|
|
@@ -41,8 +41,11 @@
|
|
|
41
41
|
"license": "MIT",
|
|
42
42
|
"dependencies": {
|
|
43
43
|
"@clickhouse/client": "^1.14.0",
|
|
44
|
+
"drizzle-orm": "^0.45.1",
|
|
44
45
|
"eslint": "^9.21.0",
|
|
45
|
-
"mongoose": "^8.8.2"
|
|
46
|
+
"mongoose": "^8.8.2",
|
|
47
|
+
"pg": "^8.16.3",
|
|
48
|
+
"postgres": "^3.4.7"
|
|
46
49
|
},
|
|
47
50
|
"devDependencies": {
|
|
48
51
|
"@rollup/plugin-commonjs": "^26.0.1",
|
|
@@ -53,8 +56,10 @@
|
|
|
53
56
|
"@types/mocha": "^10.0.7",
|
|
54
57
|
"@types/mssql": "^9.1.5",
|
|
55
58
|
"@types/node": "^22.3.0",
|
|
59
|
+
"@types/pg": "^8.16.0",
|
|
56
60
|
"@typescript-eslint/eslint-plugin": "^8.5.0",
|
|
57
61
|
"chai": "^4.2.0",
|
|
62
|
+
"drizzle-kit": "^0.31.8",
|
|
58
63
|
"events": "^3.3.0",
|
|
59
64
|
"jest": "^29.7.0",
|
|
60
65
|
"mocha": "^10.7.3",
|
|
@@ -74,4 +79,4 @@
|
|
|
74
79
|
"files": [
|
|
75
80
|
"dist"
|
|
76
81
|
]
|
|
77
|
-
}
|
|
82
|
+
}
|