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.

dropAll()

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

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 an string with error message.

Clone this wiki locally