-
Notifications
You must be signed in to change notification settings - Fork 1
/
drizzle.ts
35 lines (28 loc) · 935 Bytes
/
drizzle.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import { drizzle } from 'drizzle-orm/node-postgres';
import pg from 'pg';
import { postgresConfig } from '../config';
import { eq } from 'drizzle-orm';
import { serial, text, pgTable, timestamp } from 'drizzle-orm/pg-core';
const users = pgTable('users', {
id: serial('id').primaryKey(),
username: text('username').notNull(),
email: text('email').notNull(),
password: text('password').notNull(),
name: text('name').notNull(),
createdAt: timestamp('created_at').notNull(),
updatedAt: timestamp('updated_at').notNull(),
deletedAt: timestamp('deleted_at'),
});
const { max, ...config } = postgresConfig;
if (max) {
Object.assign(config, { max });
}
const pool = new pg.Pool(config);
const db = drizzle(pool);
export const drizzlePostgreGetUser = async (id: number) =>
await db
.select()
.from(users)
.where(eq(users.id, id))
.then((arr) => arr[0]);
export const drizzleClose = () => pool.end();