@medyll/idae-db 0.0.1 → 0.2.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/dist/idaDb.js DELETED
@@ -1,59 +0,0 @@
1
- // packages\idae-db\lib\idaDb.ts
2
- import { DbType } from "./types.js";
3
- import { IdaeDbConnection } from "./IdaeDbConnection";
4
- import { MongoDBAdapter } from "./adapters/MongoDBAdapter";
5
- import { MySQLAdapter } from "./adapters/MysqlAdapter";
6
- export class IdaeDb {
7
- static instances = new Map();
8
- connections = new Map();
9
- dbType;
10
- constructor(dbType) {
11
- this.dbType = dbType;
12
- }
13
- static getOrCreateInstance(dbType) {
14
- if (!IdaeDb.instances.has(dbType)) {
15
- IdaeDb.instances.set(dbType, new IdaeDb(dbType));
16
- }
17
- return IdaeDb.instances.get(dbType);
18
- }
19
- async createConnection(connectionName, uri, dbName) {
20
- if (this.connections.has(connectionName)) {
21
- throw new Error(`Connection '${connectionName}' already exists.`);
22
- }
23
- const connection = new IdaeDbConnection(uri, dbName, this.dbType);
24
- await connection.connect();
25
- this.connections.set(connectionName, connection);
26
- return connection;
27
- }
28
- getConnection(connectionName) {
29
- const connection = this.connections.get(connectionName);
30
- if (!connection) {
31
- throw new Error(`Connection '${connectionName}' not found.`);
32
- }
33
- return connection;
34
- }
35
- getAdapter(connectionName, collectionName) {
36
- const connection = this.getConnection(connectionName);
37
- switch (this.dbType) {
38
- case DbType.MONGODB:
39
- return new MongoDBAdapter(collectionName, connection);
40
- case DbType.MYSQL:
41
- return new MySQLAdapter(collectionName, connection);
42
- default:
43
- throw new Error(`Unsupported database type: ${this.dbType}`);
44
- }
45
- }
46
- async closeConnection(connectionName) {
47
- const connection = this.connections.get(connectionName);
48
- if (connection) {
49
- await connection.close();
50
- this.connections.delete(connectionName);
51
- }
52
- }
53
- async closeAllConnections() {
54
- for (const [connectionName, connection] of this.connections) {
55
- await connection.close();
56
- }
57
- this.connections.clear();
58
- }
59
- }