Created
December 10, 2010 21:35
-
-
Save dandean/736866 to your computer and use it in GitHub Desktop.
Random idea around extending riak-js to support automatic prefixing of bucket names. Could come in handy for a riak database in use by multiple applications.
This file contains hidden or 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
| var riakClient = require("riak-js/client"); | |
| var riakHttpClient = require("riak-js/http_client"); | |
| riakClient.prototype.bucketPrefix = ""; | |
| riakClient.prototype.getBucketName = function(name) { | |
| var prefix = ""; | |
| if (this.bucketPrefix) prefix = this.bucketPrefix + "_"; | |
| return prefix + name; | |
| }; | |
| var oldGet = riakHttpClient.prototype.get; | |
| riakHttpClient.prototype.get = function(bucket, key) { | |
| var options = Array.prototype.slice.call(arguments, 2); | |
| var args = [this.getBucketName(bucket), key]; | |
| return oldGet.apply(this, [this.getBucketName(bucket), key, options.map(args.push)]); | |
| }; | |
| var db = require('riak-js').getClient({ | |
| host: "127.0.0.1", | |
| port: 8091 | |
| }); | |
| db.bucketPrefix = "!!!"; | |
| console.log(db.get("stuff", "things")); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment