Created
February 5, 2013 17:42
-
-
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.
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
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