The primary abstraction class, there is no database implimintation code here. Just events, quries and filters.

export
class

  NanoSQLInstance

### Hierarchy

- NanoSQLInstance

## Index

### Constructors

- constructor

### Properties

- _AVMod
- _activeAV
- _hasEvents
- _models
- _ormFns
- _queryMod
- _tableNames
- _triggerEvents
- backend
- data

### Methods

- actions
- avFilter
- cleanArgs
- config
- connect
- default
- defaultORM
- doAction
- doTransaction
- extend
- getView
- loadCSV
- loadJS
- model
- newFunction
- off
- on
- query
- queryFilter
- rowFilter
- table
- triggerEvent
- updateORM
- views
- _hash
- chain
- random16Bits
- timeid
- uuid

## Constructors

### constructor

- new NanoSQLInstance(): NanoSQLInstance

- - Defined in index.ts:344

  #### Returns NanoSQLInstance

## Properties

### _AVMod

_AVMod: IActionViewMod

- Defined in index.ts:317

Holds a reference to the optional action/view modifier

memberof

  NanoSQLInstance

### _activeAV

_activeAV: string | undefined

- Defined in index.ts:269

The current action or view being triggered.

internal
type

  {string}

memberof

  NanoSQLInstance

### _hasEvents

_hasEvents: StdObject<boolean>

- Defined in index.ts:260

Stores wether each table has events attached to it or not.

type

  {StdObject<boolean>}

memberof

  NanoSQLInstance

### _models

_models: StdObject<Array<DataModel>>

- Defined in index.ts:230

A map containing the models

internal
type

  {StdObject<Array<DataModel>>}

memberof

  NanoSQLInstance

### _ormFns

_ormFns: object

- Defined in index.ts:240

Stores the default ORM functions for each table.

memberof

  NanoSQLInstance

#### Type declaration

- ##### [table: string]: function

  - - (column: string, row: DBRow): ORMArgs

    - #### Parameters

      - ##### column: string

      - ##### row: DBRow

      #### Returns ORMArgs

### _queryMod

_queryMod: function

- Defined in index.ts:309

Lets you modify queries before they run on the database

internal
memberof

  NanoSQLInstance

#### Type declaration

- - (args: DBExec, complete: function): void

  - #### Parameters

    - ##### args: DBExec

    - ##### complete: function

      - - (args: DBExec): void

        - #### Parameters

          - ##### args: DBExec

          #### Returns void

### Private _tableNames

_tableNames: string[]

- Defined in index.ts:335

Store an array of table names for ORM type casting.

type

  {string[]}

memberof

  NanoSQLInstance

### _triggerEvents

_triggerEvents: Array<"change" | "delete" | "upsert" | "drop" | "select" | "error" | string>

- Defined in index.ts:251

An array containing a temporary list of events to trigger

internal
type

  {Array<"change"|"delete"|"upsert"|"drop"|"select"|"error">}

memberof

  NanoSQLInstance

### backend

backend: NanoSQLBackend

- Defined in index.ts:176

The backend currently being used

type

  {NanoSQLBackend}

memberof

  NanoSQLInstance

### data

data: any

- Defined in index.ts:184

Misc placeholder that can be used by the dev.

type

  {*}

memberof

  NanoSQLInstance

## Methods

### actions

- actions(actionArray: Array<ActionOrView>): NanoSQLInstance

- - Defined in index.ts:736

  Declare the actions for the current selected table. Must be called before connect()

  Actions are created like this:

      .actions([
       {
           name:"action-name",
           args: ["array","of","arguments"],
           call: function(args) {
               // Because of our "args" array the args input of this function will look like this:
               // NanoSQL will not let any other arguments into this function.
               args:{
                   array:'',
                   of:'',
                   arguments:''
               }
               //We can use them in our query
               return this.query("upsert",{balance:0}).where(['name','IN',args.array]).exec();
           }
       }
      ])

  Then later in your app..

      NanoSQL("users").doAction("action-name",{array:'',of:"",arguments:""}).then(function(result) {
       console.log(result) <=== result of your view will be there.
      })

  Optionally you can type cast the arguments at run time typescript style, just add the types after the arguments in the array. Like this:

      .actions[{
           name:...
           args:["name:string","balance:float","active:bool"]
           call:...
      }]

  NanoSQL will force the arguments passed into the function to those types.

  Possible types are string, bool, float, int, map, array and bool.

  memberof

    NanoSQLInstance

  #### Parameters

  - ##### actionArray: Array<ActionOrView>

  #### Returns NanoSQLInstance

### avFilter

- avFilter(filterFunc: IActionViewMod): this

- - Defined in index.ts:1156

  Set the action/view filter function. Called before the action/view is sent to the datastore

  memberof

    NanoSQLInstance

  #### Parameters

  - ##### filterFunc: IActionViewMod

  #### Returns this

### cleanArgs

- cleanArgs(argDeclarations: Array<string>, args: StdObject<any>): StdObject<any>

- - Defined in index.ts:606

  Take an action or view and it's args, then make sure the args comform to the types declared in the model.

  memberof

    NanoSQLInstance

  #### Parameters

  - ##### argDeclarations: Array<string>

  - ##### args: StdObject<any>

  #### Returns StdObject<any>

### config

- config(args: any): NanoSQLInstance

- - Defined in index.ts:1169

  Configure the database driver, must be called before the connect() method.

  memberof

    NanoSQLInstance

  #### Parameters

  - ##### args: any

  #### Returns NanoSQLInstance

### connect

- connect(backend?: NanoSQLBackend): Promise<Object | string>

- - Defined in index.ts:394

  Inits the backend database for use.

  Optionally include a custom database driver, otherwise the built in memory driver will be used.

  memberof

    NanoSQLInstance

  #### Parameters

  - ##### Optional backend: NanoSQLBackend

  #### Returns Promise<Object | string>

### default

- default(replaceObj?: any): object

- - Defined in index.ts:1032

  Returns a default object for the current table's data model, useful for forms.

  The optional argument lets you pass in an object to over write the data model's defaults as desired.

  Examples:

      console.log(NanoSQL("users").default()) <= {username:"none", id:undefined, age: 0}
      console.log(NanoSQL("users").default({username:"defalt"})) <= {username:"default", id:undefined, age: 0}

  DO NOT use this inside upsert commands like `.query("upsert",NanoSQL("users").defalt({userObj}))..`. The database defaults are already applied through the upsert path, you'll be doing double work.

  Only use this to pull default values into a form in your UI or similar situation.

  memberof

    NanoSQLInstance

  #### Parameters

  - ##### Optional replaceObj: any

  #### Returns object

  - ##### [key: string]: any

### defaultORM

- defaultORM(callBack: function): this

- - Defined in index.ts:979

  Add a default ORM query to a speicfic table.

  memberof

    NanoSQLInstance

  #### Parameters

  - ##### callBack: function

    - - (column: string, parentRowData: DBRow[]): ORMArgs

      - #### Parameters

        - ##### column: string

        - ##### parentRowData: DBRow[]

        #### Returns ORMArgs

  #### Returns this

### doAction

- doAction(actionName: string, actionArgs: any): Promise<Array<DBRow> | NanoSQLInstance>

- - Defined in index.ts:756

  Init an action for the current selected table. Reference the "actions" method for more info.

  Example:

      NanoSQL("users").doAction('action-name',{foo:"bar"}).then(function(result) {
           console.log(result) <== result of your action
      });

  memberof

    NanoSQLInstance

  #### Parameters

  - ##### actionName: string

  - ##### actionArgs: any

  #### Returns Promise<Array<DBRow> | NanoSQLInstance>

### doTransaction

- doTransaction(initTransaction: function): Promise<any>

- - Defined in index.ts:1056

  Executes a transaction against the database, batching all the queries together.

  memberof

    NanoSQLInstance

  #### Parameters

  - ##### initTransaction: function

    - - (db: function, complete: function): void

      - #### Parameters

        - ##### db: function

          - - (table?: undefined | string): object

            - #### Parameters

              - ##### Optional table: undefined | string

              #### Returns object

              - ##### query: function

                - - (action: "select" | "upsert" | "delete" | "drop" | "show tables" | "describe", args?: any): _NanoSQLTransactionQuery

                  - #### Parameters

                    - ##### action: "select" | "upsert" | "delete" | "drop" | "show tables" | "describe"

                    - ##### Optional args: any

                    #### Returns _NanoSQLTransactionQuery

              - ##### updateORM: function

                - - (action: "add" | "delete" | "drop" | "set", column?: undefined | string, relationIDs?: any[]): _NanoSQLTransactionORMQuery | undefined

                  - #### Parameters

                    - ##### action: "add" | "delete" | "drop" | "set"

                    - ##### Optional column: undefined | string

                    - ##### Optional relationIDs: any[]

                    #### Returns _NanoSQLTransactionORMQuery | undefined

        - ##### complete: function

          - - (): void

            - #### Returns void

  #### Returns Promise<any>

### extend

- extend(...args: Array<any>): any | NanoSQLInstance

- - Defined in index.ts:1183

  Perform a custom action supported by the database driver.

  memberof

    NanoSQLInstance

  #### Parameters

  - ##### Rest ...args: Array<any>

  #### Returns any | NanoSQLInstance

### getView

- getView(viewName: string, viewArgs?: any): Promise<Array<any> | NanoSQLInstance>

- - Defined in index.ts:592

  Execute a specific view. Refernece the "views" function for more description.

  Example:

      NanoSQL("users").getView('view-name',{foo:"bar"}).then(function(result) {
       console.log(result) <== view result.
      })

  memberof

    NanoSQLInstance

  #### Parameters

  - ##### viewName: string

  - ##### Default value viewArgs: any = {}

  #### Returns Promise<Array<any> | NanoSQLInstance>

### loadCSV

- loadCSV(table: string, csv: string, useTransaction?: boolean): Promise<Array<Object>>

- - Defined in index.ts:1263

  Load a CSV file into the DB. Headers must exist and will be used to identify what columns to attach the data to.

  This function performs a bunch of upserts, so expect appropriate behavior based on the primary key.

  Rows must align with the data model. Row data that isn't in the data model will be ignored.

  memberof

    NanoSQLInstance

  #### Parameters

  - ##### table: string

  - ##### csv: string

  - ##### Default value useTransaction: boolean = true

  #### Returns Promise<Array<Object>>

### loadJS

- loadJS(table: string, rows: Array<Object>, useTransaction?: boolean): Promise<Array<Object>>

- - Defined in index.ts:1214

  Load JSON directly into the DB. JSON must be an array of maps, like this:

      [
       {"name":"billy","age":20},
       {"name":"johnny":"age":30}
      ]

  Rows must align with the data model. Row data that isn't in the data model will be ignored.

  memberof

    NanoSQLInstance

  #### Parameters

  - ##### table: string

  - ##### rows: Array<Object>

  - ##### Default value useTransaction: boolean = true

  #### Returns Promise<Array<Object>>

### model

- model(dataModel: Array<DataModel>): NanoSQLInstance

- - Defined in index.ts:502

  Declare the data model for the current selected table.

  Please reference the DataModel interface for how to impliment this, a quick example:

      .model([
       {key:"id",type:"int",props:["ai","pk"]} //auto incriment and primary key
       {key:"name",type:"string"}
      ])

  memberof

    NanoSQLInstance

  #### Parameters

  - ##### dataModel: Array<DataModel>

  #### Returns NanoSQLInstance

### newFunction

- newFunction(functionName: string, functionType: "aggregate" | "simple", filterFunction: function): NanoSQLInstance

- - Defined in index.ts:837

  Add a function to the usable list of functions for this database. Must be called BEFORE connect().

  Functions can be used with any database on the attached store.

  Example:

      NanoSQL().newFunction('ADD',{ // Function is called "ADD"
       type:"simple", // "aggregate" or "simple"
       call:function(row:DBRow, args: string[], ptr: number[], prev: any) {
           // arguments are passed in as an array in the args argument.
           // ptr is an array that lets you know the length and position of the current query.
           // ptr[0] is the current index, ptr[1] is the max index/length
           // prev is only used for aggregate functions, lets  you pass an argument into the next function call.
           let r = JSON.parse(JSON.stringify(row));
           r.ADD = args.reduce((a, b) => parseFloat(a) + parseFloat(b));
           return r;
       }
      });

  Then to use it in a query:

      NanoSQL("users").query("select",["name","ADD(balance, 2)"]).exec();

  Make sure the calculated value is add to the row(s) with the `useKey` argument, otherwise `AS` arguments won't work.

  memberof

    NanoSQLInstance

  #### Parameters

  - ##### functionName: string

  - ##### functionType: "aggregate" | "simple"

  - ##### filterFunction: function

    - - (row: DBRow, args: string[], ptr: number[], prev?: any): DBRow[]

      - #### Parameters

        - ##### row: DBRow

        - ##### args: string[]

        - ##### ptr: number[]

        - ##### Optional prev: any

        #### Returns DBRow[]

  #### Returns NanoSQLInstance

### off

- off(callBack: Function): NanoSQLInstance

- - Defined in index.ts:463

  Remove a specific event handler from being triggered anymore.

  memberof

    NanoSQLInstance

  #### Parameters

  - ##### callBack: Function

  #### Returns NanoSQLInstance

### on

- on(actions: "change" | "delete" | "upsert" | "drop" | "select" | "error", callBack: function): NanoSQLInstance

- - Defined in index.ts:431

  Adds an event listener to the selected database table.

  memberof

    NanoSQLInstance

  #### Parameters

  - ##### actions: "change" | "delete" | "upsert" | "drop" | "select" | "error"

  - ##### callBack: function

    - - (event: DatabaseEvent, database: NanoSQLInstance): void

      - #### Parameters

        - ##### event: DatabaseEvent

        - ##### database: NanoSQLInstance

        #### Returns void

  #### Returns NanoSQLInstance

### query

- query(action: "select" | "upsert" | "delete" | "drop" | "show tables" | "describe", args?: any, bypassORMPurge?: undefined | true | false): _NanoSQLQuery

- - Defined in index.ts:900

  Start a query into the current selected table. Possibl querys are "select", "upsert", "delete", and "drop";

  ### Select

  Select is used to pull a set of rows or other data from the table. When you use select the optional second argument of the query is an array of strings that allow you to show only specific columns.

  Examples:

      .query("select") // No arguments, select all columns
      .query("select",['username']) // only get the username column
      .query("select",["username","balance"]) //Get two columns, username and balance.
      .query("select",["count(*)"]) //Get the length of records in the database

  ### Upsert

  Upsert is used to add or modify data in the database. If the primary key rows are null or undefined, the data will always be added in a new row. Otherwise, you might be updating existing rows. The second argument of the query with upserts is always an Object of the data to upsert.

  Examples:

      .query("upsert",{id:1, username:"Scott"}) //If row ID 1 exists, set the username to scott, otherwise create a new row with this data.
      .query("upsert",{username:"Scott"}) //Add a new row to the db with this username in the row.
      .query("upsert",{balance:-35}).where(["balance","<",0]) // If you use a WHERE statement this data will be applied to the rows found with the where statement.

  ### Delete

  Delete is used to remove data from the database. It works exactly like select, except it removes data instead of selecting it. The second argument is an array of columns to clear. If no second argument is passed, the entire row is deleted. If no where argument is passed, the entire table is dropped

  Examples:

      .query("delete",['balance']) //Clear the contents of the balance column on ALL rows.
      .query("delete",['comments']).where(["accountType","=","spammer"]) // If a where statment is passed you'll only clear the columns of the rows selected by the where statement.
      .query("delete").where(["balance","<",0]) // remove all rows with a balance less than zero
      .query("delete") // Same as drop statement

  ### Drop

  Drop is used to completely clear the contents of a database. There are no arguments.

  Drop Examples:

      .query("drop")

  memberof

    NanoSQLInstance

  #### Parameters

  - ##### action: "select" | "upsert" | "delete" | "drop" | "show tables" | "describe"

  - ##### Optional args: any

  - ##### Optional bypassORMPurge: undefined | true | false

  #### Returns _NanoSQLQuery

### queryFilter

- queryFilter(callBack: function): NanoSQLInstance

- - Defined in index.ts:1142

  Adds a query filter to every request.

  memberof

    NanoSQLInstance

  #### Parameters

  - ##### callBack: function

    - - (args: DBExec, complete: function): void

      - #### Parameters

        - ##### args: DBExec

        - ##### complete: function

          - - (args: DBExec): void

            - #### Parameters

              - ##### args: DBExec

              #### Returns void

  #### Returns NanoSQLInstance

### rowFilter

- rowFilter(callBack: function): this

- - Defined in index.ts:1247

  Adds a filter to rows going into the database, allows you to control the range and type of inputs.

  This function will be called on every upsert and you'll recieve the upsert data as it's being passed in.

  NanoSQL will apply the "default" row data to each column and type cast each column BEFORE calling this function.

  memberof

    NanoSQLInstance

  #### Parameters

  - ##### callBack: function

    - - (row: any): any

      - #### Parameters

        - ##### row: any

        #### Returns any

  #### Returns this

### table

- table(table?: undefined | string): NanoSQLInstance

- - Defined in index.ts:379

  Changes the table pointer to a new table.

  memberof

    NanoSQLInstance

  #### Parameters

  - ##### Optional table: undefined | string

  #### Returns NanoSQLInstance

### triggerEvent

- triggerEvent(eventData: DatabaseEvent, triggerEvents: Array<string>): void

- - Defined in index.ts:991

  Trigger a database event

  memberof

    NanoSQLInstance

  #### Parameters

  - ##### eventData: DatabaseEvent

  - ##### triggerEvents: Array<string>

  #### Returns void

### updateORM

- updateORM(action: "add" | "delete" | "drop" | "rebuild" | "set", column?: undefined | string, relationIDs?: any[]): _NanoSQLORMQuery

- - Defined in index.ts:968

  Update relational ORM data.

  memberof

    NanoSQLInstance

  #### Parameters

  - ##### action: "add" | "delete" | "drop" | "rebuild" | "set"

  - ##### Optional column: undefined | string

  - ##### Optional relationIDs: any[]

  #### Returns _NanoSQLORMQuery

### views

- views(viewArray: Array<ActionOrView>): NanoSQLInstance

- - Defined in index.ts:572

  Declare the views for the current selected table. Must be called before connect()

  Views are created like this:

      .views([
       {
           name:"view-name",
           args: ["array","of","arguments"],
           call: function(args) {
               // Because of our "args" array the args input of this function will look like this:
               // NanoSQL will not let any other arguments into this function.
               args:{
                   array:'',
                   of:'',
                   arguments:''
               }
               //We can use them in our query
               return this.query('select').where(['name','IN',args.array]).exec();
           }
       }
      ])

  Then later in your app..

      NanoSQL("users").getView("view-name",{array:'',of:"",arguments:""}).then(function(result) {
       console.log(result) <=== result of your view will be there.
      })

  Optionally you can type cast the arguments at run time typescript style, just add the types after the arguments in the array. Like this:

      .views[{
           name:...
           args:["name:string","balance:float","active:bool"]
           call:...
      }]

  NanoSQL will force the arguments passed into the function to those types.

  Possible types are string, bool, float, int, map, array and bool.

  memberof

    NanoSQLInstance

  #### Parameters

  - ##### viewArray: Array<ActionOrView>

  #### Returns NanoSQLInstance

### Static _hash

- _hash(key: string): number

- - Defined in index.ts:1409

  Utility function for generating numerical hashes from strings.

  internal
  memberof

    _NanoSQLDB

  #### Parameters

  - ##### key: string

  #### Returns number

### Static chain

- chain(callbacks: function[]): function

- - Defined in index.ts:1334

  Chain an array of functions to fire sequentially.

  static
  memberof

    NanoSQLInstance

  #### Parameters

  - ##### callbacks: function[]

    - - (next: function): void

      - #### Parameters

        - ##### next: function

          - - (result?: any): void

            - #### Parameters

              - ##### Optional result: any

              #### Returns void

  #### Returns function

  - - (complete: function): void

    - #### Parameters

      - ##### complete: function

        - - (results: any[]): void

          - #### Parameters

            - ##### results: any[]

            #### Returns void

### Static random16Bits

- random16Bits(): number

- - Defined in index.ts:1309

  #### Returns number

### Static timeid

- timeid(ms?: undefined | true | false): string

- - Defined in index.ts:1369

  Generate a unique, sortable time ID

  static
  memberof

    NanoSQLInstance

  #### Parameters

  - ##### Optional ms: undefined | true | false

  #### Returns string

### Static uuid

- uuid(): string

- - Defined in index.ts:1389

  RFC4122 compliant UUID v4, 9 randomly generated 16 bit numbers.

  static
  memberof

    NanoSQLInstance

  #### Returns string

Generated using TypeDoc