Skip to content

Instantly share code, notes, and snippets.

@juice49
Last active June 7, 2019 16:42
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 juice49/7fbe918b589bba06dd69ba65bfa20f37 to your computer and use it in GitHub Desktop.
Save juice49/7fbe918b589bba06dd69ba65bfa20f37 to your computer and use it in GitHub Desktop.
sql-fns
/* sql-tag
mysql2
minigrate */
// from redux
function compose(...funcs) {
if (funcs.length === 0) {
return arg => arg
}
if (funcs.length === 1) {
return funcs[0]
}
return funcs.reduce((a, b) => (...args) => a(b(...args)))
}
const pipe = (...parts) => parts.join(' ')
const select = (...columns) =>
next => pipe(
`SELECT ${columns.join(', ')}`,
next
)
const from = table =>
next => pipe(
`FROM ${table}`,
next
)
const where = column =>
predicate =>
value =>
next => pipe(
`WHERE ${column} ${predicate} ${value}`,
next
)
console.log(
compose(
select('*'),
from('users'),
where('id')('=')(30)
)()
)
/* console.log(
select(
'*'
)(
from(
'users'
)(
where('id')('=')(30)()
)
)
) */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment