Module Rowtype_sqlite.Pool

Connections made up front to one file and lent one at a time.

type t
val create : sw:Eio.Switch.t -> mono_clock:_ Eio.Time.Mono.t -> ?timeout:Mtime.Span.t -> ?size:int -> ?wait:Mtime.Span.t -> ?observe:observer -> string -> (t, [> Rowtype.error ]) Stdlib.result

size connections, 8 unless given and at least one, each as connect makes it, timeout and observe passed through; the first that cannot be made is the answer, and those made before it are closed. wait is how long a borrow waits for one, 5 s unless given. A database in memory, ":memory:" or "", is refused, since each connection would have one of its own: a pool is of a file. Readers alongside a writer want the file in WAL mode, pragma journal_mode = wal, which the file keeps.

type error = [
  1. | `Pool of [ `Busy | `Closed ]
]

What a borrow meets in the pool, a state of the pool's own.

val use : ?wait:Mtime.Span.t -> t -> (conn -> 'a) -> ('a, [> error ]) Stdlib.result

Borrow a connection, run f on it on the calling fiber, and give it back, even if f raises: `Pool `Busy if none came free within the wait, and `Pool `Closed at once if the pool is closed, or closes while the borrow waits. A connection is given back with no transaction open: one a borrower left open is rolled back, and one whose rollback fails is an error line on rowtype-sqlite, closed and made again.

type stats = {
  1. size : int;
    (*

    connections the pool keeps

    *)
  2. idle : int;
    (*

    of them, not borrowed

    *)
  3. waiting : int;
    (*

    borrows waiting for one

    *)
}
val stats : t -> stats

For a health endpoint.

val close : t -> unit

Close the idle connections now and each borrowed one as it is given back. A borrow waiting, and every one after, is `Pool `Closed.