25 lines
565 B
JavaScript
25 lines
565 B
JavaScript
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);
|
|
}
|
|
}
|