💾 Archived View for iich.space › src › db › sql.ts captured on 2021-12-03 at 14:04:38.

View Raw

More Information

-=-=-=-=-=-=-

import { Statement } from 'better-sqlite3';

import db from '.';

export const sql = <T extends Array<unknown> = []>(
  literals: TemplateStringsArray,
  ...placeholders: Array<string>
): Statement<T> => {
  let string = '';

  for (let n = 0; n < placeholders.length; n += 1) {
    string += literals[n];
    string += placeholders[n];
  }

  string += literals[literals.length - 1];

  return db.prepare<T>(string);
};