Add MLI files

This commit is contained in:
2022-08-31 13:41:40 -06:00
parent 3ba3c77f0a
commit e36282150e
5 changed files with 94 additions and 2 deletions

1
#start.sh# Normal file
View File

@@ -0,0 +1 @@
#!/usr/bin

77
db/database.mli Normal file
View File

@@ -0,0 +1,77 @@
module BlogPost :
sig
type t = {
slug : string;
title : string;
content : string;
date : string;
}
end
module Q :
sig
val blog_post : BlogPost.t Caqti_type.t
val create_blog_post_table : (unit, unit, [ `Zero ]) Caqti_request.t
val create_blog_post :
(string * string * string * string, unit, [ `Zero ]) Caqti_request.t
val get_all_blog_posts :
(unit, BlogPost.t, [ `Many | `One | `Zero ]) Caqti_request.t
val get_all_blog_posts_for_display :
(unit, string * string, [ `Many | `One | `Zero ]) Caqti_request.t
val get_blog_post_by_slug :
(string, BlogPost.t, [ `One | `Zero ]) Caqti_request.t
val update_blog_post_content :
(string * string, unit, [ `Zero ]) Caqti_request.t
val update_blog_post_title :
(string * string, unit, [ `Zero ]) Caqti_request.t
val delete_blog_post : (string, unit, [ `Zero ]) Caqti_request.t
end
module Db : Caqti_lwt.CONNECTION
module Database :
sig
val create_blog_post_table :
unit -> (unit, [> Caqti_error.call_or_retrieve ]) Stdlib.result Lwt.t
val create_blog_post :
string ->
string ->
string ->
string -> (unit, [> Caqti_error.call_or_retrieve ]) Stdlib.result Lwt.t
val update_blog_post_content :
string ->
string -> (unit, [> Caqti_error.call_or_retrieve ]) Stdlib.result Lwt.t
val update_blog_post_title :
string ->
string -> (unit, [> Caqti_error.call_or_retrieve ]) Stdlib.result Lwt.t
val get_blog_post_by_slug :
string ->
(BlogPost.t option, [> Caqti_error.call_or_retrieve ]) Stdlib.result Lwt.t
val get_all_blog_posts :
unit ->
(BlogPost.t list, [> Caqti_error.call_or_retrieve ]) Stdlib.result Lwt.t
val iter_blog_posts :
(BlogPost.t ->
(unit, [> Caqti_error.call_or_retrieve ] as 'a) Stdlib.result Lwt.t) ->
(unit, 'a) Stdlib.result Lwt.t
val ( >>=? ) :
('a, 'b) Stdlib.result Lwt.t ->
('a -> ('c, 'b) Stdlib.result Lwt.t) -> ('c, 'b) Stdlib.result Lwt.t
val report_error : (unit, [< Caqti_error.t ]) Stdlib.result -> unit Lwt.t
end

View File

@@ -6,7 +6,7 @@ exception DatabaseCreationFailure
let _ =
Database.create_blog_post_table () >>= function
| Ok () -> Lwt_io.print "Database was initialized successfully\n"
| Ok () -> Lwt_io.print "Database initialized successfully.\n"
| Error _ -> raise DatabaseCreationFailure
let () =

View File

@@ -93,7 +93,7 @@ module Render = struct
|> render_page
|> Dream.html
let render_blog_index _ =
let render_blog_index (_ : Dream.request) =
let buff = Buffer.create 512 in
let () = Buffer.add_string buff "<h3>Blog</h3>" in
let posts_t = Database.get_all_blog_posts () in

14
render/render.mli Normal file
View File

@@ -0,0 +1,14 @@
open Database
module Render :
sig
val not_found_template : string
val error_template : string
val header_template : string
val footer_template : string
val render_page : string -> string
val generate_link : BlogPost.t -> string
val handle_error : [< Caqti_error.t ] -> Dream.response Lwt.t
val render_blog_post : Dream.request -> Dream.response Lwt.t
val render_blog_index : Dream.request -> Dream.response Lwt.t
end