glesia

Safe-ish Gleam bindings for Erlang Mnesia.

Glesia wraps the common Mnesia lifecycle and data operations while keeping the dynamic BEAM boundary explicit. Table names and attributes are atoms; records cross the FFI boundary as Dynamic values and can be decoded by callers with normal Gleam decoders.

Types

pub type InsertNewResult {
  InsertNewInserted
  InsertNewExists
  InsertNewError(reason: dynamic.Dynamic)
}

Constructors

  • InsertNewInserted
  • InsertNewExists
  • InsertNewError(reason: dynamic.Dynamic)
pub type MnesiaError {
  AlreadyExists
  NotFound
  Timeout
  BadType(String)
  Abort(String)
  Unknown(String)
}

Constructors

  • AlreadyExists
  • NotFound
  • Timeout
  • BadType(String)
  • Abort(String)
  • Unknown(String)
pub type ReadResult {
  ReadOk(records: List(dynamic.Dynamic))
  ReadError(reason: dynamic.Dynamic)
}

Constructors

pub type SchemaResult {
  SchemaOk
  SchemaError(reason: dynamic.Dynamic)
}

Constructors

pub type SimpleResult {
  SimpleOk
  SimpleError(reason: dynamic.Dynamic)
}

Constructors

pub type StorageType {
  RamCopies
  DiscCopies
  DiscOnlyCopies
}

Constructors

  • RamCopies
  • DiscCopies
  • DiscOnlyCopies
pub type TableCreateResult {
  TableCreateOk
  TableCreateAlreadyExists
  TableCreateError(reason: dynamic.Dynamic)
}

Constructors

  • TableCreateOk
  • TableCreateAlreadyExists
  • TableCreateError(reason: dynamic.Dynamic)
pub type TableType {
  Set
  OrderedSet
  Bag
}

Constructors

  • Set
  • OrderedSet
  • Bag
pub type TransactionResult {
  TransactionOk(value: dynamic.Dynamic)
  TransactionAbort(reason: dynamic.Dynamic)
}

Constructors

Values

pub fn create_local_schema() -> Result(Nil, MnesiaError)
pub fn create_ram_table(
  table: atom.Atom,
  attributes: List(atom.Atom),
) -> Result(Nil, MnesiaError)
pub fn create_schema(
  nodes: List(atom.Atom),
) -> Result(Nil, MnesiaError)
pub fn create_table(
  table: atom.Atom,
  attributes: List(atom.Atom),
  storage_type: StorageType,
  table_type: TableType,
) -> Result(Nil, MnesiaError)
pub fn delete_local_schema() -> Result(Nil, MnesiaError)
pub fn delete_schema(
  nodes: List(atom.Atom),
) -> Result(Nil, MnesiaError)
pub fn dirty_delete(
  table: atom.Atom,
  key: dynamic.Dynamic,
) -> Result(Nil, MnesiaError)
pub fn dirty_read(
  table: atom.Atom,
  key: dynamic.Dynamic,
) -> Result(List(dynamic.Dynamic), MnesiaError)
pub fn dirty_read_decoded(
  table: atom.Atom,
  key: dynamic.Dynamic,
  decoder: decode.Decoder(value),
) -> Result(List(value), MnesiaError)
pub fn dirty_write(
  record: dynamic.Dynamic,
) -> Result(Nil, MnesiaError)
pub fn insert_new(
  table: atom.Atom,
  key: dynamic.Dynamic,
  record: dynamic.Dynamic,
) -> Result(Bool, MnesiaError)

Atomically write a record only when no record exists for the given key.

This uses a transactional Mnesia read with a write lock, then writes the record inside the same transaction. It returns Ok(True) when inserted and Ok(False) when the key already exists.

pub fn set_dir(path: String) -> Result(Nil, MnesiaError)
pub fn start() -> Result(Nil, MnesiaError)
pub fn stop() -> Result(Nil, MnesiaError)
pub fn transaction(
  fun: fn() -> value,
) -> Result(dynamic.Dynamic, MnesiaError)
Search Document