package granary

  1. Overview
  2. Docs
Pure-OCaml SQL engine

Install

dune-project
 Dependency

Authors

Maintainers

Sources

0.0.3.tar.gz
sha256=8b18780ea373be48301d9f333925860a2f9110fc0ac28684295118d72b65a67e
sha512=25ca3c9c5e2b528704a542502e0f37dc33ba003f65622d969b8c2b800778585f8ef0cf89b36e6679832e3993e8303aecddfc662742baf7044d6afe4a796b8f11

doc/src/granary.sample/mem_wal.ml.html

Source file mem_wal.ml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
type t = { mutable buf : Bytes.t }

let create ?(initial_size = 65536) () = { buf = Bytes.make initial_size '\x00' }
let size_bytes t = Int64.of_int (Bytes.length t.buf)
let pp fmt t = Format.fprintf fmt "Mem_wal { size = %Ld }" (size_bytes t)

let grow t need =
  let cur = Bytes.length t.buf in
  if need > cur
  then (
    let nb = Bytes.make (max need (cur * 2)) '\x00' in
    Bytes.blit t.buf 0 nb 0 cur;
    t.buf <- nb)
;;

let read_at t ~offset out =
  let off = Int64.to_int offset in
  let len = Cstruct.length out in
  grow t (off + len);
  Cstruct.blit_from_bytes t.buf off out 0 len;
  Lwt.return (Ok ())
;;

let write_at t ~offset src =
  let off = Int64.to_int offset in
  let len = Cstruct.length src in
  grow t (off + len);
  Cstruct.blit_to_bytes src 0 t.buf off len;
  Lwt.return (Ok ())
;;

let sync () = Lwt.return (Ok ())

[@@@ai_disclosure "ai-generated"]
[@@@ai_model "claude-opus-4-8"]
[@@@ai_provider "Anthropic"]