Skip to content

Instantly share code, notes, and snippets.

@alexbosworth
Created March 30, 2011 07:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexbosworth/894008 to your computer and use it in GitHub Desktop.
Save alexbosworth/894008 to your computer and use it in GitHub Desktop.
Sdb.prototype.getQueryString = function(query) {
if (!query.domain) throw new Error('no domain specified');
if (!query.fields || !query.fields.length) query.fields = '*';
var str = query.fields.join() + ' from ' + query.domain;
if (query.selectors && query.selectors.length)
str+= ' where ' + query.selectors.join(' intersection ');
if (query.order) str+= ' order by ' + query.order;
if (query.limit) str+= ' limit ' + query.limit;
return str;
}
Sdb.prototype.select = function(query, token) {
if (!query) throw new Error('no query specified');
// can pass a query object with <fields [], domain str, selectors [], limit int, order str>
if (typeof(query) != 'string') query = this.getQueryString(query);
this.params.SelectExpression = 'select ' + query;
if (token) this.params.NextToken = token;
return this.request('Select');
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment