use caqti infix
This commit is contained in:
parent
d57c359b1f
commit
6b5bfcd144
5 changed files with 102 additions and 121 deletions
|
|
@ -41,163 +41,155 @@ type t =
|
|||
| Post of post
|
||||
|
||||
module Q = struct
|
||||
open Caqti_request.Infix
|
||||
|
||||
let create_post_user_table =
|
||||
Caqti_request.exec Caqti_type.unit
|
||||
(Caqti_type.unit ->. Caqti_type.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_request.exec Caqti_type.unit
|
||||
(Caqti_type.unit ->. Caqti_type.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_request.exec Caqti_type.unit
|
||||
(Caqti_type.unit ->. Caqti_type.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_request.exec Caqti_type.unit
|
||||
(Caqti_type.unit ->. Caqti_type.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_request.exec Caqti_type.unit
|
||||
(Caqti_type.unit ->. Caqti_type.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_request.exec Caqti_type.unit
|
||||
(Caqti_type.unit ->. Caqti_type.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_request.exec Caqti_type.unit
|
||||
(Caqti_type.unit ->. Caqti_type.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_request.exec Caqti_type.unit
|
||||
(Caqti_type.unit ->. Caqti_type.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_request.exec Caqti_type.unit
|
||||
(Caqti_type.unit ->. Caqti_type.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_request.exec
|
||||
Caqti_type.(tup4 string string float string)
|
||||
(Caqti_type.(tup4 string string float string) ->. Caqti_type.unit)
|
||||
"INSERT INTO report VALUES (?,?,?,?);"
|
||||
|
||||
let ignore_report =
|
||||
Caqti_request.exec Caqti_type.string "DELETE FROM report WHERE post_id=?;"
|
||||
(Caqti_type.string ->. Caqti_type.unit)
|
||||
"DELETE FROM report WHERE post_id=?;"
|
||||
|
||||
let get_reports =
|
||||
Caqti_request.collect Caqti_type.unit
|
||||
Caqti_type.(tup4 string string float string)
|
||||
(Caqti_type.unit ->* Caqti_type.(tup4 string string float string))
|
||||
"SELECT * FROM report;"
|
||||
|
||||
let upload_post_id =
|
||||
Caqti_request.exec
|
||||
Caqti_type.(tup2 string string)
|
||||
(Caqti_type.(tup2 string string) ->. Caqti_type.unit)
|
||||
"INSERT INTO post_user VALUES (?,?);"
|
||||
|
||||
let upload_thread_info =
|
||||
Caqti_request.exec
|
||||
Caqti_type.(tup4 string string float float)
|
||||
(Caqti_type.(tup4 string string float float) ->. Caqti_type.unit)
|
||||
"INSERT INTO thread_info VALUES (?,?,?,?);"
|
||||
|
||||
let upload_thread_post =
|
||||
Caqti_request.exec
|
||||
Caqti_type.(tup2 string string)
|
||||
(Caqti_type.(tup2 string string) ->. Caqti_type.unit)
|
||||
"INSERT INTO thread_post VALUES (?,?);"
|
||||
|
||||
let upload_post_reply =
|
||||
Caqti_request.exec
|
||||
Caqti_type.(tup2 string string)
|
||||
(Caqti_type.(tup2 string string) ->. Caqti_type.unit)
|
||||
"INSERT INTO post_replies VALUES (?,?);"
|
||||
|
||||
let upload_post_comment =
|
||||
Caqti_request.exec
|
||||
Caqti_type.(tup2 string string)
|
||||
(Caqti_type.(tup2 string string) ->. Caqti_type.unit)
|
||||
"INSERT INTO post_comment VALUES (?,?);"
|
||||
|
||||
let upload_post_tag =
|
||||
Caqti_request.exec
|
||||
Caqti_type.(tup2 string string)
|
||||
(Caqti_type.(tup2 string string) ->. Caqti_type.unit)
|
||||
"INSERT INTO post_tags VALUES (?,?);"
|
||||
|
||||
let upload_post_date =
|
||||
Caqti_request.exec
|
||||
Caqti_type.(tup2 string float)
|
||||
(Caqti_type.(tup2 string float) ->. Caqti_type.unit)
|
||||
"INSERT INTO post_date VALUES (?,?);"
|
||||
|
||||
let get_post_user_id =
|
||||
Caqti_request.find Caqti_type.string Caqti_type.string
|
||||
(Caqti_type.string ->! Caqti_type.string)
|
||||
"SELECT user_id FROM post_user WHERE post_id=?;"
|
||||
|
||||
let get_post_comment =
|
||||
Caqti_request.find Caqti_type.string Caqti_type.string
|
||||
(Caqti_type.string ->! Caqti_type.string)
|
||||
"SELECT comment FROM post_comment WHERE post_id=?;"
|
||||
|
||||
let get_post_tags =
|
||||
Caqti_request.collect Caqti_type.string Caqti_type.string
|
||||
(Caqti_type.string ->* Caqti_type.string)
|
||||
"SELECT tag FROM post_tags WHERE post_id=?;"
|
||||
|
||||
let get_post_date =
|
||||
Caqti_request.find Caqti_type.string Caqti_type.float
|
||||
(Caqti_type.string ->! Caqti_type.float)
|
||||
"SELECT date FROM post_date WHERE post_id=?;"
|
||||
|
||||
let get_post_citations =
|
||||
Caqti_request.collect Caqti_type.string Caqti_type.string
|
||||
(Caqti_type.string ->* Caqti_type.string)
|
||||
"SELECT post_id FROM post_citations WHERE post_id=?;"
|
||||
|
||||
let get_post_replies =
|
||||
Caqti_request.collect Caqti_type.string Caqti_type.string
|
||||
(Caqti_type.string ->* Caqti_type.string)
|
||||
"SELECT reply_id FROM post_replies WHERE post_id=?;"
|
||||
|
||||
let get_thread_posts =
|
||||
Caqti_request.collect Caqti_type.string Caqti_type.string
|
||||
(Caqti_type.string ->* Caqti_type.string)
|
||||
"SELECT post_id FROM thread_post WHERE thread_id=?;"
|
||||
|
||||
let count_thread_posts =
|
||||
Caqti_request.find Caqti_type.string Caqti_type.int
|
||||
(Caqti_type.string ->! Caqti_type.int)
|
||||
"SELECT COUNT(post_id) FROM thread_post WHERE thread_id=?;"
|
||||
|
||||
let get_is_thread =
|
||||
Caqti_request.find Caqti_type.string Caqti_type.string
|
||||
(Caqti_type.string ->! Caqti_type.string)
|
||||
"SELECT thread_id FROM thread_info WHERE thread_id=? LIMIT 1;"
|
||||
|
||||
let get_is_post =
|
||||
Caqti_request.find Caqti_type.string Caqti_type.string
|
||||
(Caqti_type.string ->! Caqti_type.string)
|
||||
"SELECT post_id FROM post_user WHERE post_id=? LIMIT 1;"
|
||||
|
||||
let get_post_thread =
|
||||
Caqti_request.find Caqti_type.string Caqti_type.string
|
||||
(Caqti_type.string ->! Caqti_type.string)
|
||||
"SELECT thread_id FROM thread_post WHERE post_id=? LIMIT 1;"
|
||||
|
||||
let get_thread_info =
|
||||
Caqti_request.find Caqti_type.string
|
||||
Caqti_type.(tup3 string float float)
|
||||
(Caqti_type.string ->! Caqti_type.(tup3 string float float))
|
||||
"SELECT subject,lat,lng FROM thread_info WHERE thread_id=?;"
|
||||
|
||||
let get_threads =
|
||||
Caqti_request.collect Caqti_type.unit Caqti_type.string
|
||||
"SELECT thread_id FROM thread_info;"
|
||||
(Caqti_type.unit ->* Caqti_type.string) "SELECT thread_id FROM thread_info;"
|
||||
|
||||
let delete_post =
|
||||
Caqti_request.exec Caqti_type.string
|
||||
(Caqti_type.string ->. Caqti_type.unit)
|
||||
"DELETE FROM post_user WHERE post_id=?;"
|
||||
end
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue