feat: add basic blog features
This commit is contained in:
24
controllers/Post.controller.js
Normal file
24
controllers/Post.controller.js
Normal file
@@ -0,0 +1,24 @@
|
||||
import client from "../db/index.js";
|
||||
|
||||
export default class PostController {
|
||||
static async getAll() {
|
||||
const res = await client.query("SELECT * FROM posts");
|
||||
return res.rows;
|
||||
}
|
||||
|
||||
static async get(id) {
|
||||
const res = await client.query({
|
||||
text: "SELECT * FROM posts WHERE id=$1",
|
||||
values: [id]
|
||||
});
|
||||
return res.rows[0];
|
||||
}
|
||||
|
||||
static async create(title, content) {
|
||||
const res = await client.query({
|
||||
text: "INSERT INTO posts(title, content) VALUES($1, $2)",
|
||||
values: [title, content]
|
||||
});
|
||||
console.log(res.rows);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user