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

33
lib/db/repos/links.js Normal file
View File

@@ -0,0 +1,33 @@
import { pool } from '../pool.js';
export async function create(from_type, from_id, to_type, to_id, relation = 'attached') {
const { rows: [r] } = await pool.query(
`INSERT INTO entity_links(from_type, from_id, to_type, to_id, relation)
VALUES($1,$2,$3,$4,$5)
ON CONFLICT (from_type, from_id, to_type, to_id, relation)
DO UPDATE SET relation=EXCLUDED.relation
RETURNING *`,
[from_type, from_id, to_type, to_id, relation]
);
return r;
}
export async function listFrom(from_type, from_id) {
const { rows } = await pool.query(
`SELECT * FROM entity_links WHERE from_type=$1 AND from_id=$2`,
[from_type, from_id]
);
return rows;
}
export async function listTo(to_type, to_id) {
const { rows } = await pool.query(
`SELECT * FROM entity_links WHERE to_type=$1 AND to_id=$2`,
[to_type, to_id]
);
return rows;
}
export async function remove(id) {
await pool.query(`DELETE FROM entity_links WHERE id=$1`, [id]);
}