summaryrefslogtreecommitdiff
path: root/litedb/query.ml
diff options
context:
space:
mode:
authorpolwex <polwex@sortug.com>2025-06-23 06:02:52 +0700
committerpolwex <polwex@sortug.com>2025-06-23 06:02:52 +0700
commitf4459658a0cad4b7615c01af9c3f87fb4d0233e0 (patch)
treea5f2403e420154abd95dffdc6c45045c8530599a /litedb/query.ml
parentd653f488017b1904fb0089d2bf308ae042240f38 (diff)
working working
Diffstat (limited to 'litedb/query.ml')
-rw-r--r--litedb/query.ml45
1 files changed, 38 insertions, 7 deletions
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"); *)