diff --git a/src/db/index.ts b/src/db/index.ts index 819ebab..c2226e6 100644 --- a/src/db/index.ts +++ b/src/db/index.ts @@ -1,5 +1,5 @@ import 'dotenv/config'; -import { drizzle } from 'drizzle-orm'; +import { drizzle } from 'drizzle-orm/node-postgres'; import { Pool } from 'pg'; import { sql } from 'drizzle-orm'; @@ -8,5 +8,6 @@ import { sql } from 'drizzle-orm'; const pool = new Pool({ connectionString: process.env.DATABASE_URL, }); + export const db = drizzle(pool); diff --git a/src/db/queries/index.ts b/src/db/queries/index.ts index 4ca8b50..6a3907e 100644 --- a/src/db/queries/index.ts +++ b/src/db/queries/index.ts @@ -1,23 +1,23 @@ // db/queries.ts -import { accounts } from '../schema/Account' +import { Account } from '../schema/Account' import { db } from '../index'; -// Fetch all accounts +// Fetch all account export async function getAllAccounts() { - return await db.select().from(accounts); + return await db.select().from(Account); } -// Add a new accounts -export async function addAcounts(name: string) { - return await db.insertInto(accounts).values({ name }).returning(); +// Add a new account +export async function addAcount(first_name: string, last_name : string, username : string, password_hash: string ) { + return await db.insert(Account).values({ first_name, last_name, username, password_hash }).returning(); } -// Update a accounts -export async function updateAcounts(id: number, name: string) { - return await db.update(accounts).set({ name }).where(accounts.id.equals(id)); +// Update a account +export async function updateAcount(id: number, first_name: string, last_name : string, username : string, password_hash: string ) { + return await db.update(Account).set({ first_name, last_name, username, password_hash }).where(Account.id.equals(id)); } -// Delete a accounts +// Delete a account export async function deleteAccount(id: number) { - return await db.deleteFrom(accounts).where(accounts.id.equals(id)); + return await db.delete(Account).where(Account.id.equals(id)); } \ No newline at end of file diff --git a/src/db/schema.ts b/src/db/schema.ts deleted file mode 100644 index 755e0f8..0000000 --- a/src/db/schema.ts +++ /dev/null @@ -1,7 +0,0 @@ -import { integer, pgTable, varchar } from "drizzle-orm/pg-core"; -export const usersTable = pgTable("users", { - id: integer().primaryKey().generatedAlwaysAsIdentity(), - name: varchar({ length: 255 }).notNull(), - age: integer().notNull(), - email: varchar({ length: 255 }).notNull().unique(), -}); \ No newline at end of file diff --git a/src/db/schema/Account.ts b/src/db/schema/Account.ts index ed11859..61f1dad 100644 --- a/src/db/schema/Account.ts +++ b/src/db/schema/Account.ts @@ -1,6 +1,6 @@ import { pgTable, integer, varchar } from "drizzle-orm/pg-core"; import { sql } from "drizzle-orm"; -import { timestamps } from "./columns.helpers"; +import { timestamps } from "./helpers/columns.helpers"; export const Account = pgTable("bal_accounts", { id: integer().primaryKey().generatedAlwaysAsIdentity({ name: "accounts_id_seq", startWith: 1, increment: 1, minValue: 1, maxValue: 2147483647, cache: 1 }), diff --git a/src/db/schema/Build.ts b/src/db/schema/Build.ts new file mode 100644 index 0000000..b190766 --- /dev/null +++ b/src/db/schema/Build.ts @@ -0,0 +1,11 @@ +import { pgTable, integer, varchar, text } from "drizzle-orm/pg-core"; +import { sql } from "drizzle-orm"; +import { timestamps } from "./helpers/columns.helpers"; + +export const Build = pgTable("builds", { + id: integer().primaryKey().generatedAlwaysAsIdentity({ name: "build_id_seq", startWith: 1, increment: 1, minValue: 1, maxValue: 2147483647, cache: 1 }), + account_id: integer().notNull(), + name: varchar({length:255}).notNull(), + description: text(), + ...timestamps +}) \ No newline at end of file diff --git a/src/db/schema/BuildComponent.ts b/src/db/schema/BuildComponent.ts new file mode 100644 index 0000000..8c850f1 --- /dev/null +++ b/src/db/schema/BuildComponent.ts @@ -0,0 +1,10 @@ +import { pgTable, integer, varchar, text } from "drizzle-orm/pg-core"; +import { sql } from "drizzle-orm"; +import { timestamps } from "./helpers/columns.helpers"; + +export const BuildComponent = pgTable("builds_components", { + id: integer().primaryKey().generatedAlwaysAsIdentity({ name: "build_components_id_seq", startWith: 1, increment: 1, minValue: 1, maxValue: 2147483647, cache: 1 }), + build_id: integer().notNull(), + product_id: integer().notNull(), + ...timestamps +}) \ No newline at end of file diff --git a/src/db/schema/Category.ts b/src/db/schema/Category.ts index 280d26f..2f59877 100644 --- a/src/db/schema/Category.ts +++ b/src/db/schema/Category.ts @@ -1,6 +1,6 @@ import { pgTable, integer, varchar } from "drizzle-orm/pg-core"; import { sql } from "drizzle-orm"; -import { timestamps } from "./columns.helpers"; +import { timestamps } from "./helpers/columns.helpers"; export const Category = pgTable("categories", { id: integer().primaryKey().generatedAlwaysAsIdentity({ name: "categories_id_seq", startWith: 1, increment: 1, minValue: 1, maxValue: 2147483647, cache: 1 }), diff --git a/src/db/schema/LipseyCatalog.ts b/src/db/schema/LipseyCatalog.ts index ce87ab7..05ab6eb 100644 --- a/src/db/schema/LipseyCatalog.ts +++ b/src/db/schema/LipseyCatalog.ts @@ -1,6 +1,6 @@ import { pgTable, integer, varchar, text, doublePrecision, timestamp } from "drizzle-orm/pg-core" import { sql } from "drizzle-orm" -import { timestamps } from "./columns.helpers"; +import { timestamps } from "./helpers/columns.helpers"; export const LipseyCatalog = pgTable("lipseycatalog", { diff --git a/src/db/schema/Product.ts b/src/db/schema/Product.ts index dd3c047..85bb63b 100644 --- a/src/db/schema/Product.ts +++ b/src/db/schema/Product.ts @@ -1,6 +1,6 @@ import { pgTable, integer, varchar, text, decimal } from "drizzle-orm/pg-core"; import { sql } from "drizzle-orm"; -import { timestamps } from "./columns.helpers"; +import { timestamps } from "./helpers/columns.helpers"; export const Product = pgTable("products", { id: integer().primaryKey().generatedAlwaysAsIdentity({ name: "products_id_seq", startWith: 1, increment: 1, minValue: 1, maxValue: 2147483647, cache: 1 }), diff --git a/src/db/schema/Product_feed.ts b/src/db/schema/Product_feed.ts index b0c20f5..0ae9f22 100644 --- a/src/db/schema/Product_feed.ts +++ b/src/db/schema/Product_feed.ts @@ -1,6 +1,6 @@ import { pgTable, integer, varchar, timestamp } from "drizzle-orm/pg-core"; import { sql } from "drizzle-orm"; -import { timestamps } from "./columns.helpers"; +import { timestamps } from "./helpers/columns.helpers"; export const Product_feed = pgTable("product_feeds", { id: integer().primaryKey().generatedAlwaysAsIdentity({ name: "productfeeds_id_seq", startWith: 1, increment: 1, minValue: 1, maxValue: 2147483647, cache: 1 }), diff --git a/src/db/schema/Reseller.ts b/src/db/schema/Reseller.ts index 16c6e81..786e1d2 100644 --- a/src/db/schema/Reseller.ts +++ b/src/db/schema/Reseller.ts @@ -1,6 +1,6 @@ import { pgTable, integer, varchar } from "drizzle-orm/pg-core"; import { sql } from "drizzle-orm"; -import { timestamps } from "./columns.helpers"; +import { timestamps } from "./helpers/columns.helpers"; export const Reseller = pgTable("bal_resellers", { id: integer().primaryKey().generatedAlwaysAsIdentity({ name: "resellers_id_seq", startWith: 1, increment: 1, minValue: 1, maxValue: 2147483647, cache: 1 }), diff --git a/src/db/schema/baseTable.ts b/src/db/schema/baseTable.ts index 9387682..16dc233 100644 --- a/src/db/schema/baseTable.ts +++ b/src/db/schema/baseTable.ts @@ -1,6 +1,6 @@ import { pgTable, integer, varchar } from "drizzle-orm/pg-core"; import { sql } from "drizzle-orm"; -import { timestamps } from "./columns.helpers"; +import { timestamps } from "./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/db/schema/columns.helpers.ts b/src/db/schema/helpers/columns.helpers.ts similarity index 100% rename from src/db/schema/columns.helpers.ts rename to src/db/schema/helpers/columns.helpers.ts diff --git a/src/drizzle/schema/lipseyCatalog.ts b/src/drizzle/schema/lipseyCatalog.ts deleted file mode 100644 index e69de29..0000000