Move db calls to server file

This commit is contained in:
2024-07-19 15:58:24 -05:00
parent bf7f6a466a
commit 76977427e0
6 changed files with 79 additions and 41 deletions

View File

@ -13,8 +13,8 @@ export const users = createTable(
"users",
{
id: bigint("id", {mode: "number"}).primaryKey().autoincrement(),
name: varchar("name", { length: 256 }),
status: varchar("status", { length: 256 }),
name: varchar("name", { length: 256 }).notNull(),
status: varchar("status", { length: 256 }).notNull(),
updatedAt: timestamp("updated_at")
.default(sql`CURRENT_TIMESTAMP`)
.notNull(),
@ -26,7 +26,7 @@ export const history = createTable(
{
id: bigint("id", {mode: "number"}).primaryKey().autoincrement(),
user_id: bigint("user_id", {mode: "number"}).references(() => users.id),
status: varchar("status", { length: 256 }),
status: varchar("status", { length: 256 }).notNull(),
updatedAt: timestamp("updated_at").notNull(),
},
);

11
src/server/functions.ts Normal file
View File

@ -0,0 +1,11 @@
import "server-only";
import { db } from "~/server/db";
//import * as schema from "~/server/db/schema";
export const getEmployees = async () => {
return await db.query.users.findMany({
orderBy: (model, { desc }) => desc(model.id),
});
};