Class: FaunaConnection

FaunaConnection()

A wrapper class for using the faunuDB javascript API

Constructor

new FaunaConnection()

Source:

Methods

create(collection, doc) → {Object}

Creates a document within the named collection given either single doc or an array of documents.
Parameters:
Name Type Description
collection string name of the collection to put the doc into
doc Object the document to put in the database collection
Source:
Returns:
the document that was inserted
Type
Object

createCollection(name) → {Object}

Creates a collection of the given name
Parameters:
Name Type Description
name string A descriptive name for the collection
Source:
Returns:
Reference to collection object
Type
Object

createDB(name) → {Object}

If the client was instantiated using an admin key this will create a database with the given name.
Parameters:
Name Type Description
name string the name to use for the database
Source:
Returns:
Response object with database name and ref
Type
Object

createIndex(name, src, terms, values) → {Object}

Creates an index for use on a collection
Parameters:
Name Type Default Description
name string descriptive name for the index
src string the name of the collection to apply this to
terms Array null the terms to be used for the index
values Array null the values to be used for the index
Source:
Returns:
the index object
Type
Object

createServer(dbName) → {Object}

If the client was instantiated with at least a databse key, this will return a server role for the given named database.
Parameters:
Name Type Description
dbName string the name of the database to create a server for
Source:
Returns:
Response object with database name and ref
Type
Object

createWithCustomID(collection, docs) → {Array}

Given an array of touples [custom id,document] will iterate through and place each into the given collection in the database with the custom id is the 'ref' field for the document.
Parameters:
Name Type Description
collection string name of the collection to put the docs into
docs Array the documents to put in the database collection
Source:
Returns:
an array of the documents put in the database
Type
Array

delete(collection, ref) → {Object}

Destroys a document
Parameters:
Name Type Description
collection string the name of the collection
ref string the ID or ref of the doc
Source:
Returns:
the deleted document
Type
Object

get(collection, ref) → {Object}

Retrieve a document given its ref and collection
Parameters:
Name Type Description
collection string the name of the collection
ref string the ID or ref of the document
Source:
Returns:
the document identified by the query
Type
Object

getAllDocsByIndex(index, options) → {Object}

Provided with an index, returns all matching documents
Parameters:
Name Type Description
index string name of the index
options Object options that may be passed in include: before - ref to document for traversing pagination backward after - ref to document for traversing pagination forward term - a such term to use with a searchable index size - the number of docs to return per page scope - the database ref within which to perform the match
Source:
Returns:
Returns a collection of docs matching the query conditions
Type
Object

getAllRefsByIndex(index, size) → {Array}

Given an index 'all_' with no set terms or values, this will return the refs of all documents in that index.
Parameters:
Name Type Description
index string name of the index to use
size integer number of docs to be returned per page
Source:
Returns:
an array of the refs to the docs within the index
Type
Array

getMatch(index, value) → {Object}

Retrieve the first document that matches the given value of a term used to create the index. For example, if we have an index called "posts_by_title" whose term was set to "title", we can search that index using a value of "My Blog Post" to see if any posts' titles match our value.
Parameters:
Name Type Description
index string name of index to search on
value multiple the value to match on the index term
Source:
Returns:
the first matching document
Type
Object

replace(collection, ref, data) → {Object}

Given the ref and collection this will replace the data of that document whose fields match the given data. Any old fields in the document that are not mentioned in the data param are removed.
Parameters:
Name Type Description
collection string the name of the collection
ref string the ID or ref of the doc
data Object the data to be replace
Source:
Returns:
the updated document
Type
Object

update(collection, ref, data) → {Object}

Given the ref and collection this will update the data of that document.
Parameters:
Name Type Description
collection string the name of the collection
ref string the ID or ref of the doc
data Object the data to be updated
Source:
Returns:
the updated document
Type
Object