# 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
1. Add `fsdb` to your list of dependencies in `mix.exs`:
```elixir
def deps do
[{:fsdb, "~> 0.2.0"}]
end
```
2. Start `fsdb` along your app, optionally configure its `path` and 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")
```
3. Manually start it and use the extended API
```elixir
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)
```
4. Run the tests
```
mix test --no-start
```
## Releases
Version 0.1.0
- [x] create, drop support
- [x] insert, fetch, update, delete, list support
- [x] Erlang text term serialization support
Version 0.2.0
- [x] save support to bypass id generator
- [x] Added documentation
- [x] Added app supervisor