Skip to content

Commit

Permalink
refactor(workers): sql migrate
Browse files Browse the repository at this point in the history
  • Loading branch information
shaokeyibb authored and Enter-tainer committed Jul 18, 2024
1 parent 773571a commit d6252a9
Showing 1 changed file with 2 additions and 8 deletions.
10 changes: 2 additions & 8 deletions cloudflare-workers/src/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,12 @@ export async function postComment(env: Env, req: PostComment) {
export async function getComment(env: Env, req: GetComment): Promise<GetCommentRespBody> {
const db = env.DB;

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

if (!page) {
return [];
}

const comments = (
await db
.prepare(
'SELECT * FROM comments JOIN commenters ON comments.commenter_id = commenters.id JOIN offsets ON comments.offset_id = offsets.id WHERE offsets.page_id = ?',
'SELECT *, comments.id AS id FROM comments JOIN commenters ON comments.commenter_id = commenters.id JOIN offsets ON comments.offset_id = offsets.id JOIN pages ON offsets.page_id = pages.id WHERE pages.path = ?',
)
.bind(page.id)
.bind(req.path)
.all()
).results;

Expand Down

0 comments on commit d6252a9

Please sign in to comment.