Created
March 28, 2017 16:53
-
-
Save charmander/8f7b05f8d2b2e4e3c190c7a9e1bec1f2 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
class Query { | |
constructor(text, values) { | |
this.text = text; | |
this.values = values; | |
} | |
} | |
const sql = (parts, ...values) => { | |
let text = parts[0]; | |
for (let i = 1; i < parts.length; i++) { | |
text += '$' + i + parts[i]; | |
} | |
return new Query(text, values); | |
}; | |
const query = q => { | |
if (!(q instanceof Query)) { | |
throw new TypeError('query must be a Query object'); | |
} | |
return db.query(q); | |
}; | |
query(sql`INSERT INTO t (c) VALUES (${'safe'})`); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment