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
- Host: GitHub
- URL: https://github.com/arpunk/memento
- Owner: arpunk
- License: mit
- Created: 2015-06-10T02:37:53.000Z (about 11 years ago)
- Default Branch: master
- Last Pushed: 2015-12-29T05:17:42.000Z (over 10 years ago)
- Last Synced: 2023-03-23T23:51:42.563Z (about 3 years ago)
- Topics: lfe, mnesia
- Language: Erlang
- Size: 14.6 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.org
- License: LICENSE
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