123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165typedatabase=|MariaDb|PostgreSql(* Signature *)letname="database"exceptionExceptionofstringmoduletypeSig=sig(** ['a prepared_search_request] is a prepared SQL statement that can be used
to sort, filter and paginate (= search) a collection. *)type'aprepared_search_requestvalprepare_requests:string->string->string->string(* Deprecated in 0.6.0 *)[@@deprecated"Use prepare_search_request instead"](** [prepare_search_request ~search_query ~count_query ~filter_fragment
?sort_by_field type]
returns a prepared SQL statement ['a prepared_search_request] by
assembling the SQL query from the provided fragments.
[search_query] is the [SELECT ... FROM table] part of the query.
[count_query] is a query that is executed by Sihl after the search in
order to obtain the total number of items in the table. For example
[SELECT COUNT(\*\) FROM table].
[filter_fragment] is the fragment that is appended to [search_query] for
filtering. Usually you want ot [OR] fields that are often searched for.
For example
[WHERE table.field1 LIKE $1 OR table.field2 $1 OR table.field3 LIKE $1].
[sort_by_field] is an optional field name that is used for sorting. By
default, the field "id" is used. Note that in order to prepare the
requests, the sort field has to be known beforehand. If you want to
dynamically set the field, you need to write your own query at runtime.
[format_filter] is a function applied to the filter keyword before it is
passed to the database. By default, a keyword "keyword" is formatted to
"%skeyword%s". This might not be what you want performance-wise. If you
need full control, pass in the identity function and format the keyword
yourself.
[type] is the caqti type of an item of the collection. *)valprepare_search_request:search_query:string->filter_fragment:string->?sort_by_field:string->?format_filter:(string->string)->'aCaqti_type.t->'aprepared_search_requestvalrun_request:(moduleCaqti_lwt.CONNECTION)->'aprepared_search_request->[<`Asc|`Desc]->'coption->'a->('blist*int)Lwt.t(* Deprecated in 0.6.0 *)[@@deprecated"Use run_search_request instead"](** [run_search_request prepared_request sort filter ~limit ~offset] runs the
[prepared_request] and returns a partial result of the whole stored
collection. The second element of the result tuple is the total amount of
items in the whole collection.
[prepared_request] is the returned prepared request by
{!prepare_search_request}.
[sort] is the sort order. The field that is sorted by was set by
{!prepare_search_request}.
[filter] is an optional keyword that is used to filter the collection. If
no filter is provided, the collection is not filtered.
[offset] is the number of items that the returned partial result is offset
by.
[limit] is the number of items of the returned partial result.
[offset] and [limit] can be used together to implement pagination. *)valrun_search_request:'aprepared_search_request->[`Asc|`Desc]->stringoption->limit:int->offset:int->('alist*int)Lwt.t(** [raise_error err] raises a printable caqti error [err] .*)valraise_error:('a,Caqti_error.t)Result.t->'a(** [fetch_pool ()] returns the connection pool that was set up. If there was
no connection pool set up, setting it up now. *)valfetch_pool:unit->(Caqti_lwt.connection,Caqti_error.t)Caqti_lwt.Pool.t(** [find_opt request input] runs a caqti [request] in the connection pool
where [input] is the input of the caqti request and returns one row or
[None]. Returns [None] if no rows are found.
Note that the caqti request is only allowed to return one or zero rows,
not many. *)valfind_opt:('a,'b,[<`One|`Zero])Caqti_request.t->'a->'boptionLwt.t(** [find request input] runs a caqti [request] on the connection pool where
[input] is the input of the caqti request and returns one row. Raises an
exception if no row was found.
Note that the caqti request is only allowed to return one or zero rows,
not many. *)valfind:('a,'b,[<`One])Caqti_request.t->'a->'bLwt.t(** [collect request input] runs a caqti [request] on the connection pool
where [input] is the input of the caqti request and retuns a list of rows.
Note that the caqti request is allowed to return one, zero or many rows. *)valcollect:('a,'b,[<`One|`Zero|`Many])Caqti_request.t->'a->'blistLwt.t(** [exec request input] runs a caqti [request] on the connection pool.
Note that the caqti request is not allowed to return any rows.
Use {!exec} to run mutations. *)valexec:('b,unit,[<`Zero])Caqti_request.t->'b->unitLwt.t(** [query f] runs the query [f] on the connection pool and returns the
result. If the query fails the Lwt.t fails as well. *)valquery:(Caqti_lwt.connection->'aLwt.t)->'aLwt.t(** [query' f] runs the query [f] on the connection pool and returns the
result. Use [query'] instead of {!query} as a shorthand when you have a
single caqti request to execute. *)valquery':(Caqti_lwt.connection->('a,Caqti_error.t)Result.tLwt.t)->'aLwt.t(** [transaction f] runs the query [f] on the connection pool in a transaction
and returns the result. If the query fails the Lwt.t fails as well and the
transaction gets rolled back. If the database driver doesn't support
transactions, [transaction] gracefully becomes {!query}. *)valtransaction:(Caqti_lwt.connection->'aLwt.t)->'aLwt.t(** [transaction' f] runs the query [f] on the connection pool in a
transaction and returns the result. If the query fails the Lwt.t fails as
well and the transaction gets rolled back. If the database driver doesn't
support transactions, [transaction'] gracefully becomes {!query'}. *)valtransaction':(Caqti_lwt.connection->('a,Caqti_error.t)Result.tLwt.t)->'aLwt.tvalregister:unit->Core_container.Service.tincludeCore_container.Service.Sigend