Drizzle-ORM setup
This commit is contained in:
4
api/src/db/index.ts
Normal file
4
api/src/db/index.ts
Normal 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 }});
|
||||
9
api/src/db/productsSchema.ts
Normal file
9
api/src/db/productsSchema.ts
Normal 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
3
api/src/db/schema.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
import * as productsSchema from './productsSchema';
|
||||
|
||||
export default {...productsSchema};
|
||||
@@ -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
|
||||
Reference in New Issue
Block a user