diff --git a/src/flavors/sqlite.ts b/src/flavors/sqlite.ts new file mode 100644 index 0000000..07dd657 --- /dev/null +++ b/src/flavors/sqlite.ts @@ -0,0 +1,22 @@ +import { ExpressionBase, FunctionExpression } from "../Expression"; +import { MySQLFlavor } from "./mysql"; + +export class SQLiteFlavor extends MySQLFlavor { + // protected columnQuotes: string = "'" + protected stringQuotes: string = "'"; + escapeFunction(fn: FunctionExpression): string { + const args = fn.value + .map((arg) => ExpressionBase.deserialize(arg).toSQL(this)) + .join(", "); + if (fn.name === "MONTH") { + return `strftime('%m', ${args}, 'localtime')`; + } + if (fn.name === "YEAR") { + return `strftime('%Y', ${args}, 'localtime')`; + } + return super.escapeFunction(fn); + } + escapeTable(table: string): string { + return super.escapeTable(table.substring(table.indexOf("@") + 1)); + } +} diff --git a/src/index.ts b/src/index.ts index e161514..aa51d25 100644 --- a/src/index.ts +++ b/src/index.ts @@ -5,6 +5,7 @@ export { DeleteMutation, InsertMutation, UpdateMutation } from "./Mutation"; export { AWSTimestreamFlavor } from "./flavors/aws-timestream"; export { DefaultFlavor } from "./flavors/default"; export { MySQLFlavor } from "./flavors/mysql"; +export { SQLiteFlavor } from "./flavors/sqlite"; export { Cond, Condition, type ConditionValue } from "./Condition"; export { Fn, Function } from "./Function";