JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 20
  • Score
    100M100P100Q55803F
  • License MIT

Lightweight JSON flat file database for small projects

Package Exports

  • flatly

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (flatly) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

flatly

flatly is a simple flat file JSON db system.

IMPORTANT: This package is under active development and is not considered fit for production

Kind: global class

new flatly()

flatly class contains the entire flatly api

flatly.dbInfo() ⇒ Object

Returns currently selected database name and table names

Kind: instance method of flatly
Returns: Object - An object with the database name, table names and table count

flatly.getSchema() ⇒ Array.<string>

Returns the schema of the currently selected DB

Kind: instance method of flatly
Example

console.log(flatly.getSchema());
 // -> ['table1', 'table2', 'table3']

flatly.tables() ⇒ Array

Returns a deep clone of the tables array

Kind: instance method of flatly

flatly.getTable(tblName) ⇒ Object

Returns an object representing the table requested. Use findOne or findAll for querying table contents

Kind: instance method of flatly
Returns: Object - An object representing the requested table

Param Type Description
tblName String The name of the table to be returned

flatly.findOne(criteria) ⇒ Array

Returns a row from the specified table

Kind: instance method of flatly
Returns: Array - An array containing the search result
Params: String criteria.where.column The name of the column to search
Params: number|String criteria.where.equals The value to search the column for

Param Type Description
criteria Object An options object with the search details
criteria.from String The name of the table to search
criteria.where Object An object containing the column and value criterion

flatly.findAll(criteria) ⇒ *

Returns all rows that match the criteria object

Kind: instance method of flatly
Params: String criteria.where.column The name of the column to search
Params: number|String criteria.where.equals The value to search the column for

Param Type Description
criteria Object An options object with the search details
criteria.from String The name of the table to search
criteria.where Object An object containing the column and value criterion

flatly.use(options) ⇒ flatly

Loads a database from the specified filepath

Kind: instance method of flatly

Param Type Description
options Object
options.name String Specify a name for the database
options.src String A path to the required data

flatly.save(options, [callback]) ⇒ flatly

Save table data to disk. Remove flatly metadata before saving.

Kind: instance method of flatly

Param Type Default Description
options Object
options.table string The table to save
[options.overwrite] false Overwrite the existing table?
[options.async] boolean false Sync/Async Execution. Defaults to Sync
[callback] function The callback to execute if we're working asynchronously

flatly.checkExists(tblName, column, value) ⇒ boolean

Check if a record (row) exists within a given table

Kind: instance method of flatly
Returns: boolean - Returns {true} if the value is found {false} otherwise

Param Type Description
tblName string The name of the table to check
column string The column to search
value * The value to search for

Example

if(flatly.checkExists('table1', 'id', 1)) { //do something }

flatly.update(rowData, matchBy, tblName) ⇒ flatly

Update an existing table row

Kind: instance method of flatly

Param 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

Example

flatly.update({
     id: 6,
     name: Michael Flatly
 }, 'id', 'customers');