Add an objectToSQL mapper
Wish this would have come to mind sooner. The big pain in the butt with SQL is mapping values for queries in your code. Would be nice to have something like this:
import { databases } from '@joystick.js/node';
const [query, values] = databases.objectToSQL('postgresql', {
column_name: 'VALUE',
column_name2: 'VALUE',
});
postgresql.query(query, values);
So, this function takes an object where the property names are column names and values are whatever. It spits out the query string for the specified database along with an array of values to pass to the DB driver.
Try to find a package to recommend before going ham on this.
This just came to mind again w/ this sketch:
sqlify.table('TABLE_NAME').select({
where: {
'release_date::date': '< NOW()',
'available_until::date': '> NOW()',
'collection_id': 'abc1234'
},
});
sqlify.table('TABLE_NAME')'.update({
set: {},
where: {},
});
sqlify.table('TABLE_NAME').delete({
where: {},
});
Presumption above is that this would create prepared statements so there was no injection vulnerabilities.
Would be most helpful if this generated prepared statements that automated the $1, $2, etc vars. Returns the query and vars so you can run them.
This was added here: https://github.com/cheatcode/joystick/blob/canary/node/src/app/databases/sql.js.
It helps you generate a SQL statement along w/ args. Just needs to be doc'd.