diff --git a/src/db/schema/baseTable.ts b/src/Example Code/BaseDBTableForDrizzle/baseTable.ts similarity index 82% rename from src/db/schema/baseTable.ts rename to src/Example Code/BaseDBTableForDrizzle/baseTable.ts index 16dc233..ab4a613 100644 --- a/src/db/schema/baseTable.ts +++ b/src/Example Code/BaseDBTableForDrizzle/baseTable.ts @@ -1,6 +1,6 @@ import { pgTable, integer, varchar } from "drizzle-orm/pg-core"; import { sql } from "drizzle-orm"; -import { timestamps } from "./helpers/columns.helpers"; +import { timestamps } from "../../db/schema/helpers/columns.helpers"; export const accounts = pgTable("base_table", { id: integer().primaryKey().generatedAlwaysAsIdentity({ name: "base_id_seq", startWith: 1, increment: 1, minValue: 1, maxValue: 2147483647, cache: 1 }), diff --git a/src/actions/accountActions.ts b/src/actions/accountActions.ts index df5e63e..84918d2 100644 --- a/src/actions/accountActions.ts +++ b/src/actions/accountActions.ts @@ -3,19 +3,23 @@ import { eq, not , asc} from "drizzle-orm"; import { revalidatePath } from "next/cache"; import { db } from "../db"; import { Account } from "../db/schema/Account"; + export const getData = async () => { const data = await db.select().from(Account).orderBy(asc(Account.last_name)); return data; }; + export const addAccount = async ( first_name: string, last_name: string, username: string, email: string, password_hash : string) => { await db.insert(Account).values({ first_name : first_name, last_name: last_name, username: username, password_hash : password_hash }); }; + export const deleteAccount = async (id: number) => { await db.delete(Account).where(eq(Account.id, id)); revalidatePath("/"); }; + export const editAccount = async (id: number, first_name: string, last_name: string, username: string, email : string, password_hash: string) => { await db .update(Account) diff --git a/src/components/ComponentType/ComponentTypeList.tsx b/src/components/ComponentType/ComponentTypeList.tsx index b121372..085fe7a 100644 --- a/src/components/ComponentType/ComponentTypeList.tsx +++ b/src/components/ComponentType/ComponentTypeList.tsx @@ -3,7 +3,7 @@ import { FC, useState } from "react"; import { componentTypeType } from "src/types/componentTypeType"; import { componentType } from './componentType' // import AddBrand from "./addBrand"; -import { getData } from "../../actions/componentTypeActions"; +import { getData } from "src/actions/componentTypeActions"; interface Props { componentType: componentType[]; diff --git a/src/db/queries/index.ts b/src/db/queries/Accounts/index.ts similarity index 91% rename from src/db/queries/index.ts rename to src/db/queries/Accounts/index.ts index 2749d68..dd256de 100644 --- a/src/db/queries/index.ts +++ b/src/db/queries/Accounts/index.ts @@ -1,8 +1,8 @@ // db/queries.ts "use server"; import { eq, not , asc} from "drizzle-orm"; -import { Account } from '../schema/Account' -import { db } from '../index'; +import { Account } from '../../schema/Account' +import { db } from '../../index'; // Fetch all account export async function getAllAccounts() { diff --git a/src/db/queries/Products/index.ts b/src/db/queries/Products/index.ts new file mode 100644 index 0000000..9648294 --- /dev/null +++ b/src/db/queries/Products/index.ts @@ -0,0 +1,25 @@ +// db/queries.ts +"use server"; +import { eq, not , asc} from "drizzle-orm"; +import { Product } from '../../schema/Product' +import { db } from '../../index'; + +// Fetch all account +export async function getAllProducts() { + return await db.select().from(Product); +} + +// Add a new product +export async function addProduct() { + return await db.insert(Product).values({}).returning(); +} + +// Update a Product +export async function updateProduct( ) { + return await db.update(Product).set({ }).where(eq(Product.id, id)); +} + +// Delete a product +export async function deleteProduct(id: number) { + return await db.delete(Product).where(eq(Product.id, id)); +} \ No newline at end of file diff --git a/src/drizzle/schema.ts b/src/drizzle/schema.ts index e42766d..79518f3 100644 --- a/src/drizzle/schema.ts +++ b/src/drizzle/schema.ts @@ -1,8 +1,6 @@ import { pgTable, integer, varchar, timestamp, text, numeric, unique, doublePrecision } from "drizzle-orm/pg-core" import { sql } from "drizzle-orm" - - export const productFeeds = pgTable("product_feeds", { id: integer().primaryKey().generatedAlwaysAsIdentity({ name: "productfeeds_id_seq", startWith: 1, increment: 1, minValue: 1, maxValue: 2147483647, cache: 1 }), resellerId: integer("reseller_id").notNull(),