Repodb.Repo
repodb · API reference
type 'a result = ('a, Error.db_error) resultRepository operations over a concrete database driver.
Repo.Make(D) turns a Driver.S implementation into high-level database functions: CRUD helpers, typed query execution, preloading, DDL helpers, and transactions. Applications normally define one repo module per backend:
module Repo = Repodb.Repo.Make (Repodb_sqlite.Driver)Decoding is explicit and local to the caller:
let decode_user row =
{ User.id = Driver.row_int64 row "id";
email = Driver.row_text row "email";
name = Driver.row_text row "name" }
let list_users conn =
Query.from User.table
|> Query.order_by Expr.(column User.email)
|> Repo.all_query conn ~decode:decode_userAll public operations return ('a, Error.db_error) result. Driver errors are normalized where Repodb can recognize them; for example, PostgreSQL and SQLite constraint failures become Error.db_error.Constraint_violation. Use validate_changeset before writes when accepting external input.
transaction conn f runs f on the same connection and commits only when f returns Ok _. For multi-step writes where later operations depend on earlier results, see Multi; for pooled access, combine a repo with Pool.Make or Cqrs.Make.
val parse_pg_constraint_error :
string ->
[> `ForeignKey of string | `Unique of string ] optionval parse_sqlite_constraint_error : String.t -> (string * string) optionval driver_error_to_db_error :
dialect:Driver.dialect ->
string ->
Error.db_errormodule IntMap : sig ... endmodule type REPO = sig ... endval validate_changeset : 'a Changeset.t -> ('a, Error.db_error) resultval build_insert_sql :
placeholder:(int -> string) ->
Schema.table ->
string list ->
stringval build_insert_returning_sql :
placeholder:(int -> string) ->
Schema.table ->
string list ->
stringval build_update_sql :
placeholder:(int -> string) ->
Schema.table ->
string list ->
where_column:string ->
stringval build_delete_sql :
placeholder:(int -> string) ->
Schema.table ->
where_column:string ->
stringval build_select_sql :
placeholder:(int -> string) ->
Schema.table ->
columns:string list ->
where_column:string ->
stringval build_select_all_sql : Schema.table -> columns:string list -> stringval build_preload_sql :
placeholder:(int -> string) ->
related_table:string ->
fk_column:string ->
n_ids:int ->
stringmodule Make (D : Driver.S) : sig ... end