Database

Database

new Database(directory, passwordopt, optionsopt)

Creates a new Database object
Parameters:
Name Type Attributes Default Description
directory string The working directory for the database
password string <optional>
0 An optional password with which to encrypt the data
options object <optional>
A set of configuration options
Properties
Name Type Attributes Default Description
write_synchronous boolean <optional>
false Whether to write to disk in a synchronous manner, set to true for important data. Maybe be defaulted to true in future.
Source:
Tutorials:

Methods

(static) init(name, passwordopt)

Statically initialize a new database
Parameters:
Name Type Attributes Default Description
name string Name of the new database
password string <optional>
0 Password with which to encrypt the new database
Source:

(static) rand(lengthopt) → {string}

Get a random string
Parameters:
Name Type Attributes Default Description
length number <optional>
8
Source:

(static) rand_safe(lengthopt) → {string}

Get a random string with only alpha-numeric values
Parameters:
Name Type Attributes Default Description
length number <optional>
8
Source:

(static) test_random(test) → {number}

Test a string for randomness
Parameters:
Name Type Description
test string
Source:

cleanup()

Cleanup and write data
Source:

createColumn(name, fillopt)

Create a new empty column
Parameters:
Name Type Attributes Default Description
name string The name of the column you wish to create
fill string <optional>
"" Content to place in each row of the new column
Source:
Throws:
  • DatabaseNotInitializedError
  • NoSuchTableError

createTable(name, columns)

Create a new table with specified columns
Parameters:
Name Type Description
name string The name of the new table
columns Array.<string> An array of column names
Source:
Throws:
DatabaseNotInitializedError

deleteRows(where, limitopt) → {Array.<object>}

Delete row containing specified values, returns deleted rows
Parameters:
Name Type Attributes Default Description
where object An object defining search criteria {column:term}
limit number <optional>
Infinity Limit the number of deleted rows
Source:
Throws:
  • DatabaseNotInitializedError
  • NoSuchTableError

getRows(nameopt) → {Array.<object>}

Get all rows from selected table
Parameters:
Name Type Attributes Description
name string <optional>
Specify a table from which to get all rows
Source:
Throws:
  • DatabaseNotInitializedError
  • NoSuchTableError

initialize()

Initialize a new database
Source:
Throws:
DatabaseAlreadyInitializedError

insertRow(arguments)

Insert row containing specified values
Parameters:
Name Type Description
arguments * Insert a row from an object where {column:data}
Source:
Throws:
  • DatabaseNotInitializedError
  • NoSuchTableError

insertRowObject(object)

Insert a row from an object with key/value pairs
Parameters:
Name Type Description
object any An object containing {column:value}
Source:

searchColumn(name, term) → {object}

Search a specified column for a specified term
Parameters:
Name Type Description
name string The name of the column you wish to search
term string The term for which you wish to search
Source:
Throws:
  • DatabaseNotInitializedError
  • NoSuchTableError

searchColumns(terms, limitopt, oropt) → {Array.<object>}

Search specified columns for a specified term
Parameters:
Name Type Attributes Default Description
terms object An object with column keys and data values
limit number <optional>
Infinity Number of search results to return
or boolean <optional>
false Search by ( term AND term ), when true ( term OR term )
Source:
Throws:
  • DatabaseNotInitializedError
  • NoSuchTableError

selectTable(name)

Set the working table
Parameters:
Name Type Description
name string The name of the table you wish to select
Source:
Throws:
  • DatabaseNotInitializedError
  • NoSuchTableError

tableColumns() → {Array.<string>}

List columns from selected table
Source:
Throws:
  • DatabaseNotInitializedError
  • NoSuchTableError

updateRows(newData, where)

Updates rows with new data where current data matches
Parameters:
Name Type Description
newData object {column:name,data:value}
where object {column:term}
Source:
Throws:
  • DatabaseNotInitializedError
  • NoSuchTableError