Skip to content

Commit

Permalink
Add count function
Browse files Browse the repository at this point in the history
  • Loading branch information
jakubknejzlik committed Mar 14, 2024
1 parent 5371b2a commit 1c954b2
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/Function.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ const flavor = Q.flavors.mysql;

describe("Expression", () => {
it("should produce valid SQL", () => {
expect(Fn.count("*").toSQL(flavor)).toEqual("COUNT(*)");
expect(Fn.count("foo").toSQL(flavor)).toEqual("COUNT(`foo`)");
expect(Fn.sum("foo").toSQL(flavor)).toEqual("SUM(`foo`)");
expect(Fn.max("foo").toSQL(flavor)).toEqual("MAX(`foo`)");
expect(Fn.add("foo", "blah").toSQL(flavor)).toEqual("(`foo` + `blah`)");
Expand Down
3 changes: 3 additions & 0 deletions src/Function.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ const ifFn = (
};

export const Function = {
count: (column: ExpressionValue) => {
return new FunctionExpression("COUNT", column);
},
add: (...columns: ExpressionValue[]) => {
return new OperationExpression("+", ...columns);
},
Expand Down

0 comments on commit 1c954b2

Please sign in to comment.