# Class: Db

## Db

#### new Db()

Creates a new ForerunnerDB database instance.

Source:
  - Db.js, line 16

### Methods

- (static) collection(collectionName, primaryKey) → {Collection}
- (static) collection(collectionName, primaryKey, options) → {Collection}
- (static) collection(data) → {Collection}
- (static) collection(collectionName, options) → {Collection}
- (static) collection(collectionName) → {Collection}
- (static) collection() → {Collection}
- (static) collectionGroup(name) → {*}
- (static) document() → {Document}
- (static) document(data) → {Document}
- (static) document(documentName) → {Document}
- (static) document(documentName, options) → {Document}
- (static) documents() → {Array}
- (static) drop(callback)
- (static) drop()
- (static) drop(removePersist)
- (static) drop(removePersist, callback)
- (static) grid(selector, template, optionsopt) → {*}
- (static) gridExists(selector) → {boolean}
- (static) grids() → {Array}
- (static) load(callbackopt)
- (static) load(myData, callback)
- (static) moduleLoaded(moduleName) → {Boolean}
- (static) moduleLoaded(moduleName, callback)
- (static) moduleLoaded(moduleName, success, failure)
- (static) save(options, callback)
- (static) save(callbackopt)
- (static) unGrid(selector, template, optionsopt) → {*}
- arrayToCollection(arr) → {Collection}
- collectionExists(viewName) → {boolean}
- collectionGroups() → {Array}
- collections(search) → {Array}
- isClient() → {boolean}
- isClient() → {Boolean}
- isServer() → {boolean}
- isServer() → {Boolean}
- load(callbackopt)
- oldView(viewName) → {*}
- oldViewExists(viewName) → {boolean}
- oldViews() → {Array}
- overview(name) → {*}
- overviews() → {Array}
- peek(search) → {Array}
- peek(event, dataopt) → {*}
- peekCat(search) → {Object}
- persistedSize(callback)
- procedure(name, methodopt) → {*}
- save(callbackopt)
- sectionEnter()
- sectionLeave()
- version(val, callback) → {Boolean}
- view(name) → {*}
- viewExists(name) → {boolean}
- views() → {Array}

#### (static) collection(collectionName, primaryKey) → {Collection}

Get a collection by name. If the collection does not already exist then one is created for that name automatically.

##### Parameters:

Name | Type | Description
--- | --- | ---
`collectionName` | String | The name of the collection.
`primaryKey` | String | Optional primary key to specify the primary key field on the collection objects. Defaults to "_id".

Source:
  - Collection.js, line 3817

##### Returns:

Type
  Collection

#### (static) collection(collectionName, primaryKey, options) → {Collection}

Get a collection by name. If the collection does not already exist then one is created for that name automatically.

##### Parameters:

Name | Type | Description
--- | --- | ---
`collectionName` | String | The name of the collection.
`primaryKey` | String | Optional primary key to specify the primary key field on the collection objects. Defaults to "_id".
`options` | Object | An options object.

Source:
  - Collection.js, line 3853

##### Returns:

Type
  Collection

#### (static) collection(data) → {Collection}

Get a collection by name. If the collection does not already exist then one is created for that name automatically.

##### Parameters:

Name | Type | Description
--- | --- | ---
`data` | Object | An options object or a collection instance.

Source:
  - Collection.js, line 3776

##### Returns:

Type
  Collection

#### (static) collection(collectionName, options) → {Collection}

Get a collection by name. If the collection does not already exist then one is created for that name automatically.

##### Parameters:

Name | Type | Description
--- | --- | ---
`collectionName` | String | The name of the collection.
`options` | Object | An options object.

Source:
  - Collection.js, line 3836

##### Returns:

Type
  Collection

#### (static) collection(collectionName) → {Collection}

Get a collection by name. If the collection does not already exist then one is created for that name automatically.

##### Parameters:

Name | Type | Description
--- | --- | ---
`collectionName` | String | The name of the collection.

Source:
  - Collection.js, line 3801

##### Returns:

Type
  Collection

#### (static) collection() → {Collection}

Get a collection with no name (generates a random name). If the collection does not already exist then one is created for that name automatically.

Source:
  - Collection.js, line 3760

##### Returns:

Type
  Collection

#### (static) collectionGroup(name) → {*}

Creates a new collectionGroup instance or returns an existing instance if one already exists with the passed name.

##### Parameters:

Name | Type | Description
--- | --- | ---
`name` | String | The name of the instance.

Source:
  - CollectionGroup.js, line 307

##### Returns:

Type
  *

#### (static) document() → {Document}

Get a document with no name (generates a random name). If the document does not already exist then one is created for that name automatically.

Source:
  - Document.js, line 481

##### Returns:

Type
  Document

#### (static) document(data) → {Document}

Get a document by name. If the document does not already exist then one is created for that name automatically.

##### Parameters:

Name | Type | Description
--- | --- | ---
`data` | Object | An options object or a document instance.

Source:
  - Document.js, line 497

##### Returns:

Type
  Document

#### (static) document(documentName) → {Document}

Get a document by name. If the document does not already exist then one is created for that name automatically.

##### Parameters:

Name | Type | Description
--- | --- | ---
`documentName` | String | The name of the document.

Source:
  - Document.js, line 522

##### Returns:

Type
  Document

#### (static) document(documentName, options) → {Document}

Get a document by name. If the document does not already exist then one is created for that name automatically.

##### Parameters:

Name | Type | Description
--- | --- | ---
`documentName` | String | The name of the document.
`options` | Object | An options object.

Source:
  - Document.js, line 538

##### Returns:

Type
  Document

#### (static) documents() → {Array}

Returns an array of documents the DB currently has.

Source:
  - Document.js, line 598

##### Returns:

An array of objects containing details of each document the database is currently managing.

Type
  Array

#### (static) drop(callback)

Drops the database with optional callback method.

##### Parameters:

Name | Type | Description
--- | --- | ---
`callback` | function | Optional callback method.

Source:
  - Db.js, line 403

#### (static) drop()

Drops the database.

Source:
  - Db.js, line 376

#### (static) drop(removePersist)

Drops the database with optional persistent storage drop. Persistent storage is dropped by default if no preference is provided.

##### Parameters:

Name | Type | Description
--- | --- | ---
`removePersist` | Boolean | Drop persistent storage for this database.

Source:
  - Db.js, line 440

#### (static) drop(removePersist, callback)

Drops the database and optionally controls dropping persistent storage and callback method.

##### Parameters:

Name | Type | Description
--- | --- | ---
`removePersist` | Boolean | Drop persistent storage for this database.
`callback` | function | Optional callback method.

Source:
  - Db.js, line 469

#### (static) grid(selector, template, optionsopt) → {*}

Creates a grid based on the passed arguments.

##### Parameters:

Name | Type | Attributes | Description
--- | --- | --- | ---
`selector` | String |  | The jQuery selector of the grid to retrieve.
`template` | String |  | The table template to use when rendering the grid.
`options` | Object | <optional> | The options object to apply to the grid.

Source:
  - Grid.js, line 695

##### Returns:

Type
  *

#### (static) gridExists(selector) → {boolean}

Determine if a grid with the passed name already exists.

##### Parameters:

Name | Type | Description
--- | --- | ---
`selector` | String | The jQuery selector to bind the grid to.

Source:
  - Grid.js, line 684

##### Returns:

Type
  boolean

#### (static) grids() → {Array}

Returns an array of grids the DB currently has.

Source:
  - Grid.js, line 735

##### Returns:

An array of objects containing details of each grid the database is currently managing.

Type
  Array

#### (static) load(callbackopt)

Loads an entire database's data from persistent storage.

##### Parameters:

Name | Type | Attributes | Description
--- | --- | --- | ---
`callback` | function | <optional> | The method to call when the load function has completed.

Source:
  - Persist.js, line 947

#### (static) load(myData, callback)

Loads an entire database's data from persistent storage.

##### Parameters:

Name | Type | Description
--- | --- | ---
`myData` | Object | Custom data to load into the collection.
`callback` | function | The method to call when the load function has completed.

Source:
  - Persist.js, line 958

#### (static) moduleLoaded(moduleName) → {Boolean}

Checks if a module has been loaded into the database.

##### Parameters:

Name | Type | Description
--- | --- | ---
`moduleName` | String | The name of the module to check for.

Source:
  - Db.js, line 31

##### Returns:

True if the module is loaded, false if not.

Type
  Boolean

#### (static) moduleLoaded(moduleName, callback)

Checks if a module is loaded and if so calls the passed callback method.

##### Parameters:

Name | Type | Description
--- | --- | ---
`moduleName` | String | The name of the module to check for.
`callback` | function | The callback method to call if module is loaded.

Source:
  - Db.js, line 57

#### (static) moduleLoaded(moduleName, success, failure)

Checks if a module is loaded and if so calls the passed success method, otherwise calls the failure method.

##### Parameters:

Name | Type | Description
--- | --- | ---
`moduleName` | String | The name of the module to check for.
`success` | function | The callback method to call if module is loaded.
`failure` | function | The callback method to call if module not loaded.

Source:
  - Db.js, line 82

#### (static) save(options, callback)

Saves an entire database's data to persistent storage.

##### Parameters:

Name | Type | Description
--- | --- | ---
`options` | Object | The options object.
`callback` | function | The method to call when the save function has completed.

Source:
  - Persist.js, line 1025

#### (static) save(callbackopt)

Saves an entire database's data to persistent storage.

##### Parameters:

Name | Type | Attributes | Description
--- | --- | --- | ---
`callback` | function | <optional> | The method to call when the save function has completed.

Source:
  - Persist.js, line 1014

#### (static) unGrid(selector, template, optionsopt) → {*}

Removes a grid based on the passed arguments.

##### Parameters:

Name | Type | Attributes | Description
--- | --- | --- | ---
`selector` | String |  | The jQuery selector of the grid to retrieve.
`template` | String |  | The table template to use when rendering the grid.
`options` | Object | <optional> | The options object to apply to the grid.

Source:
  - Grid.js, line 715

##### Returns:

Type
  *

#### arrayToCollection(arr) → {Collection}

Converts a normal javascript array of objects into a DB collection.

##### Parameters:

Name | Type | Description
--- | --- | ---
`arr` | Array | An array of objects.

Source:
  - Db.js, line 226

##### Returns:

A new collection instance with the data set to the array passed.

Type
  Collection

#### collectionExists(viewName) → {boolean}

Determine if a collection with the passed name already exists.

##### Parameters:

Name | Type | Description
--- | --- | ---
`viewName` | String | The name of the collection to check for.

Source:
  - Collection.js, line 3936

##### Returns:

Type
  boolean

#### collectionGroups() → {Array}

Returns an array of collection groups the DB currently has.

Source:
  - CollectionGroup.js, line 344

##### Returns:

An array of objects containing details of each collection group the database is currently managing.

Type
  Array

#### collections(search) → {Array}

Returns an array of collections the DB currently has.

##### Parameters:

Name | Type | Description
--- | --- | ---
`search` | String | RegExp | The optional search string or regular expression to use to match collection names against.

Source:
  - Collection.js, line 3948

##### Returns:

An array of objects containing details of each collection the database is currently managing.

Type
  Array

#### isClient() → {boolean}

Returns true if ForerunnerDB is running on a client browser.

Source:
  - Db.js, line 190

##### Returns:

Type
  boolean

#### isClient() → {Boolean}

Checks if the database is running on a client (browser) or a server (node.js).

Source:
  - Db.js, line 207

##### Returns:

Returns true if running on a browser.

Type
  Boolean

#### isServer() → {boolean}

Returns true if ForerunnerDB is running on a server.

Source:
  - Db.js, line 198

##### Returns:

Type
  boolean

#### isServer() → {Boolean}

Checks if the database is running on a client (browser) or a server (node.js).

Source:
  - Db.js, line 216

##### Returns:

Returns true if running on a server.

Type
  Boolean

#### load(callbackopt)

Loads an entire database's data from persistent storage.

##### Parameters:

Name | Type | Attributes | Description
--- | --- | --- | ---
`callback` | function | <optional> | The method to call when the load function has completed.

Source:
  - NodePersist.js, line 666

#### oldView(viewName) → {*}

Gets a view by it's name.

##### Parameters:

