Skip to content

Commit

Permalink
refactor: join sql
Browse files Browse the repository at this point in the history
  • Loading branch information
shaokeyibb committed Aug 23, 2024
1 parent 6688267 commit d767251
Showing 1 changed file with 1 addition and 7 deletions.
8 changes: 1 addition & 7 deletions cloudflare-workers/src/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,13 +110,7 @@ export async function isPathExists(env: Env, ...path: string[]): Promise<boolean
export async function getOffsets(env: Env, path: string): Promise<Offset[]> {
const db = env.DB;

const page = await db.prepare('SELECT * FROM pages WHERE path = ?').bind(path).first();

if (!page) {
return [];
}

return (await db.prepare('SELECT * FROM offsets WHERE page_id = ?').bind(page.id).all()).results.map((offset) => ({
return (await db.prepare('SELECT * FROM offsets JOIN pages ON offsets.page_id = pages.id WHERE path = ?').bind(path).all()).results.map((offset) => ({
start: offset.start as number,
end: offset.end as number,
}));
Expand Down

0 comments on commit d767251

Please sign in to comment.