Skip to content

Commit

Permalink
fix: separate database initialization into separate file
Browse files Browse the repository at this point in the history
  • Loading branch information
Aericio committed May 29, 2024
1 parent 4af1d9c commit 8db6410
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 20 deletions.
23 changes: 3 additions & 20 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,3 @@
import postgres from "postgres";
import { drizzle } from "drizzle-orm/postgres-js";
import { cosmetics, players } from "./schema";

/**
* @param connectionString See {@link https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-CONNSTRING-URIS Postgres Connection URIs}
*/
export default function initializeDatabase({
connectionUri,
}: {
connectionUri: string;
}) {
const client = postgres(connectionUri, { prepare: false });
const db = drizzle(client, { schema: { cosmetics, players } });

return { client, db };
}

export * from "./types";
export * from "./schema";
export * from "./lib/database";
export * from "./lib/types";
export * from "./lib/schema";
17 changes: 17 additions & 0 deletions src/lib/database.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import postgres from "postgres";
import { drizzle } from "drizzle-orm/postgres-js";
import { cosmetics, players } from "./schema";

/**
* @param connectionString See {@link https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-CONNSTRING-URIS Postgres Connection URIs}
*/
export default function initializeDatabase({
connectionUri,
}: {
connectionUri: string;
}) {
const client = postgres(connectionUri, { prepare: false });
const db = drizzle(client, { schema: { cosmetics, players } });

return { client, db };
}
File renamed without changes.
File renamed without changes.

0 comments on commit 8db6410

Please sign in to comment.