open caqti_type; use Q module for discuss

This commit is contained in:
Swrup 2022-04-04 21:38:09 +02:00
parent 613d901bca
commit 0632a713c7
5 changed files with 115 additions and 162 deletions

View file

@ -10,81 +10,73 @@ type t =
module Q = struct
open Caqti_request.Infix
open Caqti_type
let create_info_table =
(Caqti_type.unit ->. Caqti_type.unit)
(unit ->. unit)
"CREATE TABLE IF NOT EXISTS image_info (post_id TEXT, image_name TEXT, \
image_alt TEXT, FOREIGN KEY(post_id) REFERENCES post_user(post_id) ON \
DELETE CASCADE)"
let create_content_table =
(Caqti_type.unit ->. Caqti_type.unit)
(unit ->. unit)
"CREATE TABLE IF NOT EXISTS image_content (post_id TEXT, content TEXT, \
FOREIGN KEY(post_id) REFERENCES post_user(post_id) ON DELETE CASCADE)"
let create_thumbnail_table =
(Caqti_type.unit ->. Caqti_type.unit)
(unit ->. unit)
"CREATE TABLE IF NOT EXISTS image_thumbnail (post_id TEXT, content TEXT, \
FOREIGN KEY(post_id) REFERENCES post_user(post_id) ON DELETE CASCADE)"
let upload_info =
(Caqti_type.(tup3 string string string) ->. Caqti_type.unit)
"INSERT INTO image_info VALUES (?,?,?)"
(tup3 string string string ->. unit) "INSERT INTO image_info VALUES (?,?,?)"
let upload_content =
(Caqti_type.(tup2 string string) ->. Caqti_type.unit)
"INSERT INTO image_content VALUES (?,?)"
(tup2 string string ->. unit) "INSERT INTO image_content VALUES (?,?)"
let upload_thumbnail =
(Caqti_type.(tup2 string string) ->. Caqti_type.unit)
"INSERT INTO image_thumbnail VALUES (?,?)"
(tup2 string string ->. unit) "INSERT INTO image_thumbnail VALUES (?,?)"
let get_post_content =
(Caqti_type.string ->? Caqti_type.string)
"SELECT content FROM image_content WHERE post_id=?"
(string ->? string) "SELECT content FROM image_content WHERE post_id=?"
let get_post_thumbnail =
(Caqti_type.string ->? Caqti_type.string)
"SELECT content FROM image_thumbnail WHERE post_id=?"
(string ->? string) "SELECT content FROM image_thumbnail WHERE post_id=?"
let get_post_info =
(Caqti_type.string ->? Caqti_type.(tup2 string string))
(string ->? tup2 string string)
"SELECT image_name,image_alt FROM image_info WHERE post_id=?"
(*avatars*)
let create_user_content_table =
(Caqti_type.unit ->. Caqti_type.unit)
(unit ->. unit)
"CREATE TABLE IF NOT EXISTS user_image_content (user_id TEXT, content \
TEXT, FOREIGN KEY(user_id) REFERENCES user(user_id) ON DELETE CASCADE)"
let create_user_thumbnail_table =
(Caqti_type.unit ->. Caqti_type.unit)
(unit ->. unit)
"CREATE TABLE IF NOT EXISTS user_image_thumbnail (user_id TEXT, content \
TEXT, FOREIGN KEY(user_id) REFERENCES user(user_id) ON DELETE CASCADE)"
let upload_user_content =
(Caqti_type.(tup2 string string) ->. Caqti_type.unit)
"INSERT INTO user_image_content VALUES (?,?)"
(tup2 string string ->. unit) "INSERT INTO user_image_content VALUES (?,?)"
let upload_user_thumbnail =
(Caqti_type.(tup2 string string) ->. Caqti_type.unit)
(tup2 string string ->. unit)
"INSERT INTO user_image_thumbnail VALUES (?,?)"
let get_user_content =
(Caqti_type.string ->? Caqti_type.string)
"SELECT content FROM user_image_content WHERE user_id=?"
(string ->? string) "SELECT content FROM user_image_content WHERE user_id=?"
let get_user_thumbnail =
(Caqti_type.string ->? Caqti_type.string)
(string ->? string)
"SELECT content FROM user_image_thumbnail WHERE user_id=?"
let delete_user_content =
(Caqti_type.string ->. Caqti_type.unit)
"DELETE FROM user_image_content WHERE user_id=?"
(string ->. unit) "DELETE FROM user_image_content WHERE user_id=?"
let delete_user_thumbnail =
(Caqti_type.string ->. Caqti_type.unit)
"DELETE FROM user_image_thumbnail WHERE user_id=?"
(string ->. unit) "DELETE FROM user_image_thumbnail WHERE user_id=?"
end
let () =