Methods
-
checkExists(tblName, column, value)
-
Check if a record (row) exists within a given table
Parameters:
Name Type Description tblName
string The name of the table to check
column
string The column to search
value
* The value to search for
Returns:
Returns {true} if the value is found {false} otherwise
- Type
- boolean
Example
if(flatly.checkExists('table1', 'id', 1)) { //do something }
-
dbInfo()
-
Returns currently selected database name and table names
Returns:
An object with the database name, table names and table count
- Type
- Object
-
findAll(criteria)
-
Returns all rows that match the criteria object
Parameters:
Name Type Description criteria
Object An options object with the search details
Properties
Name Type Description from
String The name of the table to search
where
Object An object containing the column and value criterion
Returns:
- Type
- *
-
findOne(criteria)
-
Returns a row from the specified table
Parameters:
Name Type Description criteria
Object An options object with the search details
Properties
Name Type Description from
String The name of the table to search
where
Object An object containing the column and value criterion
Returns:
A row object
- Type
- Object
-
getSchema()
-
Returns the schema of the currently selected DB
Returns:
- Type
- Array.<string>
Example
console.log(flatly.getSchema()); // -> ['table1', 'table2', 'table3']
-
getTable(tblName)
-
Returns an object representing the table requested. Use flatly#findOne or flatly#findAll for querying table contents
Parameters:
Name Type Description tblName
String The name of the table to be returned
Returns:
An object representing the requested table
- Type
- Object
-
insert(row, tblName)
-
Insert a row into a table
Parameters:
Name Type Description row
object Row object to insert
tblName
string Name of the table to insert into
Returns:
- Type
- flatly
-
refreshTable(tblName)
-
Refresh table from disk
Parameters:
Name Type Description tblName
string Table name to refresh
Returns:
Table
- Type
- object
-
save(options, callback)
-
Save table data to disk. Remove flatly metadata before saving.
Parameters:
Name Type Argument Description options
Object Properties
Name Type Argument Default Description table
string The table to save
overwrite
<optional>
false Overwrite the existing table?
async
boolean <optional>
false Sync/Async Execution. Defaults to Sync
callback
function <optional>
The callback to execute if we're working asynchronously
Returns:
- Type
- flatly
-
tables()
-
Returns a deep clone of the tables array
Returns:
- Type
- Array
-
update(rowData, matchBy, tblName)
-
Update an existing table row
Parameters:
Name Type Description rowData
Object An object representing a row of the target table
matchBy
String The key to use to match rowData to an existing row in the table
tblName
String The target table name
Returns:
- Type
- flatly
Example
flatly.update({ id: 6, name: Michael Flatly }, 'id', 'customers');
-
use(options)
-
Loads a database from the specified filepath
Parameters:
Name Type Description options
Object Properties
Name Type Description name
String Specify a name for the database
src
String A path to the required data
Returns:
- Type
- flatly