An open API service indexing awesome lists of open source software.

https://github.com/arpunk/memento

Mnesia wrapper for LFE
https://github.com/arpunk/memento

lfe mnesia

Last synced: 8 months ago
JSON representation

Mnesia wrapper for LFE

Awesome Lists containing this project

README

          

* Memento
** Introduction

Memento is an mnesia wrapper for LFE

** Installation

Just add it to your =rebar.config= deps:

#+BEGIN_SRC erlang
{deps, [
...
{memento, {git, "git@github.com:arpunk/memento.git", {branch, "master"}}}
...
]}.
#+END_SRC

And then do the usual:

#+BEGIN_SRC sh
$ rebar3 compile
#+END_SRC

** Usage

It's very easy!

#+BEGIN_SRC lisp
(defmodule testing-memento
(import
(from memento-table (write 2))
(from memento-query (select 2))))

(include-lib "memento/include/table.lfe")
(include-lib "memento/include/transaction.lfe")

;; First time?
(memento:stop)
(memento-schema:create)
(memento:start)

;; Let's define some records
(defrecord person
name
age)

;; Now let's define our table properties
(set person-opts `[#(type set)
#(disc_copies [,(node)])])

;; Once we are ready we can create the table
(create-table person person-opts)

;; And the fun starts
(with-transaction
(write 'person (make-person name "John Doe" age 31)))

;; Querying
(with-transaction
(select 'person
(match-spec
(((tuple _ name age)) (when (> age 20))
(tuple 'ok name)))))
#+END_SRC