Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit a7d0e83
Showing
2 changed files
with
48 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
var simpledb = require('node-simpledb'); | ||
|
||
module.exports = function(settings) { | ||
var sdb = new simpledb.SimpleDB({keyid: settings.aws_key, secret: settings.aws_secret}); | ||
sdb.createDomain(settings.simpledb_domain, function(err) { | ||
if (err) throw err; | ||
}); | ||
|
||
// Helper function to get a URL from a Model or Collection as a property | ||
// or as a function. | ||
var getUrl = function(object) { | ||
if (object.url instanceof Function) { | ||
return object.url(); | ||
} else if (typeof object.url === 'string') { | ||
return object.url; | ||
} | ||
}; | ||
|
||
return { | ||
sync: function(method, model, success, error) { | ||
switch (method) { | ||
case 'read': | ||
var data, | ||
base = getUrl(model); | ||
if (model.id) { | ||
sdb.getItem(settings.simpledb_domain, base, function(err, data) { | ||
return data ? success(data) : error('Model not found.'); | ||
}); | ||
} else { | ||
return error('Not supported yet.'); | ||
} | ||
break; | ||
case 'create': | ||
case 'update': | ||
sdb.putItem( | ||
settings.simpledb_domain, | ||
getUrl(model), | ||
model.toJSON(), | ||
function(err) { | ||
return err ? error(err) : success({}); | ||
} | ||
); | ||
break; | ||
} | ||
} | ||
} | ||
} |
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 @@ | ||
module.exports = require('./backbone-simpledb'); |