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_full to obtain the full Driver.S interface. The raw driver is responsible for connection management, placeholder syntax, parameter binding, row construction, transaction control, 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 exec_result_raw conn sql ~params = ...
    let query_raw conn sql ~params = ...
    let begin_transaction conn = ...
    let commit conn = ...
    let rollback conn = ...
    let placeholder i = "?"
    let returning_supported = false
    let upsert_syntax = `Standard
    let last_insert_id conn = ...
  end

  module Driver = Repodb.Driver_common.Make_full (Raw)

transaction commits when the callback returns Ok, and rolls back both when it returns Error and when it raises. Transaction control goes through the raw driver's begin_transaction, commit, and rollback rather than through the statement path, because MySQL 8 rejects a prepared BEGIN with error 1295 and because backends may hold row locks per native transaction.

Make remains available for raw drivers written against the original signature. It drives transactions with plain BEGIN/COMMIT/ROLLBACK statements and reports exec_result as unsupported; new backends should implement RAW_DRIVER_FULL instead.

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