Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
fauna client library for javascript
CoffeeScript Ruby
tree: e291bed1b5

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
src
test
.gitignore
Cakefile
LICENSE.txt
README.md
package.json

README.md

fauna-js

This is a client library for using the fauna service (https://fauna.org).

It's written in coffeescript and node, but it compiles to javascript, and is explicitly written to work in (modern) browsers. It does this primarily by using the 'request' library (https://npmjs.org/package/request) for HTTP inside node, and 'browser-request' (https://npmjs.org/package/browser-request) inside a browser.

All API calls use the standard Q futures library (https://npmjs.org/package/q).

The packaging assumes you use browserify, or something very similar.

Usage

This library is currently incomplete, and only implements the features I need for the redpanda project. I intend to end up with a complete implementation of the fauna v1 API, so please file an issue or contact me (Twitter & email below) if you have suggestions, bug reports, or patches.

Fauna works with "classes" and "instances" which should map to "models" and "objects" in your app. To define a model, describe a schema with the fields you intend to store in the database, and mark each field as being data or a reference:

fauna = require("fauna-js")

Schema = {
  messages: {
    author: fauna.Reference,
    body: fauna.Data
  }
  users: {
    email: fauna.Data
  }
}

When decoding objects from the fauna servers, items with class "messages" will be decoded from a json object like this:

"classes/messages/29192553537470464": {
  "ref" : "classes/messages/29192553537470464",
  "class" : "classes/messages",
  "ts" : 1364099038540000,
  "references": {
    "author" : "users/29183911200292864"
  },
  "data" : {
    "body" : "meet me on bernal hill!"
  }
}

to an object like this:

{ 
  meta: {
    id: "classes/messages/29192553537470464",
    className: "messages",
    ts: Sat Mar 23 2013 21:23:58 GMT-0700 (PDT)
  },
  author: {
    meta: { ... },
    email: "robey@example.com"
  },
  body: "meet me on bernal hill!"
}

License

Apache 2 license, included in 'LICENSE.txt'.

Authors

@robey - Robey Pointer robeypointer@gmail.com

Something went wrong with that request. Please try again.