import { escapeSQLiteIdentifier } from "@databases/escape-identifier";
function escapeSQLiteString(str) {
  return `'${str.replace(/'/g, "''")}'`;
}
function inlineValue(value) {
  if (value === null) {
    return "NULL";
  }
  if (typeof value === "string") {
    return escapeSQLiteString(value);
  }
  if (typeof value === "number") {
    return String(value);
  }
  if (typeof value === "boolean") {
    return value ? "1" : "0";
  }
  if (Array.isArray(value)) {
    return escapeSQLiteString(JSON.stringify(value));
  }
  return escapeSQLiteString(JSON.stringify(value));
}
const sqliteInlineFormat = {
  escapeIdentifier: (str) => escapeSQLiteIdentifier(str),
  formatValue: (value) => (
    // undefined is our signal to use a placeholder
    // IMPORTANT. Changing this will break the planner as it will assume `NULL`
    // for constraints!
    value === void 0 ? {
      placeholder: "?",
      value
    } : {
      placeholder: inlineValue(value),
      value: void 0
      // No binding needed since value is inlined
    }
  )
};
function compileInline(sql) {
  return sql.format(sqliteInlineFormat).text;
}
export {
  compileInline
};
//# sourceMappingURL=sql-inline.js.map
