Repodb.Driver_common.RAW_DRIVER

repodb · API reference

Helpers for implementing concrete database drivers.

Driver packages normally provide only a raw backend binding and then apply Make to obtain the full Driver.S interface. The raw driver is responsible for connection management, placeholder syntax, parameter binding, row construction, and dialect capability flags. The functor adds convenience operations such as query_one, query_fold, query_iter, with_connection, and the standard transaction wrapper.

A minimal backend has this shape:

module Raw = struct
    type connection = ...
    type error = string

    let dialect = Repodb.Driver.Other "example"
    let error_message e = e
    let error_of_string e = e
    let connect conninfo = ...
    let close conn = ...
    let exec_raw conn sql ~params = ...
    let query_raw conn sql ~params = ...
    let placeholder i = "?"
    let returning_supported = false
    let upsert_syntax = `Standard
    let last_insert_id conn = ...
  end

  module Driver = Repodb.Driver_common.Make (Raw)

transaction issues BEGIN, COMMIT, and ROLLBACK using exec_raw. If a backend needs savepoints, isolation levels, or non-standard transaction SQL, implement Driver.S directly instead of using this functor.

type connection
type error
val dialect : Driver.dialect
val error_message : error -> string
val error_of_string : string -> error
val connect : string -> (connection, error) result
val close : connection -> unit
val exec_raw : 
  connection ->
  string ->
  params:Driver.Value.t array ->
  (unit, error) result
val query_raw : 
  connection ->
  string ->
  params:Driver.Value.t array ->
  (Driver.row list, error) result
val placeholder : int -> string
val returning_supported : bool
val upsert_syntax : [ `PostgreSQL | `SQLite | `Standard ]
val last_insert_id : connection -> (int64, error) result