Files
ballistic-builder/src/actions/brandActions.ts

31 lines
756 B
TypeScript

"use server";
import { eq, not , asc} from "drizzle-orm";
import { revalidatePath } from "next/cache";
import { db } from "@db/index";
import { brands } from "@schemas/schema";
export const getData = async () => {
const data = await db.select().from(brands).orderBy(asc(brands.name));
return data;
};
export const addBrand = async ( name: string) => {
await db.insert(brands).values({
name: name,
});
};
export const deleteBrand = async (id: number) => {
"use server";
await db.delete(brands).where(eq(brands.id, id));
revalidatePath("/Brands");
};
export const editBrand = async (id: number, name: string) => {
await db
.update(brands)
.set({
name: name,
})
.where(eq(brands.id, id));
revalidatePath("/");
};