Constructor
new IndexedWDWDB(opts)
- Description:
- Construct a new IndexedWDWDB object
- Source:
Parameters:
Name |
Type |
Description |
opts |
object
|
PouchDB options object
Properties
Name |
Type |
Attributes |
Default |
Description |
remoteHost |
string
|
<optional>
|
|
Remote database to replicate |
remoteUsername |
string
|
<optional>
|
|
Remote database username to authenticate |
remotePassword |
string
|
<optional>
|
|
Remote database password to authenticate |
dbName |
string
|
<optional>
|
'wdw'
|
Local database name |
snapshot |
string
|
<optional>
|
|
File location of a snapshot to 'seed' the database during startup |
skipSync |
string
|
<optional>
|
|
Skip network replication, only use data already on disk |
|
Extends
Classes
- IndexedWDWDB
Methods
(async, private) _createIndex(name, defaultIndex)
- Description:
- Create an index object to be used by this database
- Source:
Parameters:
Name |
Type |
Description |
name |
string
|
Index name |
defaultIndex |
*
|
Index initial object state |
(async, private) _createIndexes()
- Description:
- Source:
- Description:
- Given a WDW database document, try to return its language
- Source:
Parameters:
Name |
Type |
Description |
doc |
object
|
|
Returns:
Language of this document. Eg. en_intl, en_us
-
Type
-
string
- Description:
- Given a WDW document, extract key identifiable data
This is used to build a look-up index of unique document types
See ancestorIndexes for some of the keys we use
This is important so we can tell the difference between entities with the same ID, but different purposes
eg. an entity ID can have multiple documents, one for the attraction itself, one for it's wait times, etc.
These need to both be in the index under the same entity ID, but with different properties to make them distinct
- Source:
Parameters:
Name |
Type |
Description |
doc |
object
|
WDW Database Document |
Returns:
Index object containing important identifying data
-
Type
-
object
(async, private) _indexWDWDocument(doc)
- Description:
- Add a document to the database index
Used for fast lookups of entities etc. to the correct documents
- Source:
Parameters:
Name |
Type |
Description |
doc |
object
|
CouchDB document to index |
(async, private) _initIndexes()
- Description:
- Index initialisation
This function wraps taking care of creating our indexes once only
- Source:
(async, private) _loadAndInit()
- Description:
- Internal function
Loads and performs an initial sync on the database
- Source:
_removeFromArrayIndex(index, docID)
- Description:
- Remove all indexes referencing docID from the given index
- Source:
Parameters:
Name |
Type |
Description |
index |
object
|
|
docID |
string
|
|
(private) _replicate()
- Description:
- Start database replication
- Source:
(async) find(filteropt) → {array.<object>}
- Description:
- Return all documents in the database that match the given filter
This is a slow operation! Use sparingly!
- Source:
Parameters:
Name |
Type |
Attributes |
Description |
filter |
object
|
<optional>
|
|
Returns:
-
Type
-
array.<object>
(async) getByChannel(channel, filteropt) → {array.<object>}
- Description:
- Find all documents by channel
eg. 'wdw.facilitystatus.1_0' to get all WDW facility status documents
- Source:
Parameters:
Name |
Type |
Attributes |
Description |
channel |
string
|
|
Channel ID |
filter |
object
|
<optional>
|
Optional document index filter |
Returns:
All documents in this channel (or empty array)
-
Type
-
array.<object>
(async) getDocChildren(id)
- Description:
- Return an array of children document IDs for a given entity ID
- Source:
Parameters:
Name |
Type |
Description |
id |
string
|
|
(async) getDocNameSearch(name)
- Description:
- Very rudementary text search for documents matching the incoming name.
name argument will be stripped of all non-alphanumeric characters for searching.
Will return an array of document IDs with matching name substrings.
- Source:
Parameters:
Name |
Type |
Description |
name |
string
|
|
(async) getDocsById(ids)
- Description:
- Get an array of documents from an array of _id
- Source:
Parameters:
Name |
Type |
Description |
ids |
array.<string>
|
|
getDumpFilename(postfixopt) → {string}
- Description:
- Get the filename we use for saving backups of the database to disk
Used for creating simple "snapshots" to reduce initial sync times
- Source:
Parameters:
Name |
Type |
Attributes |
Description |
postfix |
string
|
<optional>
|
Optional postfix for the filename
eg. Use postfix to generate a temporary version of a file to write to before replacing the "real" database |
Returns:
-
Type
-
string
(async) getEntity(id, filteropt) → {array.<object>}
- Description:
- Search for an entity in the WDW database
- Source:
Parameters:
Name |
Type |
Attributes |
Description |
id |
string
|
|
Entity ID |
filter |
object
|
<optional>
|
Filter index by field |
Returns:
Returns all documents for this entity ID
-
Type
-
array.<object>
(async) getEntityIndex(id, filteropt) → {array.<object>}
- Description:
- Find search index entries by ID
If you want the actual document and not just the meta-index data, use getEntity() instead
- Source:
Parameters:
Name |
Type |
Attributes |
Description |
id |
string
|
|
|
filter |
object
|
<optional>
|
|
Returns:
Returns the index data for this entity ID
-
Type
-
array.<object>
(async) getEntityOne(id, filteropt) → {object}
- Description:
- Search for an entity in the WDW database
Attempts to return the "best candidate" single document that matches the incoming ID
- Source:
Parameters:
Name |
Type |
Attributes |
Description |
id |
string
|
|
Entity ID |
filter |
object
|
<optional>
|
Optional index filter |
Returns:
Returns the best candidate single document, or undefined
-
Type
-
object
(async) getFacilityStatus(id) → {object}
- Description:
- Get the live facility status for a given entity ID
- Source:
Parameters:
Name |
Type |
Description |
id |
string
|
Entity ID |
Returns:
Facility status document, or undefined
-
Type
-
object
(private) getIndex(name) → {*}
- Description:
- Get the internal index object for the given index type
- Source:
Parameters:
Name |
Type |
Description |
name |
object
|
Index name (see constants.INDEX_*) |
Returns:
-
Type
-
*
(async) init()
- Description:
- Initialise the live database, returns once finished an initial sync
- Source:
(async) loadSnapshot(snapshotFileopt)
- Description:
- Restore a database backup from disk
Perform this after running "dump()" on a previous synced database
This will help to reduce the initial sync time for large databases
- Source:
Parameters:
Name |
Type |
Attributes |
Description |
snapshotFile |
string
|
<optional>
|
File path of the snapshot to restore into the database
snapshotFile will use default saveSnapshot result location if not supplied |
(async) saveSnapshot() → {string}
- Description:
- Save a snapshot of this live database to disk
This will be used to "seed" the database to speed up syncs for future runs
- Source:
Returns:
Path to resulting database snapshot
-
Type
-
string
subscribeToChanges(filteropt, callback)
- Description:
- Subscribe to all database changes with an optional mongo-style filter
- Source:
Parameters:
Name |
Type |
Attributes |
Description |
filter |
object
|
<optional>
|
|
callback |
function
|
|
|
subscribeToChannel(channel, callback)
- Description:
- Subscribe to all changes to a channel
- Source:
Parameters:
Name |
Type |
Description |
channel |
string
|
|
callback |
function
|
|
(async, private, static) _pluginBulkDocs(…args)
- Description:
- Plugin function to intercept bulkDocs function
We index any WDW documents we find for easier lookup later
- Source:
Parameters:
Name |
Type |
Attributes |
Description |
args |
any
|
<repeatable>
|
bulkDocs in |
(static) getDatabaseFilePath(name) → {string}
- Description:
- Get the LevelDOWN database location to use
- Source:
Parameters:
Name |
Type |
Description |
name |
string
|
Database name |
Returns:
-
Type
-
string