feat(repos): tags, polymorphic entity_links, attachments

This commit is contained in:
root
2026-05-31 11:02:58 +10:00
parent 1b51c3c18d
commit 47ea0768fd
6 changed files with 190 additions and 0 deletions

View 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]);
}