Skip to content

Commit 2c344f0

Browse files
committed
feat: DB provider/migration 스캐폴드 추가
1 parent 65a2eb1 commit 2c344f0

6 files changed

Lines changed: 95 additions & 0 deletions

File tree

packages/core/src/db/index.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,13 @@ export interface MigrationRunner {
88
up(): Promise<void>;
99
down(): Promise<void>;
1010
}
11+
12+
export interface DbConnectionConfig {
13+
connectionString: string;
14+
}
15+
16+
export * from "./migrations";
17+
export * from "./providers/postgres";
18+
export * from "./providers/sqlite";
19+
export * from "./providers/supabase";
20+
export * from "./providers/mongodb";
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import type { MigrationRunner } from "../index";
2+
3+
export interface MigrationDefinition {
4+
id: string;
5+
upSql: string;
6+
downSql: string;
7+
}
8+
9+
export class InMemoryMigrationRunner implements MigrationRunner {
10+
private readonly applied: string[] = [];
11+
12+
public constructor(private readonly migrations: MigrationDefinition[]) {}
13+
14+
public async up(): Promise<void> {
15+
this.applied.splice(0, this.applied.length, ...this.migrations.map((item) => item.id));
16+
}
17+
18+
public async down(): Promise<void> {
19+
this.applied.splice(0, this.applied.length);
20+
}
21+
22+
public listApplied(): string[] {
23+
return [...this.applied];
24+
}
25+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import type { DbConnectionConfig, DbProvider } from "../index";
2+
3+
export class MongoDbProvider implements DbProvider {
4+
public readonly name = "mongodb";
5+
6+
public constructor(private readonly config: DbConnectionConfig) {}
7+
8+
public async connect(): Promise<void> {
9+
void this.config.connectionString;
10+
}
11+
12+
public async disconnect(): Promise<void> {
13+
return Promise.resolve();
14+
}
15+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import type { DbConnectionConfig, DbProvider } from "../index";
2+
3+
export class PostgresProvider implements DbProvider {
4+
public readonly name = "postgres";
5+
6+
public constructor(private readonly config: DbConnectionConfig) {}
7+
8+
public async connect(): Promise<void> {
9+
void this.config.connectionString;
10+
}
11+
12+
public async disconnect(): Promise<void> {
13+
return Promise.resolve();
14+
}
15+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import type { DbConnectionConfig, DbProvider } from "../index";
2+
3+
export class SqliteProvider implements DbProvider {
4+
public readonly name = "sqlite";
5+
6+
public constructor(private readonly config: DbConnectionConfig) {}
7+
8+
public async connect(): Promise<void> {
9+
void this.config.connectionString;
10+
}
11+
12+
public async disconnect(): Promise<void> {
13+
return Promise.resolve();
14+
}
15+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import type { DbConnectionConfig, DbProvider } from "../index";
2+
3+
export class SupabaseProvider implements DbProvider {
4+
public readonly name = "supabase";
5+
6+
public constructor(private readonly config: DbConnectionConfig) {}
7+
8+
public async connect(): Promise<void> {
9+
void this.config.connectionString;
10+
}
11+
12+
public async disconnect(): Promise<void> {
13+
return Promise.resolve();
14+
}
15+
}

0 commit comments

Comments
 (0)