feat(repos): tags, polymorphic entity_links, attachments
This commit is contained in:
33
lib/db/repos/links.js
Normal file
33
lib/db/repos/links.js
Normal 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]);
|
||||
}
|
||||
Reference in New Issue
Block a user