feat(repos): tags, polymorphic entity_links, attachments
This commit is contained in:
27
lib/db/repos/attachments.js
Normal file
27
lib/db/repos/attachments.js
Normal file
@@ -0,0 +1,27 @@
|
||||
import { pool } from '../pool.js';
|
||||
|
||||
export async function create({ entity_type, entity_id, filename, mime_type, size_bytes, blob_path, checksum }) {
|
||||
const { rows: [r] } = await pool.query(
|
||||
`INSERT INTO attachments(entity_type, entity_id, filename, mime_type, size_bytes, blob_path, checksum)
|
||||
VALUES($1,$2,$3,$4,$5,$6,$7) RETURNING *`,
|
||||
[entity_type, entity_id, filename, mime_type || null, size_bytes || null, blob_path, checksum || null]
|
||||
);
|
||||
return r;
|
||||
}
|
||||
|
||||
export async function listForEntity(entity_type, entity_id) {
|
||||
const { rows } = await pool.query(
|
||||
`SELECT * FROM attachments WHERE entity_type=$1 AND entity_id=$2 ORDER BY uploaded_at DESC`,
|
||||
[entity_type, entity_id]
|
||||
);
|
||||
return rows;
|
||||
}
|
||||
|
||||
export async function getById(id) {
|
||||
const { rows: [r] } = await pool.query(`SELECT * FROM attachments WHERE id=$1`, [id]);
|
||||
return r;
|
||||
}
|
||||
|
||||
export async function del(id) {
|
||||
await pool.query(`DELETE FROM attachments WHERE id=$1`, [id]);
|
||||
}
|
||||
Reference in New Issue
Block a user