mirror of
https://gitea.gofwd.group/dstrawsb/ballistic-builder.git
synced 2025-12-06 02:36:44 -05:00
more fixes and organizing
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
import { pgTable, integer, varchar } from "drizzle-orm/pg-core";
|
import { pgTable, integer, varchar } from "drizzle-orm/pg-core";
|
||||||
import { sql } from "drizzle-orm";
|
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", {
|
export const accounts = pgTable("base_table", {
|
||||||
id: integer().primaryKey().generatedAlwaysAsIdentity({ name: "base_id_seq", startWith: 1, increment: 1, minValue: 1, maxValue: 2147483647, cache: 1 }),
|
id: integer().primaryKey().generatedAlwaysAsIdentity({ name: "base_id_seq", startWith: 1, increment: 1, minValue: 1, maxValue: 2147483647, cache: 1 }),
|
||||||
@@ -3,19 +3,23 @@ import { eq, not , asc} from "drizzle-orm";
|
|||||||
import { revalidatePath } from "next/cache";
|
import { revalidatePath } from "next/cache";
|
||||||
import { db } from "../db";
|
import { db } from "../db";
|
||||||
import { Account } from "../db/schema/Account";
|
import { Account } from "../db/schema/Account";
|
||||||
|
|
||||||
export const getData = async () => {
|
export const getData = async () => {
|
||||||
const data = await db.select().from(Account).orderBy(asc(Account.last_name));
|
const data = await db.select().from(Account).orderBy(asc(Account.last_name));
|
||||||
return data;
|
return data;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const addAccount = async ( first_name: string, last_name: string, username: string, email: string, password_hash : string) => {
|
export const addAccount = async ( first_name: string, last_name: string, username: string, email: string, password_hash : string) => {
|
||||||
await db.insert(Account).values({
|
await db.insert(Account).values({
|
||||||
first_name : first_name, last_name: last_name, username: username, password_hash : password_hash
|
first_name : first_name, last_name: last_name, username: username, password_hash : password_hash
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
export const deleteAccount = async (id: number) => {
|
export const deleteAccount = async (id: number) => {
|
||||||
await db.delete(Account).where(eq(Account.id, id));
|
await db.delete(Account).where(eq(Account.id, id));
|
||||||
revalidatePath("/");
|
revalidatePath("/");
|
||||||
};
|
};
|
||||||
|
|
||||||
export const editAccount = async (id: number, first_name: string, last_name: string, username: string, email : string, password_hash: string) => {
|
export const editAccount = async (id: number, first_name: string, last_name: string, username: string, email : string, password_hash: string) => {
|
||||||
await db
|
await db
|
||||||
.update(Account)
|
.update(Account)
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import { FC, useState } from "react";
|
|||||||
import { componentTypeType } from "src/types/componentTypeType";
|
import { componentTypeType } from "src/types/componentTypeType";
|
||||||
import { componentType } from './componentType'
|
import { componentType } from './componentType'
|
||||||
// import AddBrand from "./addBrand";
|
// import AddBrand from "./addBrand";
|
||||||
import { getData } from "../../actions/componentTypeActions";
|
import { getData } from "src/actions/componentTypeActions";
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
componentType: componentType[];
|
componentType: componentType[];
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
// db/queries.ts
|
// db/queries.ts
|
||||||
"use server";
|
"use server";
|
||||||
import { eq, not , asc} from "drizzle-orm";
|
import { eq, not , asc} from "drizzle-orm";
|
||||||
import { Account } from '../schema/Account'
|
import { Account } from '../../schema/Account'
|
||||||
import { db } from '../index';
|
import { db } from '../../index';
|
||||||
|
|
||||||
// Fetch all account
|
// Fetch all account
|
||||||
export async function getAllAccounts() {
|
export async function getAllAccounts() {
|
||||||
25
src/db/queries/Products/index.ts
Normal file
25
src/db/queries/Products/index.ts
Normal file
@@ -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));
|
||||||
|
}
|
||||||
@@ -1,8 +1,6 @@
|
|||||||
import { pgTable, integer, varchar, timestamp, text, numeric, unique, doublePrecision } from "drizzle-orm/pg-core"
|
import { pgTable, integer, varchar, timestamp, text, numeric, unique, doublePrecision } from "drizzle-orm/pg-core"
|
||||||
import { sql } from "drizzle-orm"
|
import { sql } from "drizzle-orm"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
export const productFeeds = pgTable("product_feeds", {
|
export const productFeeds = pgTable("product_feeds", {
|
||||||
id: integer().primaryKey().generatedAlwaysAsIdentity({ name: "productfeeds_id_seq", startWith: 1, increment: 1, minValue: 1, maxValue: 2147483647, cache: 1 }),
|
id: integer().primaryKey().generatedAlwaysAsIdentity({ name: "productfeeds_id_seq", startWith: 1, increment: 1, minValue: 1, maxValue: 2147483647, cache: 1 }),
|
||||||
resellerId: integer("reseller_id").notNull(),
|
resellerId: integer("reseller_id").notNull(),
|
||||||
|
|||||||
Reference in New Issue
Block a user