A NodeJS Layer for FoundationDB that provides documents and queries
with similar capabilities to MongoDB but providing support for
multidocument transactions.
Transaction support is an incredile powerful feature that simplifies
server logic and helps avoiding difficult to solve race conditions.
Fowl provides a low level API based on keypaths for describing documents and its
properties following CRUD semantics.
Fowl aims to be a low level document layer that can be used by others to provide
higher level features such as schemas, models, validation, etc.
All asynchronous operations return A+ compliant promises (provided by bluebirdjs).
##Contribute
Do you like Fowl and want to bring it up to the next level? Do not hesitate to
clone the project and start contributing to it! :)
##Install
npm install fowl
##Test
npm test
##Features
Clean API based on promises
Complete transaction support for all available operations.
Supports: create, get, update, remove, and find.
Access of documents and subdocuments seamless due to a keypath based design.
##Roadmap
namespaces
Advanced queries (implement all mongodb query operators)
// Open a foundationDB databasefowl.open();// Create a document (if _id not specify a GUID will be generated)var john = fowl.create('people', { _id: 'john', name: 'John', lastname: 'Smith', balance: 100});var lisa = fowl.create('people', { _id: 'lisa', name: 'Lisa', lastname: 'Jones', balance: 80});// Use transactions to transfer money from one account to anotherfowl.transaction(function(tr){ Promise.all([ tx.get(['people', 'john']), tx.get(['people', 'lisa']) ]).spread(function (john, lisa) { john.balance -= 10; lisa.balance += 10; tr.put(['people', 'john'], john); tr.put(['people', 'lisa'], lisa);}).then(function(){ // We need to wait for the commit to complete since we are finding the // same keypaths. fowl.find('people', {balance: 90}, ['lastname']).then(function(docs){ // docs = [{lastname: 'Jones'}, {lastname: 'Smith'}]
In order to accelerate queries you should use indexes on the most common
fields in a document. Just add indexes specifying a base key path and the
fields to index:
fowl.addIndex('people', ['name', 'balance']);
It is possible to perform more advanced queries using the Query object:
var query = fowl.query('people');query .eql('lastname', 'Andersson') .gt('balance', 15) .lte('balance', 45) .exec(tr).then(function(results){ // results -> array of documents matching the query. })
About atomicity
All CRUD functions are atomic. Meaning that updating or getting a document is
fully atomic and you either update or get a full document or nothing at all.
The transaction object provides this same CRUD operations as atomic operations
spawning multiple documents.
About Key Paths
Key paths are used in fowl to represent the location of some document or
subdocument. It is just an array of strings (or numbers) that maps to a
key or key range inside FoundationDB.
Key paths are more flexible than bucket based collections, as used for example
in mongoDB, since it allows you to specify a document or subdocument in a
generic way.
For example:
// Specify a document for some user in bucket 'people'['people', '60abd640-2d98-11e3-a7d8-bd61eca52c5c']// Specify a location of all the songs in a playlist['playlist', '60af31a0-2d98-11e3-a7d8-bd61eca52c5c', 'songs']
All methods accepting a key path as parameter also accept a string that will just
be converted to an array:
'people' -> ['people']
About the _id property
As in MongoDB, we generate a unique _id property as a primary key for all the
created documents.
This property can be overrided if required by providing it explicitly in the
document object.
It is also possible skip the use of the _id property by just using the put
method directly and never calling create.
transactionBody(transaction) {Function} This method should contain all transaction operations and may return a Promise in which case the commit will take place when that Promise is resolved. returns {Promise} A promise that resolves after the transaction has executed.
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
'Software'), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.