mirror of
https://gitea.gofwd.group/dstrawsb/ballistic-builder.git
synced 2025-12-05 18:26:45 -05:00
adding
This commit is contained in:
@@ -1,3 +1,12 @@
|
||||
import 'dotenv/config';
|
||||
import { drizzle } from 'drizzle-orm/node-postgres';
|
||||
const db = drizzle(process.env.DATABASE_URL!);
|
||||
import { Pool } from 'pg';
|
||||
import { sql } from 'drizzle-orm';
|
||||
|
||||
// db/index.ts
|
||||
|
||||
const pool = new Pool({
|
||||
connectionString: process.env.DATABASE_URL,
|
||||
});
|
||||
export const db = drizzle(pool);
|
||||
|
||||
|
||||
23
src/db/queries/index.ts
Normal file
23
src/db/queries/index.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
// db/queries.ts
|
||||
import { accounts } from '../schema/accounts'
|
||||
import { db } from '../index';
|
||||
|
||||
// Fetch all accounts
|
||||
export async function getAllAccounts() {
|
||||
return await db.select().from(accounts);
|
||||
}
|
||||
|
||||
// Add a new accounts
|
||||
export async function addAcounts(name: string) {
|
||||
return await db.insertInto(User).values({ name }).returning();
|
||||
}
|
||||
|
||||
// Update a user
|
||||
export async function updateUser(id: number, name: string) {
|
||||
return await db.update(User).set({ name }).where(User.id.equals(id));
|
||||
}
|
||||
|
||||
// Delete a user
|
||||
export async function deleteUser(id: number) {
|
||||
return await db.deleteFrom(User).where(User.id.equals(id));
|
||||
}
|
||||
Reference in New Issue
Block a user