summaryrefslogtreecommitdiff
path: root/litedb/query.ml
diff options
context:
space:
mode:
Diffstat (limited to 'litedb/query.ml')
-rw-r--r--litedb/query.ml71
1 files changed, 71 insertions, 0 deletions
diff --git a/litedb/query.ml b/litedb/query.ml
new file mode 100644
index 0000000..4929fdf
--- /dev/null
+++ b/litedb/query.ml
@@ -0,0 +1,71 @@
+module Query = struct
+ let poasts =
+ [%rapper
+ get_many
+ {sql|
+ SELECT @int{id}, @string{title}, @string{content}, @string{date}
+ FROM Posts
+ ORDER BY id DESC LIMIT 100
+ |sql}]
+ ;;
+
+ let poast =
+ [%rapper
+ get_opt
+ {sql|
+ SELECT @int{id}, @string{title}, @string{content}, @string{date}, @string{tags}, @string{url}
+ FROM Posts
+ WHERE id = %int{post_id}
+ |sql}]
+ ;;
+
+ let comment =
+ [%rapper
+ get_opt
+ {sql|
+ SELECT @int{id}, @string{content}, @string{date}, @string{tags}, @string{url}
+ FROM Comments
+ WHERE id = %int{id}
+ |sql}]
+ ;;
+
+ let user_comments =
+ [%rapper
+ get_opt
+ {sql|
+ SELECT @int{id}, @string{content}, @string{date}, @string{tags}, @string{url}
+ FROM Comments
+ WHERE author = %string{username}
+ |sql}]
+ ;;
+
+ let post_comments =
+ [%rapper
+ get_opt
+ {sql|
+ SELECT @int{id}, @string{content}, @string{date}, @string{tags}, @string{url}
+ FROM Comments
+ WHERE post_id = %int{post_id}
+ |sql}]
+ ;;
+
+ let comment_children =
+ [%rapper
+ get_opt
+ {sql|
+ SELECT @int{id}, @string{content}, @string{date}, @string{tags}, @string{url}
+ FROM Comments
+ WHERE parent= %int{post_id}
+ |sql}]
+ ;;
+end
+
+let get_poasts conn = Query.poast conn
+let get_poast post_id conn = Query.poast ~post_id conn
+
+(* db.exec("PRAGMA journal_mode = WAL"); *)
+(* db.exec("PRAGMA foreign_keys = ON"); *)
+(* db.exec("PRAGMA cache_size = -8000"); // 8MB cache *)
+(* db.exec("PRAGMA temp_store = MEMORY"); *)
+(* db.exec("PRAGMA synchronous = NORMAL"); *)
+(* db.exec("PRAGMA mmap_size = 30000000000"); // 30GB memory map *)