Skip to content

day1co/fastsql

Repository files navigation

fastsql

fast and simple sql builder

version

Getting Started

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

Contributing

test

$ npm test

build

$ npm run build

watch(continuous build)

$ npm start

may the SOURCE be with you...