From 1990bedcfdd33a654ddd77e6870b804c2527246a Mon Sep 17 00:00:00 2001 From: Mathis Date: Wed, 10 Jul 2024 10:13:04 +0200 Subject: [PATCH] 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. --- src/schema.ts | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/schema.ts b/src/schema.ts index 94fdaee..74b4766 100644 --- a/src/schema.ts +++ b/src/schema.ts @@ -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);