refactor(schema): Reorganize insert and select schema declarations

This commit reorganizes the insert and select schema declarations for improved readability. The declarations for 'UsersTable', 'ProductsTable', 'StocksTable', and 'CommentsTable' have been moved closer to their respective table schemas.
This commit is contained in:
Mathis H (Avnyr) 2024-07-10 10:13:04 +02:00
parent 3ac89964ab
commit 1990bedcfd
Signed by: Mathis
GPG Key ID: DD9E0666A747D126

View File

@ -1,5 +1,6 @@
import { pgTable } from "drizzle-orm/pg-core";
import * as p from "drizzle-orm/pg-core";
import { z } from "zod"
import { createInsertSchema, createSelectSchema } from "drizzle-zod";
@ -58,6 +59,9 @@ export const UsersTable = pgTable("users", {
isAdmin: p.boolean("is_admin").default(false).notNull(),
});
export const UsersTableSelectSchema = createSelectSchema(UsersTable)
export const UsersTableInsertSchema = createInsertSchema(UsersTable)
export const ProductsTable = pgTable("products", {
uuid: p.uuid("uuid").unique().primaryKey().defaultRandom().notNull(),
@ -94,6 +98,9 @@ export const ProductsTable = pgTable("products", {
//playload of the description element
});
export const ProductsTableSelectSchema = createSelectSchema(ProductsTable);
export const ProductsTableInsertSchema = createInsertSchema(ProductsTable);
export const StocksTable = pgTable("stocks", {
productId: p
@ -103,6 +110,9 @@ export const StocksTable = pgTable("stocks", {
quantity: p.integer("quantity").default(0).notNull(),
});
export const StocksTableSelectSchema = createSelectSchema(StocksTable);
export const StocksTableInsertSchema = createInsertSchema(StocksTable);
export const CommentsTable = pgTable("comments", {
productId: p
@ -129,6 +139,9 @@ export const CommentsTable = pgTable("comments", {
.defaultNow()
.notNull(),
});
export const CommentsTableSelectSchema = createSelectSchema(CommentsTable);
export const CommentsTableInsertSchema = createInsertSchema(CommentsTable);
export const PurchaseHistory = pgTable("purchases", {
uuid: p.uuid("uuid").unique().primaryKey().defaultRandom().notNull(),
@ -160,18 +173,5 @@ export const PurchaseHistory = pgTable("purchases", {
.defaultNow()
.notNull(),
});
export const UsersTableSelectSchema = createSelectSchema(UsersTable)
export const UsersTableInsertSchema = createInsertSchema(UsersTable)
export const ProductsTableSelectSchema = createSelectSchema(ProductsTable);
export const ProductsTableInsertSchema = createInsertSchema(ProductsTable);
export const StocksTableSelectSchema = createSelectSchema(StocksTable);
export const StocksTableInsertSchema = createInsertSchema(StocksTable);
export const CommentsTableSelectSchema = createSelectSchema(CommentsTable);
export const CommentsTableInsertSchema = createInsertSchema(CommentsTable);
export const PurchaseHistorySelectSchema = createSelectSchema(PurchaseHistory);
export const PurchaseHistoryInsertSchema = createInsertSchema(PurchaseHistory);