Skip to content

Instantly share code, notes, and snippets.

@marcuswestin
Created February 5, 2013 17:42
Show Gist options
  • Save marcuswestin/4716160 to your computer and use it in GitHub Desktop.
Save marcuswestin/4716160 to your computer and use it in GitHub Desktop.
javascript to generate sql strings with appropriately named aliased for each selected property.
function selectFrom(table, props) {
return 'SELECT ' + joinProperties(props) + ' FROM ' + table + '\n'
function joinProperties(props) {
return ' '+map(props, function(rawName, prettyName) {
return rawName+' as '+prettyName
}).join(', ')+' '
}
}
selectFrom('person p', {
fullName: 'p.full_name',
bestFriendFullName: 'bff.full_name'
}) + ' INNER JOIN best_friend_forever bff'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment