diff --git a/express/bun.lockb b/express/bun.lockb index dc22586..1707daf 100755 Binary files a/express/bun.lockb and b/express/bun.lockb differ diff --git a/express/package.json b/express/package.json index 3d33f6c..5ffa25e 100644 --- a/express/package.json +++ b/express/package.json @@ -1 +1,9 @@ -{ "dependencies": { "@types/express": "^4.17.17", "express": "^4.18.2" } } \ No newline at end of file +{ + "dependencies": { + "@types/express": "^4.17.17", + "@types/pg": "^8.10.2", + "express": "^4.18.2", + "kysely": "^0.26.3", + "pg": "^8.11.3" + } +} diff --git a/express/src/database.ts b/express/src/database.ts new file mode 100644 index 0000000..3fd030f --- /dev/null +++ b/express/src/database.ts @@ -0,0 +1,18 @@ +import { Database } from './types' +import { Pool } from 'pg' +import { Kysely, PostgresDialect } from 'kysely' + +const dialect = new PostgresDialect({ + pool: new Pool({ + database: 'link-shortener', + host: '0.0.0.0', + user: 'postgres', + password: 'password', + port: 5432, + max: 10, + }), +}) + +export const db = new Kysely({ + dialect, +}) diff --git a/express/src/types.ts b/express/src/types.ts new file mode 100644 index 0000000..f511492 --- /dev/null +++ b/express/src/types.ts @@ -0,0 +1,15 @@ +import { Generated, Insertable, Selectable, Updateable } from 'kysely' + +export interface Database { + shortener: ShortenerTable +} + +export interface ShortenerTable { + id: Generated + link: string + code: string +} + +export type Shortener = Selectable +export type NewShortener = Insertable +export type ShortenerUpdate = Updateable