open caqti_type; use Q module for discuss
This commit is contained in:
parent
613d901bca
commit
0632a713c7
5 changed files with 115 additions and 162 deletions
|
|
@ -42,154 +42,135 @@ type t =
|
|||
|
||||
module Q = struct
|
||||
open Caqti_request.Infix
|
||||
open Caqti_type
|
||||
|
||||
let create_post_user_table =
|
||||
(Caqti_type.unit ->. Caqti_type.unit)
|
||||
(unit ->. unit)
|
||||
"CREATE TABLE IF NOT EXISTS post_user (post_id TEXT, user_id TEXT, \
|
||||
PRIMARY KEY(post_id), FOREIGN KEY(user_id) REFERENCES user(user_id) ON \
|
||||
DELETE CASCADE)"
|
||||
|
||||
(* one row for each thread, with thread's data *)
|
||||
let create_thread_info_table =
|
||||
(Caqti_type.unit ->. Caqti_type.unit)
|
||||
(unit ->. unit)
|
||||
"CREATE TABLE IF NOT EXISTS thread_info (thread_id TEXT, subject TEXT, \
|
||||
lat FLOAT, lng FLOAT, FOREIGN KEY(thread_id) REFERENCES \
|
||||
post_user(post_id) ON DELETE CASCADE)"
|
||||
|
||||
(* map thread and reply to the thread *)
|
||||
let create_thread_post_table =
|
||||
(Caqti_type.unit ->. Caqti_type.unit)
|
||||
(unit ->. unit)
|
||||
"CREATE TABLE IF NOT EXISTS thread_post (thread_id TEXT, post_id TEXT, \
|
||||
FOREIGN KEY(thread_id) REFERENCES post_user(post_id) ON DELETE CASCADE, \
|
||||
FOREIGN KEY(post_id) REFERENCES post_user(post_id) ON DELETE CASCADE)"
|
||||
|
||||
let create_post_replies_table =
|
||||
(Caqti_type.unit ->. Caqti_type.unit)
|
||||
(unit ->. unit)
|
||||
"CREATE TABLE IF NOT EXISTS post_replies (post_id TEXT, reply_id TEXT, \
|
||||
FOREIGN KEY(post_id) REFERENCES post_user(post_id) ON DELETE CASCADE, \
|
||||
FOREIGN KEY(reply_id) REFERENCES post_user(post_id) ON DELETE CASCADE)"
|
||||
|
||||
let create_post_citations_table =
|
||||
(Caqti_type.unit ->. Caqti_type.unit)
|
||||
(unit ->. unit)
|
||||
"CREATE TABLE IF NOT EXISTS post_citations (post_id TEXT, cited_id TEXT, \
|
||||
FOREIGN KEY(post_id) REFERENCES post_user(post_id) ON DELETE CASCADE, \
|
||||
FOREIGN KEY(cited_id) REFERENCES post_user(post_id) ON DELETE CASCADE)"
|
||||
|
||||
let create_post_date_table =
|
||||
(Caqti_type.unit ->. Caqti_type.unit)
|
||||
(unit ->. unit)
|
||||
"CREATE TABLE IF NOT EXISTS post_date (post_id TEXT, date FLOAT, FOREIGN \
|
||||
KEY(post_id) REFERENCES post_user(post_id) ON DELETE CASCADE)"
|
||||
|
||||
let create_post_comment_table =
|
||||
(Caqti_type.unit ->. Caqti_type.unit)
|
||||
(unit ->. unit)
|
||||
"CREATE TABLE IF NOT EXISTS post_comment (post_id TEXT, comment TEXT, \
|
||||
FOREIGN KEY(post_id) REFERENCES post_user(post_id) ON DELETE CASCADE)"
|
||||
|
||||
let create_post_tags_table =
|
||||
(Caqti_type.unit ->. Caqti_type.unit)
|
||||
(unit ->. unit)
|
||||
"CREATE TABLE IF NOT EXISTS post_tags (post_id TEXT, tag TEXT, FOREIGN \
|
||||
KEY(post_id) REFERENCES post_user(post_id) ON DELETE CASCADE)"
|
||||
|
||||
let create_report_table =
|
||||
(Caqti_type.unit ->. Caqti_type.unit)
|
||||
(unit ->. unit)
|
||||
"CREATE TABLE IF NOT EXISTS report (user_id TEXT, reason TEXT, date \
|
||||
FLOAT,post_id TEXT, FOREIGN KEY(post_id) REFERENCES post_user(post_id) \
|
||||
ON DELETE CASCADE, FOREIGN KEY(user_id) REFERENCES user(user_id) ON \
|
||||
DELETE CASCADE)"
|
||||
|
||||
let upload_report =
|
||||
(Caqti_type.(tup4 string string float string) ->. Caqti_type.unit)
|
||||
(tup4 string string float string ->. unit)
|
||||
"INSERT INTO report VALUES (?,?,?,?)"
|
||||
|
||||
let ignore_report =
|
||||
(Caqti_type.string ->. Caqti_type.unit) "DELETE FROM report WHERE post_id=?"
|
||||
let ignore_report = (string ->. unit) "DELETE FROM report WHERE post_id=?"
|
||||
|
||||
let get_reports =
|
||||
(Caqti_type.unit ->* Caqti_type.(tup4 string string float string))
|
||||
"SELECT * FROM report"
|
||||
(unit ->* tup4 string string float string) "SELECT * FROM report"
|
||||
|
||||
let upload_post_id =
|
||||
(Caqti_type.(tup2 string string) ->. Caqti_type.unit)
|
||||
"INSERT INTO post_user VALUES (?,?)"
|
||||
(tup2 string string ->. unit) "INSERT INTO post_user VALUES (?,?)"
|
||||
|
||||
let upload_thread_info =
|
||||
(Caqti_type.(tup4 string string float float) ->. Caqti_type.unit)
|
||||
(tup4 string string float float ->. unit)
|
||||
"INSERT INTO thread_info VALUES (?,?,?,?)"
|
||||
|
||||
let upload_thread_post =
|
||||
(Caqti_type.(tup2 string string) ->. Caqti_type.unit)
|
||||
"INSERT INTO thread_post VALUES (?,?)"
|
||||
(tup2 string string ->. unit) "INSERT INTO thread_post VALUES (?,?)"
|
||||
|
||||
let upload_post_reply =
|
||||
(Caqti_type.(tup2 string string) ->. Caqti_type.unit)
|
||||
"INSERT INTO post_replies VALUES (?,?)"
|
||||
(tup2 string string ->. unit) "INSERT INTO post_replies VALUES (?,?)"
|
||||
|
||||
let upload_post_comment =
|
||||
(Caqti_type.(tup2 string string) ->. Caqti_type.unit)
|
||||
"INSERT INTO post_comment VALUES (?,?)"
|
||||
(tup2 string string ->. unit) "INSERT INTO post_comment VALUES (?,?)"
|
||||
|
||||
let upload_post_tag =
|
||||
(Caqti_type.(tup2 string string) ->. Caqti_type.unit)
|
||||
"INSERT INTO post_tags VALUES (?,?)"
|
||||
(tup2 string string ->. unit) "INSERT INTO post_tags VALUES (?,?)"
|
||||
|
||||
let upload_post_date =
|
||||
(Caqti_type.(tup2 string float) ->. Caqti_type.unit)
|
||||
"INSERT INTO post_date VALUES (?,?)"
|
||||
(tup2 string float ->. unit) "INSERT INTO post_date VALUES (?,?)"
|
||||
|
||||
let get_post_user_id =
|
||||
(Caqti_type.string ->! Caqti_type.string)
|
||||
"SELECT user_id FROM post_user WHERE post_id=?"
|
||||
(string ->! string) "SELECT user_id FROM post_user WHERE post_id=?"
|
||||
|
||||
let get_post_comment =
|
||||
(Caqti_type.string ->! Caqti_type.string)
|
||||
"SELECT comment FROM post_comment WHERE post_id=?"
|
||||
(string ->! string) "SELECT comment FROM post_comment WHERE post_id=?"
|
||||
|
||||
let get_post_tags =
|
||||
(Caqti_type.string ->* Caqti_type.string)
|
||||
"SELECT tag FROM post_tags WHERE post_id=?"
|
||||
(string ->* string) "SELECT tag FROM post_tags WHERE post_id=?"
|
||||
|
||||
let get_post_date =
|
||||
(Caqti_type.string ->! Caqti_type.float)
|
||||
"SELECT date FROM post_date WHERE post_id=?"
|
||||
(string ->! float) "SELECT date FROM post_date WHERE post_id=?"
|
||||
|
||||
let get_post_citations =
|
||||
(Caqti_type.string ->* Caqti_type.string)
|
||||
"SELECT post_id FROM post_citations WHERE post_id=?"
|
||||
(string ->* string) "SELECT post_id FROM post_citations WHERE post_id=?"
|
||||
|
||||
let get_post_replies =
|
||||
(Caqti_type.string ->* Caqti_type.string)
|
||||
"SELECT reply_id FROM post_replies WHERE post_id=?"
|
||||
(string ->* string) "SELECT reply_id FROM post_replies WHERE post_id=?"
|
||||
|
||||
let get_thread_posts =
|
||||
(Caqti_type.string ->* Caqti_type.string)
|
||||
"SELECT post_id FROM thread_post WHERE thread_id=?"
|
||||
(string ->* string) "SELECT post_id FROM thread_post WHERE thread_id=?"
|
||||
|
||||
let count_thread_posts =
|
||||
(Caqti_type.string ->! Caqti_type.int)
|
||||
"SELECT COUNT(post_id) FROM thread_post WHERE thread_id=?"
|
||||
(string ->! int) "SELECT COUNT(post_id) FROM thread_post WHERE thread_id=?"
|
||||
|
||||
let get_is_thread =
|
||||
(Caqti_type.string ->! Caqti_type.string)
|
||||
(string ->! string)
|
||||
"SELECT thread_id FROM thread_info WHERE thread_id=? LIMIT 1"
|
||||
|
||||
let get_is_post =
|
||||
(Caqti_type.string ->! Caqti_type.string)
|
||||
"SELECT post_id FROM post_user WHERE post_id=? LIMIT 1"
|
||||
(string ->! string) "SELECT post_id FROM post_user WHERE post_id=? LIMIT 1"
|
||||
|
||||
let get_post_thread =
|
||||
(Caqti_type.string ->! Caqti_type.string)
|
||||
(string ->! string)
|
||||
"SELECT thread_id FROM thread_post WHERE post_id=? LIMIT 1"
|
||||
|
||||
let get_thread_info =
|
||||
(Caqti_type.string ->! Caqti_type.(tup3 string float float))
|
||||
(string ->! tup3 string float float)
|
||||
"SELECT subject,lat,lng FROM thread_info WHERE thread_id=?"
|
||||
|
||||
let get_threads =
|
||||
(Caqti_type.unit ->* Caqti_type.string) "SELECT thread_id FROM thread_info"
|
||||
let get_threads = (unit ->* string) "SELECT thread_id FROM thread_info"
|
||||
|
||||
let delete_post =
|
||||
(Caqti_type.string ->. Caqti_type.unit)
|
||||
"DELETE FROM post_user WHERE post_id=?"
|
||||
let delete_post = (string ->. unit) "DELETE FROM post_user WHERE post_id=?"
|
||||
end
|
||||
|
||||
let () =
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue