Skip to content

Commit

Permalink
Fix AWS Timestream function escaping
Browse files Browse the repository at this point in the history
  • Loading branch information
jakubknejzlik committed Jan 16, 2024
1 parent 40096d5 commit e2d4630
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
11 changes: 8 additions & 3 deletions src/Query.time.ts → src/Query.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Cond } from "./Condition";
import { Fn } from "./Function";
import { Query, SelectQuery, UnionType, Q } from "./Query";

const flavor = Q.flavors.mysql;
Expand All @@ -9,9 +10,13 @@ describe("Query builder SQL", () => {
expect(Query.select().from("foo").toSQL(flavor)).toEqual(
"SELECT * FROM `foo`"
);
expect(Query.select().from("table").field("foo").toSQL(flavor)).toEqual(
"SELECT `foo` FROM `table`"
);
expect(
Query.select()
.from("table")
.field("foo")
.addField(Fn.max("foo"), "fooMax")
.toSQL(flavor)
).toEqual("SELECT `foo`, MAX(foo) AS `fooMax` FROM `table`");
expect(
Query.select().from("table").field("foo", "blah").toSQL(flavor)
).toEqual("SELECT `foo` AS `blah` FROM `table`");
Expand Down
4 changes: 3 additions & 1 deletion src/flavors/aws-timestream.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Cond } from "../Condition";
import { Fn } from "../Function";
import { Q } from "../Query";

const flavor = Q.flavors.awsTimestream;
Expand All @@ -7,12 +8,13 @@ describe("Query builder AWS Timestream flavor", () => {
it("should render correct SQL", () => {
const query = Q.select()
.addField("foo", "blah")
.addField(Fn.max("foo"), "blahMax")
.from("table")
.where(Cond.equal("foo", 123))
.where(Cond.equal("blah", "hello"))
.orderBy("foo", "DESC");
expect(query.toSQL(flavor)).toEqual(
`SELECT "foo" AS "blah" FROM "table" WHERE "foo" = 123 AND "blah" = 'hello' ORDER BY "foo" DESC`
`SELECT "foo" AS "blah", MAX(foo) AS "blahMax" FROM "table" WHERE "foo" = 123 AND "blah" = 'hello' ORDER BY "foo" DESC`
);
});
});
2 changes: 1 addition & 1 deletion src/flavors/mysql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export class MySQLFlavor implements ISQLFlavor {
.split(".")
.join("`.`")}${this.columnQuotes}`;
}
return `${this.columnQuotes}${name}${this.columnQuotes}`;
return `${name}`;
}

escapeTable(table: string): string {
Expand Down

0 comments on commit e2d4630

Please sign in to comment.