mirror of
https://gitea.gofwd.group/dstrawsb/ballistic-builder.git
synced 2025-12-05 18:26:45 -05:00
more database design
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
import 'dotenv/config';
|
import 'dotenv/config';
|
||||||
import { drizzle } from 'drizzle-orm';
|
import { drizzle } from 'drizzle-orm/node-postgres';
|
||||||
import { Pool } from 'pg';
|
import { Pool } from 'pg';
|
||||||
import { sql } from 'drizzle-orm';
|
import { sql } from 'drizzle-orm';
|
||||||
|
|
||||||
@@ -8,5 +8,6 @@ import { sql } from 'drizzle-orm';
|
|||||||
const pool = new Pool({
|
const pool = new Pool({
|
||||||
connectionString: process.env.DATABASE_URL,
|
connectionString: process.env.DATABASE_URL,
|
||||||
});
|
});
|
||||||
|
|
||||||
export const db = drizzle(pool);
|
export const db = drizzle(pool);
|
||||||
|
|
||||||
|
|||||||
@@ -1,23 +1,23 @@
|
|||||||
// db/queries.ts
|
// db/queries.ts
|
||||||
import { accounts } from '../schema/Account'
|
import { Account } from '../schema/Account'
|
||||||
import { db } from '../index';
|
import { db } from '../index';
|
||||||
|
|
||||||
// Fetch all accounts
|
// Fetch all account
|
||||||
export async function getAllAccounts() {
|
export async function getAllAccounts() {
|
||||||
return await db.select().from(accounts);
|
return await db.select().from(Account);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add a new accounts
|
// Add a new account
|
||||||
export async function addAcounts(name: string) {
|
export async function addAcount(first_name: string, last_name : string, username : string, password_hash: string ) {
|
||||||
return await db.insertInto(accounts).values({ name }).returning();
|
return await db.insert(Account).values({ first_name, last_name, username, password_hash }).returning();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update a accounts
|
// Update a account
|
||||||
export async function updateAcounts(id: number, name: string) {
|
export async function updateAcount(id: number, first_name: string, last_name : string, username : string, password_hash: string ) {
|
||||||
return await db.update(accounts).set({ name }).where(accounts.id.equals(id));
|
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) {
|
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));
|
||||||
}
|
}
|
||||||
@@ -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(),
|
|
||||||
});
|
|
||||||
@@ -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 "./columns.helpers";
|
import { timestamps } from "./helpers/columns.helpers";
|
||||||
|
|
||||||
export const Account = pgTable("bal_accounts", {
|
export const Account = pgTable("bal_accounts", {
|
||||||
id: integer().primaryKey().generatedAlwaysAsIdentity({ name: "accounts_id_seq", startWith: 1, increment: 1, minValue: 1, maxValue: 2147483647, cache: 1 }),
|
id: integer().primaryKey().generatedAlwaysAsIdentity({ name: "accounts_id_seq", startWith: 1, increment: 1, minValue: 1, maxValue: 2147483647, cache: 1 }),
|
||||||
|
|||||||
11
src/db/schema/Build.ts
Normal file
11
src/db/schema/Build.ts
Normal file
@@ -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
|
||||||
|
})
|
||||||
10
src/db/schema/BuildComponent.ts
Normal file
10
src/db/schema/BuildComponent.ts
Normal file
@@ -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
|
||||||
|
})
|
||||||
@@ -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 "./columns.helpers";
|
import { timestamps } from "./helpers/columns.helpers";
|
||||||
|
|
||||||
export const Category = pgTable("categories", {
|
export const Category = pgTable("categories", {
|
||||||
id: integer().primaryKey().generatedAlwaysAsIdentity({ name: "categories_id_seq", startWith: 1, increment: 1, minValue: 1, maxValue: 2147483647, cache: 1 }),
|
id: integer().primaryKey().generatedAlwaysAsIdentity({ name: "categories_id_seq", startWith: 1, increment: 1, minValue: 1, maxValue: 2147483647, cache: 1 }),
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { pgTable, integer, varchar, text, doublePrecision, timestamp } from "drizzle-orm/pg-core"
|
import { pgTable, integer, varchar, text, doublePrecision, timestamp } from "drizzle-orm/pg-core"
|
||||||
import { sql } from "drizzle-orm"
|
import { sql } from "drizzle-orm"
|
||||||
import { timestamps } from "./columns.helpers";
|
import { timestamps } from "./helpers/columns.helpers";
|
||||||
|
|
||||||
|
|
||||||
export const LipseyCatalog = pgTable("lipseycatalog", {
|
export const LipseyCatalog = pgTable("lipseycatalog", {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { pgTable, integer, varchar, text, decimal } from "drizzle-orm/pg-core";
|
import { pgTable, integer, varchar, text, decimal } from "drizzle-orm/pg-core";
|
||||||
import { sql } from "drizzle-orm";
|
import { sql } from "drizzle-orm";
|
||||||
import { timestamps } from "./columns.helpers";
|
import { timestamps } from "./helpers/columns.helpers";
|
||||||
|
|
||||||
export const Product = pgTable("products", {
|
export const Product = pgTable("products", {
|
||||||
id: integer().primaryKey().generatedAlwaysAsIdentity({ name: "products_id_seq", startWith: 1, increment: 1, minValue: 1, maxValue: 2147483647, cache: 1 }),
|
id: integer().primaryKey().generatedAlwaysAsIdentity({ name: "products_id_seq", startWith: 1, increment: 1, minValue: 1, maxValue: 2147483647, cache: 1 }),
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { pgTable, integer, varchar, timestamp } from "drizzle-orm/pg-core";
|
import { pgTable, integer, varchar, timestamp } from "drizzle-orm/pg-core";
|
||||||
import { sql } from "drizzle-orm";
|
import { sql } from "drizzle-orm";
|
||||||
import { timestamps } from "./columns.helpers";
|
import { timestamps } from "./helpers/columns.helpers";
|
||||||
|
|
||||||
export const Product_feed = pgTable("product_feeds", {
|
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 }),
|
id: integer().primaryKey().generatedAlwaysAsIdentity({ name: "productfeeds_id_seq", startWith: 1, increment: 1, minValue: 1, maxValue: 2147483647, cache: 1 }),
|
||||||
|
|||||||
@@ -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 "./columns.helpers";
|
import { timestamps } from "./helpers/columns.helpers";
|
||||||
|
|
||||||
export const Reseller = pgTable("bal_resellers", {
|
export const Reseller = pgTable("bal_resellers", {
|
||||||
id: integer().primaryKey().generatedAlwaysAsIdentity({ name: "resellers_id_seq", startWith: 1, increment: 1, minValue: 1, maxValue: 2147483647, cache: 1 }),
|
id: integer().primaryKey().generatedAlwaysAsIdentity({ name: "resellers_id_seq", startWith: 1, increment: 1, minValue: 1, maxValue: 2147483647, cache: 1 }),
|
||||||
|
|||||||
@@ -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 "./columns.helpers";
|
import { timestamps } from "./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 }),
|
||||||
|
|||||||
Reference in New Issue
Block a user