fsdb
Minimal filesystem database with Erlang term text serialization (Erlang's JSON). Each table is a folder and each row is a file. Any Erlang term can be persisted as a row. Rows have auto generated IDs. Row files are human readable.
Wrote this out of frustration that current versions of sqlite_ecto (1.1.0) and Phoenix (1.2.0) are incompatible. Postgres is overkill for keeping track of small persistent chunks of data.
Installation and Usage
- Add
fsdbto your list of dependencies inmix.exs:
```elixir
def deps do
[{:fsdb, "~> 0.2.1"}]
end
```
- Start
fsdbalong your app, optionally configure itspathand use the standard API
```elixir
def application do
[applications: [:fsdb]]
end
```
```elixir
#Path set to ~/.fsdb by default
config :fsdb,
path: Path.expand("~/.fsdb")
```
```elixir
:ok = Fsdb.create("table1")
{1, "row1"} = Fsdb.insert("table1", "row1")
{1, "row1+"} = Fsdb.update("table1", 1, "row1+")
{1, "row1+"} = Fsdb.fetch("table1", 1)
{1, "row1+"} = Fsdb.delete("table1", 1)
{:not_found, "table1", 1} = Fsdb.fetch("table1", 1)
[] = Fsdb.list("table1")
#bypass the id generator
{2, "row2"} = Fsdb.save("table1", 2, "row2")
{3, "row3"} = Fsdb.save("table1", 3, "row3")
#FIXME tuples may not be ID ordered
[{2, "row2"}, {3, "row3"}] = Fsdb.list("table1")
:ok = Fsdb.drop("table1")
```
- Manually start it and use the extended API
path = Path.expand("~/.fsdb")
{:ok, pid} = Fsdb.Server.start_link([path: path])
:ok = Fsdb.create(pid, "table1")
{1, "row1"} = Fsdb.insert(pid, "table1", "row1")
{1, "row1+"} = Fsdb.update(pid, "table1", 1, "row1+")
{1, "row1+"} = Fsdb.fetch(pid, "table1", 1)
{1, "row1+"} = Fsdb.delete(pid, "table1", 1)
{:not_found, "table1", 1} = Fsdb.fetch(pid, "table1", 1)
[] = Fsdb.list(pid, "table1")
#bypass the id generator
{2, "row2"} = Fsdb.save(pid, "table1", 2, "row2")
{3, "row3"} = Fsdb.save(pid, "table1", 3, "row3")
#FIXME tuples may not be ID ordered
[{2, "row2"}, {3, "row3"}] = Fsdb.list(pid, "table1")
:ok = Fsdb.drop(pid, "table1")
:ok = Fsdb.Server.stop(pid)
- Run the tests
mix test --no-start
Releases
Version 0.1.0
- create, drop support
- insert, fetch, update, delete, list support
- Erlang text term serialization support
Version 0.2.0
- save support to bypass id generator
- Added documentation
- Added app supervisor