From f4459658a0cad4b7615c01af9c3f87fb4d0233e0 Mon Sep 17 00:00:00 2001 From: polwex Date: Mon, 23 Jun 2025 06:02:52 +0700 Subject: working working --- litedb/query.ml | 45 ++++++++++++++++++++++++++++++++++++++------- 1 file changed, 38 insertions(+), 7 deletions(-) (limited to 'litedb/query.ml') diff --git a/litedb/query.ml b/litedb/query.ml index 4929fdf..536347c 100644 --- a/litedb/query.ml +++ b/litedb/query.ml @@ -1,3 +1,28 @@ +(* Define record types for the query outputs *) +type post_summary = { + id: int; + title: string; + content: string; + date: string; +} + +type post = { + id: int; + title: string; + content: string; + date: string; + tags: string; + url: string; +} + +type comment = { + id: int; + content: string; + date: string; + tags: string; + url: string; +} + module Query = struct let poasts = [%rapper @@ -6,7 +31,8 @@ module Query = struct SELECT @int{id}, @string{title}, @string{content}, @string{date} FROM Posts ORDER BY id DESC LIMIT 100 - |sql}] + |sql} + record_out] ;; let poast = @@ -16,7 +42,8 @@ module Query = struct SELECT @int{id}, @string{title}, @string{content}, @string{date}, @string{tags}, @string{url} FROM Posts WHERE id = %int{post_id} - |sql}] + |sql} + record_out] ;; let comment = @@ -26,7 +53,8 @@ module Query = struct SELECT @int{id}, @string{content}, @string{date}, @string{tags}, @string{url} FROM Comments WHERE id = %int{id} - |sql}] + |sql} + record_out] ;; let user_comments = @@ -36,7 +64,8 @@ module Query = struct SELECT @int{id}, @string{content}, @string{date}, @string{tags}, @string{url} FROM Comments WHERE author = %string{username} - |sql}] + |sql} + record_out] ;; let post_comments = @@ -46,7 +75,8 @@ module Query = struct SELECT @int{id}, @string{content}, @string{date}, @string{tags}, @string{url} FROM Comments WHERE post_id = %int{post_id} - |sql}] + |sql} + record_out] ;; let comment_children = @@ -56,11 +86,12 @@ module Query = struct SELECT @int{id}, @string{content}, @string{date}, @string{tags}, @string{url} FROM Comments WHERE parent= %int{post_id} - |sql}] + |sql} + record_out] ;; end -let get_poasts conn = Query.poast conn +let get_poasts conn = Query.poasts conn let get_poast post_id conn = Query.poast ~post_id conn (* db.exec("PRAGMA journal_mode = WAL"); *) -- cgit v1.2.3