From f4b89d95e1a91487d9294aebd4b97ba2b396ccd3 Mon Sep 17 00:00:00 2001 From: Brayden Wilmoth Date: Tue, 25 Jun 2024 21:00:53 -0400 Subject: [PATCH 1/4] Connection Factory --- playground/index.js | 2 +- src/index.ts | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/playground/index.js b/playground/index.js index d7f20a2..7979689 100644 --- a/playground/index.js +++ b/playground/index.js @@ -1,4 +1,4 @@ -import { CloudflareD1Connection, Outerbase, OuterbaseConnection, equalsNumber } from '../dist/index.js'; +import { DatabaseFactory, DatabaseType, Outerbase, greaterThanOrEqualNumber } from '../dist/index.js'; import express from 'express'; const app = express(); diff --git a/src/index.ts b/src/index.ts index d915917..9695452 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,6 +1,7 @@ export * from './connections'; +export * from './connections/_factory'; export * from './connections/outerbase'; -export * from './connections/cloudflare'; +// export * from './connections/cloudflare'; export * from './client'; export * from './models'; export * from './models/decorators'; From e18d0cb5f9e34c34fe9aade3eca4ada127fd6c38 Mon Sep 17 00:00:00 2001 From: Brayden Wilmoth Date: Tue, 25 Jun 2024 21:01:03 -0400 Subject: [PATCH 2/4] Connection Factory --- src/connections/_factory.ts | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 src/connections/_factory.ts diff --git a/src/connections/_factory.ts b/src/connections/_factory.ts new file mode 100644 index 0000000..c7b807e --- /dev/null +++ b/src/connections/_factory.ts @@ -0,0 +1,26 @@ +// DatabaseFactory.ts +import { Connection } from './index' + +export enum DatabaseType { + Outerbase = 'outerbase', + Cloudflare = 'cloudflare', + Neon = 'neon' +} + +export class DatabaseFactory { + static async createConnection(type: DatabaseType, config: any): Promise { + switch (type) { + case DatabaseType.Outerbase: + const { OuterbaseConnection } = await import('./outerbase'); + return new OuterbaseConnection(config); + case DatabaseType.Cloudflare: + const { CloudflareD1Connection } = await import('./cloudflare'); + return new CloudflareD1Connection(config); + case DatabaseType.Neon: + // const { MySQLConnection } = await import('./MySQLConnection'); + // return new MySQLConnection(config); + default: + throw new Error(`Unsupported database type: ${type}`); + } + } +} From eadc8af60c99525341be0676a1cc110437e3f170 Mon Sep 17 00:00:00 2001 From: Brayden Wilmoth Date: Tue, 25 Jun 2024 21:04:59 -0400 Subject: [PATCH 3/4] Rename factory class --- playground/index.js | 2 +- src/connections/_factory.ts | 15 +++++++-------- src/index.ts | 1 - 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/playground/index.js b/playground/index.js index 7979689..5a719a3 100644 --- a/playground/index.js +++ b/playground/index.js @@ -1,4 +1,4 @@ -import { DatabaseFactory, DatabaseType, Outerbase, greaterThanOrEqualNumber } from '../dist/index.js'; +import { ConnectionFactory, DatabaseType, Outerbase, greaterThanOrEqualNumber } from '../dist/index.js'; import express from 'express'; const app = express(); diff --git a/src/connections/_factory.ts b/src/connections/_factory.ts index c7b807e..c95fbd0 100644 --- a/src/connections/_factory.ts +++ b/src/connections/_factory.ts @@ -1,24 +1,23 @@ // DatabaseFactory.ts import { Connection } from './index' -export enum DatabaseType { +export enum ConnectionType { Outerbase = 'outerbase', Cloudflare = 'cloudflare', Neon = 'neon' } -export class DatabaseFactory { - static async createConnection(type: DatabaseType, config: any): Promise { +export class ConnectionFactory { + static async createConnection(type: ConnectionType, config: any): Promise { switch (type) { - case DatabaseType.Outerbase: + case ConnectionType.Outerbase: const { OuterbaseConnection } = await import('./outerbase'); return new OuterbaseConnection(config); - case DatabaseType.Cloudflare: + case ConnectionType.Cloudflare: const { CloudflareD1Connection } = await import('./cloudflare'); return new CloudflareD1Connection(config); - case DatabaseType.Neon: - // const { MySQLConnection } = await import('./MySQLConnection'); - // return new MySQLConnection(config); + case ConnectionType.Neon: + // TODO: Implement Neon connection after https://github.com/outerbase/sdk/pull/39 is merged default: throw new Error(`Unsupported database type: ${type}`); } diff --git a/src/index.ts b/src/index.ts index 9695452..cbec859 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,7 +1,6 @@ export * from './connections'; export * from './connections/_factory'; export * from './connections/outerbase'; -// export * from './connections/cloudflare'; export * from './client'; export * from './models'; export * from './models/decorators'; From da8a84ece265bf63687ead65a13774d4edcd9ba4 Mon Sep 17 00:00:00 2001 From: Brayden Wilmoth Date: Tue, 25 Jun 2024 21:05:58 -0400 Subject: [PATCH 4/4] Remove unused code --- playground/index.js | 2 +- src/connections/_factory.ts | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/playground/index.js b/playground/index.js index 5a719a3..7ac9f64 100644 --- a/playground/index.js +++ b/playground/index.js @@ -1,4 +1,4 @@ -import { ConnectionFactory, DatabaseType, Outerbase, greaterThanOrEqualNumber } from '../dist/index.js'; +import { ConnectionFactory, DatabaseType } from '../dist/index.js'; import express from 'express'; const app = express(); diff --git a/src/connections/_factory.ts b/src/connections/_factory.ts index c95fbd0..eac1cc5 100644 --- a/src/connections/_factory.ts +++ b/src/connections/_factory.ts @@ -1,4 +1,3 @@ -// DatabaseFactory.ts import { Connection } from './index' export enum ConnectionType {