Skip to content

Functions

Mikael Carlsson edited this page Apr 15, 2017 · 12 revisions

lociDB has alot of smart functions to help you set, get, insert and drop data.

set(tblName, object)

tblName - String of the table name eg. "users", "settings" etc.

object - An object you wish to set to table, eg. var user = {name: "mikael", city: "Gothenburg", age: 17}

This function will overwrite any existing content in the table. If you want to insert and object on the last row use the function insert(tblName, object) instead.

Returns only an error as a string if something went wrong.

insert(tblName, object)

tblName - String of the table name eg. "users", "settings" etc.

object - An object you wish to set to table, eg. var user = {name: "mikael", city: "Gothenburg", age: 17}

This function will insert the object on the last row in the table. Will NOT overwrite any existing data.

Returns only an error as a string if something went wrong.

get(tblName)

tblName - String of the table name eg. "users", "settings" etc.

Returns an array of objects that is found in the table.

listTables()

Returns an array of all tables that are existing.

getRows(tblName, key, value)

tblName - String of the table name eg. "users", "settings" etc.

key - String of what key you wish to search for.

value - String of what value you want the key to have

This function will get all rows in a table matching key and a value as an array of objects.

Returns an array of objects if any matching is found. Otherwise a string with error message.

dropRows(tblName, key, value)

tblName - String of the table you want to delete rows in.

key - String of what key you wish to match value

value - Value you want to match key.

Drop/delete specific rows in a table. Eg. dropRows("users", "name", "Mikael"); to drop/delete all users in a table that has a key name and the value is Mikael.

Returns a number of total rows deleted.

dropTable(tblName)

tblName - String of the table you want to drop/delete.

Drop/Deletes a specific table. USE AT YOUR OWN RISK

dropAll()

Drop/Deletes all tables that are existing. USE AT YOUR OWN RISK

Clone this wiki locally