Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Connection Factory #40

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion playground/index.js
Original file line number Diff line number Diff line change
@@ -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();
Expand Down
24 changes: 24 additions & 0 deletions src/connections/_factory.ts
Original file line number Diff line number Diff line change
@@ -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<Connection> {
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}`);
}
}
}
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -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';
Loading