diff --git a/playground/index.js b/playground/index.js index d7f20a2..7ac9f64 100644 --- a/playground/index.js +++ b/playground/index.js @@ -1,4 +1,4 @@ -import { CloudflareD1Connection, Outerbase, OuterbaseConnection, equalsNumber } 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 new file mode 100644 index 0000000..eac1cc5 --- /dev/null +++ b/src/connections/_factory.ts @@ -0,0 +1,24 @@ +import { Connection } from './index' + +export enum ConnectionType { + Outerbase = 'outerbase', + Cloudflare = 'cloudflare', + Neon = 'neon' +} + +export class ConnectionFactory { + static async createConnection(type: ConnectionType, config: any): Promise { + switch (type) { + case ConnectionType.Outerbase: + const { OuterbaseConnection } = await import('./outerbase'); + return new OuterbaseConnection(config); + case ConnectionType.Cloudflare: + const { CloudflareD1Connection } = await import('./cloudflare'); + return new CloudflareD1Connection(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 d915917..cbec859 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,6 +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';