Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/db/repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,22 @@ export class Repository {
}
}

async getEntityById(id: string): Promise<Entity | null> {
try {
const results = await this.db.exec({
sql: `SELECT * FROM entities WHERE id = ?`,
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Template string can be replaced with regular string literal


Template literals are useful when you need: 1. Interpolated strings.

bind: [id],
returnValue: 'resultRows',
rowMode: 'object',
}) as Record<string, unknown>[];
if (results.length === 0) return null;
return this.parseMetadata<Entity>(results[0]);
} catch (err) {
logger.error('Failed to fetch entity by id', err);
throw new AppError('Failed to fetch entity by id', 'DB_ERROR', err);
}
}

async getEntityByName(name: string): Promise<Entity | null> {
try {
const results = await this.db.exec({
Expand Down
3 changes: 1 addition & 2 deletions src/lib/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,7 @@ export const upsertToSearchIndex = async (entityId: string) => {
try {
await removeFromSearchIndex(entityId);

const entities = await repository.getAllEntities();
const entity = entities.find(e => e.id === entityId);
const entity = await repository.getEntityById(entityId);

if (entity) {
const claims = await repository.getClaimsByEntityId(entity.id!);
Expand Down
Loading