installing drizzle, confirm working db connection via test script
This commit is contained in:
parent
681c6d2b4f
commit
3faa3d4ffb
5 changed files with 1068 additions and 60 deletions
1
.env.example
Normal file
1
.env.example
Normal file
|
|
@ -0,0 +1 @@
|
|||
DATABASE_URL=postgres://postgres:mypassword@localhost:5432/postgres
|
||||
|
|
@ -2,5 +2,14 @@
|
|||
"name": "@glossa/db",
|
||||
"version": "1.0.0",
|
||||
"private": true,
|
||||
"type": "module"
|
||||
"type": "module",
|
||||
"dependencies": {
|
||||
"dotenv": "^17.3.1",
|
||||
"drizzle-orm": "^0.45.1",
|
||||
"pg": "^8.20.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/pg": "^8.20.0",
|
||||
"drizzle-kit": "^0.31.10"
|
||||
}
|
||||
}
|
||||
|
|
|
|||
11
packages/db/src/index.ts
Normal file
11
packages/db/src/index.ts
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
import { config } from "dotenv";
|
||||
import { drizzle } from "drizzle-orm/node-postgres";
|
||||
import { resolve } from "path";
|
||||
import { fileURLToPath } from "url";
|
||||
import { dirname } from "path";
|
||||
|
||||
config({
|
||||
path: resolve(dirname(fileURLToPath(import.meta.url)), "../../../.env"),
|
||||
});
|
||||
|
||||
export const db = drizzle(process.env["DATABASE_URL"]!);
|
||||
5
packages/db/src/test-db-connection.ts
Normal file
5
packages/db/src/test-db-connection.ts
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
import { db } from "./index.js";
|
||||
|
||||
const result = await db.execute("select 1");
|
||||
|
||||
console.log("result: ", result);
|
||||
1100
pnpm-lock.yaml
generated
1100
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue