fsdb v0.2.3 Fsdb

API module.

  #run with: mix sample

  #drop to start over
  :ok = Fsdb.drop("table1")

  #creates table at dev default _build/dev/.fsdb
  #configure path with: config :fsdb, path: <NEW_PATH>
  :ok = Fsdb.create("table1")

  #insert generates and returns an autoincrementing id
  {:ok, 1} = Fsdb.insert("table1", "row1")
  {:ok, "row1"} = Fsdb.fetch("table1", 1)

  #operation on unexisting ids return not found
  :nf = Fsdb.delete("table1", 5)
  :nf = Fsdb.update("table1", 5, "row5+")

  #save overrides and updates id generator
  :ok = Fsdb.save("table1", 5, "row5")
  :ok = Fsdb.save("table1", 3, "row3")
  #continue +1 of largest id used/generated before
  {:ok, 6} = Fsdb.insert("table1", "row6")

  #operations that get back previous value
  {:ok, "row5"} = Fsdb.update("table1", 5, "row5+")
  {:ok, "row5+"} = Fsdb.save("table1", 5, "row5++")
  {:ok, "row5++"} = Fsdb.delete("table1", 5)

  #tuples may not be id ordered
  [{1, "row1"}, {3, "row3"}, {6, "row6"}] = Fsdb.list("table1")

Summary

Functions

Creates a table with name table

Same as above but addresses an specific Fsdb.Server

Deletes the row in table table having the id id

Same as above but addresses an specific Fsdb.Server

Drops the table named table

Same as above but addresses an specific Fsdb.Server

Fetches the row in table table having the id id

Same as above but addresses an specific Fsdb.Server

Inserts row row in table table with auto generated id

Same as above but addresses an specific Fsdb.Server

Returns all rows in table table

Same as above but addresses an specific Fsdb.Server

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

Same as above but addresses an specific Fsdb.Server

Starts the GenServer

Stops the server

Updates the row in table table having the id id

Same as above but addresses an specific Fsdb.Server

Functions

create(table)

Creates a table with name table.

Returns :ok.

create(pid, table)

Same as above but addresses an specific Fsdb.Server.

pid can be either a pid or a registered name.

delete(table, id)

Deletes the row in table table having the id id.

Returns {:ok, previous_row} | :nf.

delete(pid, table, id)

Same as above but addresses an specific Fsdb.Server.

pid can be either a pid or a registered name.

drop(table)

Drops the table named table.

Returns :ok.

drop(pid, table)

Same as above but addresses an specific Fsdb.Server.

pid can be either a pid or a registered name.

fetch(table, id)

Fetches the row in table table having the id id.

Returns {:ok, row} | :nf.

fetch(pid, table, id)

Same as above but addresses an specific Fsdb.Server.

pid can be either a pid or a registered name.

insert(table, row)

Inserts row row in table table with auto generated id.

Returns {:ok, id}.

insert(pid, table, row)

Same as above but addresses an specific Fsdb.Server.

pid can be either a pid or a registered name.

list(table)

Returns all rows in table table.

Returns [{id, row}, ...].

list(pid, table)

Same as above but addresses an specific Fsdb.Server.

pid can be either a pid or a registered name.

save(table, 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}.

save(pid, table, id, row)

Same as above but addresses an specific Fsdb.Server.

pid can be either a pid or a registered name.

start_link(state, opts \\ [])

Starts the GenServer.

state 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])
stop(pid)

Stops the server.

Returns :ok.

update(table, id, row)

Updates the row in table table having the id id.

Returns {:ok, previous_row} | :nf.

update(pid, table, id, row)

Same as above but addresses an specific Fsdb.Server.

pid can be either a pid or a registered name.