fsdb v0.3.0 Fsdb.Server
Fsdb.Server module.
#run with: mix sample_server
path = Path.expand("_build/dev/.fsdb")
{:ok, db} = Fsdb.Server.start_link([path: path])
#drop to start over
:ok = Fsdb.Server.drop(db, "table1")
:ok = Fsdb.Server.create(db, "table1")
#insert generates and returns an autoincrementing id
{:ok, 1} = Fsdb.Server.insert(db, "table1", "row1")
{:ok, "row1"} = Fsdb.Server.fetch(db, "table1", 1)
#operation on nonexisting ids return not found
:nf = Fsdb.Server.delete(db, "table1", 5)
:nf = Fsdb.Server.update(db, "table1", 5, "row5+")
#save overrides and updates id generator
:ok = Fsdb.Server.save(db, "table1", 5, "row5")
:ok = Fsdb.Server.save(db, "table1", 3, "row3")
#continue +1 of largest id used/generated before
{:ok, 6} = Fsdb.Server.insert(db, "table1", "row6")
#operations that get back previous value
{:ok, "row5"} = Fsdb.Server.update(db, "table1", 5, "row5+")
{:ok, "row5+"} = Fsdb.Server.save(db, "table1", 5, "row5++")
{:ok, "row5++"} = Fsdb.Server.delete(db, "table1", 5)
#tuples may not be id ordered
[{1, "row1"}, {3, "row3"}, {6, "row6"}] = Fsdb.Server.list(db, "table1")
Link to this section Summary
Functions
Creates a table with name table
.
Returns :ok
Deletes the row in table table
having the id id
.
Returns {:ok, previous_row} | :nf
Drops the table named table
.
Returns :ok
Fetches the row in table table
having the id id
.
Returns {:ok, row} | :nf
Inserts row row
in table table
with auto generated id.
Returns {:ok, id}
Returns all rows in table table
.
Returns [{id, row}, ...]
Inserts or updates row row
in table table
with specific id id
.
If the provided id is greater than the last autogenerated id then
the autogenerated id is updated to the provided one.
Returns :ok | {:ok, previous_row}
Starts the GenServer
Stops the GenServer
Updates the row in table table
having the id id
.
Returns {:ok, previous_row} | :nf
Link to this section Functions
Creates a table with name table
.
Returns :ok
.
Deletes the row in table table
having the id id
.
Returns {:ok, previous_row} | :nf
.
Drops the table named table
.
Returns :ok
.
Fetches the row in table table
having the id id
.
Returns {:ok, row} | :nf
.
Inserts row row
in table table
with auto generated id.
Returns {:ok, id}
.
Returns all rows in table table
.
Returns [{id, row}, ...]
.
Inserts or updates row row
in table table
with specific id id
.
If the provided id is greater than the last autogenerated id then
the autogenerated id is updated to the provided one.
Returns :ok | {:ok, previous_row}
.
Starts the GenServer.
params
must contain a valid path in the :path
key.
opts
is optional and is passed verbatim to GenServer.
Returns {:ok, pid}
.
Example
Fsdb.Server.start_link([path: ".fsdb"], [name: Fsdb.Server])
Stops the GenServer.
Returns :ok
.
Updates the row in table table
having the id id
.
Returns {:ok, previous_row} | :nf
.