package granary

  1. Overview
  2. Docs
Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source

Module Granary_encoding.RowSource

Row schema and value (de)serialisation.

Defines column types (ty), DEFAULT/CHECK/GENERATED column metadata (column, schema) and the runtime cell values of a row (t), plus the binary encode/decode of a row against its schema.

Sourcetype ty =
  1. | Integer
  2. | Text
  3. | Real
  4. | Blob
Sourcetype default_value =
  1. | DV_int of int64
  2. | DV_text of string
  3. | DV_null
  4. | DV_real of float
  5. | DV_blob of bytes
  6. | DV_current_timestamp
  7. | DV_current_date
  8. | DV_current_time
Sourcetype column = {
  1. name : string;
  2. ty : ty;
  3. not_null : bool;
  4. primary_key : bool;
  5. pk_desc : bool;
    (*

    #312: this PK column was declared PRIMARY KEY DESC. A single-column INTEGER PK with pk_desc = true is a NON-alias (hidden rowid + implicit __pk unique index), matching SQLite. Only meaningful when primary_key is set.

    *)
  6. default : default_value option;
  7. check_sql : string option;
  8. generated_as : (string * bool) option;
    (*

    Some (expr_sql, is_stored): GENERATED ALWAYS AS expr. is_stored=true => STORED; false => VIRTUAL (both computed at write time).

    *)
}
Sourcetype schema = column list
Sourcetype value =
  1. | V_int of int64
  2. | V_text of string
  3. | V_null
  4. | V_real of float
  5. | V_blob of bytes
Sourcetype t = value array
Sourceval equal : t -> t -> bool

Structural equality of two rows.

Sourceval encode : schema -> t -> bytes

encode schema row serialises row to its on-disk byte representation according to schema.

Sourceval decode : schema -> bytes -> t

decode schema bytes reconstructs a row from its on-disk representation according to schema.

Sourceval decode_prefix : schema -> bytes -> upto:int -> t

decode_prefix schema bytes ~upto decodes only columns 0, upto; columns beyond upto are left V_null and never decoded/allocated (#247). Use only when no consumer reads a column index > upto — it skips trailing columns (e.g. a large TEXT payload) an aggregate over a column prefix never needs. Columns in 0, upto are identical to decode.