diff options
Diffstat (limited to 'litedb/query.ml')
-rw-r--r-- | litedb/query.ml | 45 |
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"); *) |