sequelts
sequelts copied to clipboard
Support ES Tagged Template Function
Basically, we want to create a function that does this: https://www.npmjs.com/package/sql-template-strings
Current API:
const getSingle = createQuerySingleFunction((q, ...p) => db.prepare(q).get(...p), databaseSchema);
const a = getSingle("SELECT name FROM user WHERE id = ?", 1);
What we want to have:
const get = createQuerySingleTagFunction((q, ...p) => db.prepare(q).get(...p), databaseSchema);
// (or just the function without the database wrapping)
const a = get`SELECT name FROM user WHERE id = ${1}`;
If the user names the function SQL instead of get, the keywords are also highlighted, improving the DX. Whether this is a good idea is a different story.
Additional benefits:
- If the columns in the
WHEREclause are also returned in theSELECT, we maybe could use the type of the bound parameter to infer the type of the column.
Solutions:
- Re-Implement
sql-template-strings(it's about 90 lines and uses legacy stuff likearguments(src)) - Have
sql-template-stringsas a dependency and provide finer types