Name | Type | Description
--- | --- | ---
`viewName` | String | The name of the view to retrieve.

Source:
  - OldView.js, line 662

##### Returns:

Type
  *

#### oldViewExists(viewName) → {boolean}

Determine if a view with the passed name already exists.

##### Parameters:

Name | Type | Description
--- | --- | ---
`viewName` | String | The name of the view to check for.

Source:
  - OldView.js, line 678

##### Returns:

Type
  boolean

#### oldViews() → {Array}

Returns an array of views the DB currently has.

Source:
  - OldView.js, line 687

##### Returns:

An array of objects containing details of each view the database is currently managing.

Type
  Array

#### overview(name) → {*}

Create an overview instance from a Db instance.

##### Parameters:

Name | Type | Description
--- | --- | ---
`name` | String | The name of the overview.

Source:
  - Overview.js, line 310

##### Returns:

Type
  *

#### overviews() → {Array}

Returns an array of overviews the DB currently has.

Source:
  - Overview.js, line 340

##### Returns:

An array of objects containing details of each overview the database is currently managing.

Type
  Array

#### peek(search) → {Array}

Find all documents across all collections in the database that match the passed string or search object.

##### Parameters:

Name | Type | Description
--- | --- | ---
`search` |  | String or search object.

Source:
  - Db.js, line 315

##### Returns:

Type
  Array

#### peek(event, dataopt) → {*}

Emits an event by name with the given data.

##### Parameters:

Name | Type | Attributes | Description
--- | --- | --- | ---
`event` | String |  | The name of the event to emit.
`data` | * | <optional> | The data to emit with the event.

Source:
  - Db.js, line 287

##### Returns:

Type
  *

#### peekCat(search) → {Object}

Find all documents across all collections in the database that match the passed string or search object and return them in an object where each key is the name of the collection that the document was matched in.

##### Parameters:

Name | Type | Description
--- | --- | ---
`search` |  | String or search object.

Source:
  - Db.js, line 344

##### Returns:

Type
  Object

#### persistedSize(callback)

Determines the byte size of a persisted DB

##### Parameters:

Name | Type | Description
--- | --- | ---
`callback` | persistedSizeCallback | The method to call when the size check is complete

Source:
  - Persist.js, line 1088

#### procedure(name, methodopt) → {*}

Create or retrieve a procedure by name.

##### Parameters:

Name | Type | Attributes | Description
--- | --- | --- | ---
`name` | String |  | The name of the procedure.
`method` | function | <optional> | If specified, creates a new procedure with the provided name and method.

Source:
  - Procedure.js, line 72

##### Returns:

Type
  *

#### save(callbackopt)

Saves an entire database's data to persistent storage.

##### Parameters:

Name | Type | Attributes | Description
--- | --- | --- | ---
`callback` | function | <optional> | The method to call when the save function has completed.

Source:
  - NodePersist.js, line 711

#### sectionEnter()

Denotes a section has been entered. All instances created after this call will be assigned to this "section".

Source:
  - Section.js, line 55

#### sectionLeave()

Denotes a section has been left. All instances that were created during the section lifespan will be automatically dropped.

Source:
  - Section.js, line 66

#### version(val, callback) → {Boolean}

Checks version against the string passed and if it matches (or partially matches) then the callback is called.

##### Parameters:

Name | Type | Description
--- | --- | ---
`val` | String | The version to check against.
`callback` | function | The callback to call if match is true.

Source:
  - Db.js, line 117

##### Returns:

Type
  Boolean

#### view(name) → {*}

Gets a view by it's name.

##### Parameters:

Name | Type | Description
--- | --- | ---
`name` | String | The name of the view to retrieve.

Source:
  - View.js, line 1525

##### Returns:

Type
  *

#### viewExists(name) → {boolean}

Determine if a view with the passed name already exists.

##### Parameters:

Name | Type | Description
--- | --- | ---
`name` | String | The name of the view to check for.

Source:
  - View.js, line 1553

##### Returns:

Type
  boolean

#### views() → {Array}

Returns an array of views the DB currently has.

Source:
  - View.js, line 1562

##### Returns:

An array of objects containing details of each view the database is currently managing.

Type
  Array