fast and simple sql builder
import { SQL, TABLE, COLUMN, RAW } from '@day1co/fastsql';
const table = 'comment';
const postId = 123;
const monthBefore = 1;
const since = `DATE_SUB(CURRENT_TIMESTAMP, INTERAVAL ${monthBefore} MONTH)`;
const sort = 'likes';
console.log(SQL`
SELECT * FROM ${TABLE(table)}
WHERE
post_id = ${postId} AND
created_at > ${RAW(since)}
ORDER BY
${COLUMN(sort)}
`);
// expected:
// SELECT * FROM `table`
// WHERE
// post_id = 123 AND
// created_at > DATE_SUB(CURRENT_TIMESTAMP, INTERVAL 1 MONTH)
// ORDER BY
// likes
$ npm test
$ npm run build
$ npm start
may the SOURCE be with you...