-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CLosed #10: Builds adaptable database layer.
- Loading branch information
Jackson Gariety
committed
Feb 16, 2014
1 parent
12a3b31
commit 506b470
Showing
11 changed files
with
144 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/*! | ||
* | ||
* A localStorage database adapter for Sara | ||
*/ | ||
|
||
var _ = require('../sara/utils') | ||
|
||
module.exports = function adapterLocalStorage(Constructor, callback) { | ||
callback({ | ||
find: function (query, callback) { | ||
if (callback) { | ||
var bootstrap = document.querySelectorAll('[type="text/json"]') | ||
callback(null, _.retrocycle(JSON.parse(bootstrap[0].innerHTML))) | ||
} | ||
} | ||
|
||
, insert: function (props, callback) { | ||
if (callback) callback(null, []) | ||
} | ||
|
||
, remove: function (query, callback) { | ||
if (callback) callback(null, []) | ||
} | ||
|
||
, update: function (query, update, options, callback) { | ||
if (callback) callback(null, []) | ||
} | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/*! | ||
* | ||
* MONGODB SARA ADAPTER | ||
* | ||
*/ | ||
|
||
var MongoClient = require('mongodb').MongoClient | ||
|
||
module.exports = function (Constructor, callback) { | ||
MongoClient.connect('mongodb://127.0.0.1:27017/' + Constructor.name, function (err, db) { | ||
if (err) throw err | ||
var collection = db.collection(Constructor.name) | ||
|
||
callback({ | ||
find: function (query, callback) { | ||
if (callback) { | ||
collection.find(query, function (err, docs) { | ||
if (err) callback(err, null) | ||
else { | ||
docs.toArray(function (err, docs) { | ||
callback(err, docs) | ||
}) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
, insert: function (props, callback) { | ||
if (callback) collection.insert(props, function (err, docs) { | ||
callback(err, docs) | ||
}) | ||
} | ||
|
||
, remove: function (query, callback) { | ||
if (callback) collection.remove(query, {}, callback) | ||
} | ||
|
||
, update: function (query, update, options, callback) { | ||
if (callback) collection.update(query, update, options, function (err) { | ||
if (err) throw err | ||
}) | ||
} | ||
}) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/*! | ||
* SARA-NEDB ADAPTER | ||
*/ | ||
|
||
var NeDB = require('nedb') | ||
|
||
module.exports = function (Constructor) { | ||
return new NeDB({ filename: Constructor.app.root + '/' + Constructor.name.toLowerCase() + '.db', autoload: true }) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters