Skip to content

Commit

Permalink
Add SQLite flavor
Browse files Browse the repository at this point in the history
  • Loading branch information
jakubknejzlik committed Aug 5, 2024
1 parent faced18 commit 9eb4b0c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/flavors/sqlite.ts
Original file line number Diff line number Diff line change
@@ -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));
}
}
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down

0 comments on commit 9eb4b0c

Please sign in to comment.