Created
February 12, 2012 20:57
-
-
Save thejh/1810814 to your computer and use it in GitHub Desktop.
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
/** | |
* @private | |
* Query a Schema for a row or rows by example | |
* | |
* @param {object} name name of Schema OR a Schema object | |
* @param {object} example example to query | |
* @param {boolean} single true to return a single row, otherwise all matching rows | |
* @returns {object} A single row matching example, or all matching rows | |
*/ | |
function find(name, example, single, _) { | |
var schema = getSchema(name); | |
name = schema.name; | |
example = example || {}; | |
var where = Schema.where(name, example); | |
var query = [ | |
'SELECT', | |
' *', | |
'FROM', | |
' ' + name | |
]; | |
if (where.length) { | |
query.push('WHERE'); | |
query.push(where.join(' AND ')); | |
} | |
if (single) { | |
var ret = SQL.getDataRow(query, _); | |
return empty(ret) ? false : Schema.onLoad(schema, ret); | |
} | |
else { | |
return Schema.onLoad(schema, SQL.getDataRows(query, _)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment