Drizzle-ORM setup

This commit is contained in:
Justin xzHome
2025-07-06 18:13:37 +09:00
parent c1cfda32f8
commit 109da1bd33
10 changed files with 874 additions and 8 deletions

4
api/src/db/index.ts Normal file
View File

@@ -0,0 +1,4 @@
import { drizzle } from "drizzle-orm/mysql2";
// You can specify any property from the mysql2 connection options
export const db = drizzle({ connection: { uri: process.env.DATABASE_URL }});

View File

@@ -0,0 +1,9 @@
import { int, mysqlTable, text, bigint, varchar, double } from 'drizzle-orm/mysql-core';
export const productsTable = mysqlTable('products', {
id: int().autoincrement().primaryKey(),
name: varchar({ length: 255 }).notNull(),
description: text(),
image: varchar({ length: 255 }),
price: double().notNull(),
});

3
api/src/db/schema.ts Normal file
View File

@@ -0,0 +1,3 @@
import * as productsSchema from './productsSchema';
export default {...productsSchema};

View File

@@ -1,12 +1,16 @@
import express, {json} from 'express';
import express, {json, urlencoded} from 'express';
import productsRoutes from './routes/products/index'
const port = 3000;
const app = express();
app.use(json());
//this is where you put middleware
app.use(urlencoded({extended: false}));
app.use(json()); // you need to parse the req.body to use it.
app.get('/', (req, res) => {
res.send('Hello World! 123');
res.send('Hello World! 1234');
});
@@ -16,4 +20,4 @@ app.listen(port, () => {
console.log(`Example app listening on port ${port}`);
});
// comment test
// comment test