Skip to content

Commit

Permalink
in not-in parens (#89)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasavila00 authored Dec 5, 2024
1 parent 350b196 commit 4a8ff2e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/safe-string.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,20 +129,26 @@ export class SafeString {
* @since 2.0.8
*/
in(other: SqlSupportedTypes): SafeString {
return dsql`(${this} IN (${other}))`;
return dsql`(${this} IN ${other})`;
}

/**
* @since 2.0.8
*/
notIn(other: SqlSupportedTypes): SafeString {
return dsql`(${this} NOT IN (${other}))`;
return dsql`(${this} NOT IN ${other})`;
}

/**
* @since 2.0.8
*/
asc(): SafeString {
return dsql`${this} ASC`;
}

/**
* @since 2.0.8
*/
desc(): SafeString {
return dsql`${this} DESC`;
}
Expand Down
16 changes: 16 additions & 0 deletions tests/unit/safe-string.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@ describe("castSafe", () => {
});
});

describe("serialize array", () => {
it("works", () => {
expect(dsql(["a", "b", "c"]).content).toMatchInlineSnapshot(`abc`);
expect(dsql`${["a", "b", "c"]}`.content).toMatchInlineSnapshot(
`'a', 'b', 'c'`
);
});
});
describe("chaining", () => {
it("works", () => {
const base = dsql`base`;
Expand All @@ -31,6 +39,14 @@ describe("chaining", () => {
expect(base.multiply(1).divide(2).content).toMatchInlineSnapshot(
`((base * 1) / 2)`
);

expect(base.desc().content).toMatchInlineSnapshot(`base DESC`);
expect(base.asc().content).toMatchInlineSnapshot(`base ASC`);

expect(base.in("a").content).toMatchInlineSnapshot(`(base IN 'a')`);
expect(base.notIn("a").content).toMatchInlineSnapshot(
`(base NOT IN 'a')`
);
});
});

Expand Down

0 comments on commit 4a8ff2e

Please sign in to comment.