feat: add topic hierarchy APIs

This commit is contained in:
2026-05-11 11:46:10 +09:00
parent d95ac8c1a0
commit ba03ecb85b
9 changed files with 223 additions and 2 deletions

View File

@@ -53,3 +53,31 @@ export async function findConnectedTopicRows(
.orderBy('topics.normalized_name', 'asc')
.execute() as Promise<ConnectedTopicRow[]>;
}
export async function findChildTopicRows(
executor: DatabaseExecutor,
parentTopicId: string,
): Promise<TopicRecord[]> {
return executor
.selectFrom('topic_relations')
.innerJoin('topics', 'topics.id', 'topic_relations.child_topic_id')
.selectAll('topics')
.where('topic_relations.parent_topic_id', '=', parentTopicId)
.where('topic_relations.relation', '=', 'parent_of')
.orderBy('topics.normalized_name', 'asc')
.execute();
}
export async function findParentTopicRows(
executor: DatabaseExecutor,
childTopicId: string,
): Promise<TopicRecord[]> {
return executor
.selectFrom('topic_relations')
.innerJoin('topics', 'topics.id', 'topic_relations.parent_topic_id')
.selectAll('topics')
.where('topic_relations.child_topic_id', '=', childTopicId)
.where('topic_relations.relation', '=', 'parent_of')
.orderBy('topics.normalized_name', 'asc')
.execute();
}