npm.io
1.0.0 • Published 5 years ago

faunadb-wrap

Licence
MIT
Version
1.0.0
Deps
1
Size
20 kB
Vulns
0
Weekly
0

faunadb-wrap

Another Node.js wrapper to interact with FaunaDB

Install

npm install faunadb-wrap

Usage

Create collections
await fauna.createCollection('my_collection');

Delete collections

await fauna.deleteCollection('my_collection');
Create indexes
// create an index called "index_name"
await fauna.createIndex('my_collection', 'index_name');

// create index with terms
await fauna.createIndex('customers', 'index_with_terms', {
  terms: [{ field: ['data', 'firstName'] }]
});

// create index with field firstName unique
await fauna.createIndex('customers', 'index_unique', {
  terms: [{ field: ['data', 'firstName'] }],
  unique: true
});
Delete indexes
await fauna.deleteIndex('index_name');
Create documents
await fauna.createDocument('customers', {
  firstName: 'John',
  lastName: 'Smith',
  age: 40
});
Retrieve documents
const documents = await fauna.retrieveDocuments('customers');
console.log(documents);             // PRINT ALL DOCUMENTS
console.log(documents[0]);          // PRINT FIRST DOCUMENT
console.log(documents[0].data);     // PRINT DOCUMENT FIELDS
Update document
// Update firstName, age and add tags
await fauna.updateDocument('customers', '291699840069403141', {
  firstName: 'Peter',
  age: 41,
  tags: ['customer', 'financial']
});

// Remove tags property
await fauna.updateDocument('customers', '291699840069403141', {
  tags: null
});
Delete document
await fauna.deleteDocument('customers', '291699840069403141');