Skip to content

Commit 0504578

Browse files
committed
Separate database packages
This is a very small refactor which aligns more with the spirit of our repo which is that meaningful exports are placed in their own file and consolidated by an index.ts.
1 parent 11ecdfd commit 0504578

File tree

3 files changed

+19
-15
lines changed

3 files changed

+19
-15
lines changed

src/database/db.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import path from 'path';
2+
import { TinyPg } from 'tinypg';
3+
4+
export const db = new TinyPg({
5+
root_dir: [path.resolve(__dirname, 'queries')],
6+
});

src/database/index.ts

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,2 @@
1-
import path from 'path';
2-
import { TinyPg } from 'tinypg';
3-
import { migrate as pgMigrate } from 'postgres-migrations';
4-
5-
export const db = new TinyPg({
6-
root_dir: [path.resolve(__dirname, 'queries')],
7-
});
8-
9-
export const migrate = async (): Promise<void> => {
10-
const client = await db.getClient();
11-
await pgMigrate(
12-
{ client },
13-
path.resolve(__dirname, 'migrations'),
14-
);
15-
};
1+
export * from './db';
2+
export * from './migrate';

src/database/migrate.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import path from 'path';
2+
import { migrate as pgMigrate } from 'postgres-migrations';
3+
import { db } from './db';
4+
5+
export const migrate = async (): Promise<void> => {
6+
const client = await db.getClient();
7+
await pgMigrate(
8+
{ client },
9+
path.resolve(__dirname, 'migrations'),
10+
);
11+
};

0 commit comments

Comments
 (0)