Skip to content

Commit d5f4e14

Browse files
committed
Refactor HTML structure in WhereCondition documentation and update formatting
- Updated the HTML structure in `WhereCondition.html` for better readability and consistency. - Removed unnecessary empty lines and improved indentation. - Cleaned up the `index.ts` example file by removing an empty line. - Adjusted formatting in `jest.config.js` for consistency. - Added a new Prettier configuration file to enforce code style. - Cleaned up the README by removing an unnecessary empty line and fixing a trailing comma in usage examples. - Modified the Postgres adapter to remove the generic type from the query method. - Updated comparison operators to remove trailing commas for consistency. - Refactored logical operators to remove trailing commas. - Cleaned up sorting operators by removing trailing commas. - Adjusted query builder classes to remove unnecessary trailing commas. - Updated repository class to remove trailing commas in method parameters. - Cleaned up column class constructor by removing trailing commas. - Updated common types to use generic types for `QueryResult`. - Refactored utility functions to remove trailing commas. - Cleaned up test setup functions by removing trailing commas.
1 parent f8160cb commit d5f4e14

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

89 files changed

+30468
-2314
lines changed

.github/workflows/generate-docs.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
- name: Set up Node.js
1717
uses: actions/setup-node@v3
1818
with:
19-
node-version: '16'
19+
node-version: "16"
2020

2121
- name: Install dependencies
2222
run: npm install
@@ -28,4 +28,4 @@ jobs:
2828
uses: peaceiris/actions-gh-pages@v3
2929
with:
3030
github_token: ${{ secrets.GH_TOKEN }}
31-
publish_dir: ./docs
31+
publish_dir: ./docs

.github/workflows/publish.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ jobs:
2929
- name: Set up Node.js
3030
uses: actions/setup-node@v3
3131
with:
32-
node-version: '16'
32+
node-version: "16"
3333

3434
- name: Install dependencies
3535
run: npm install
@@ -48,7 +48,7 @@ jobs:
4848
- name: Set up Node.js
4949
uses: actions/setup-node@v3
5050
with:
51-
node-version: '16'
51+
node-version: "16"
5252

5353
- name: Install dependencies
5454
run: npm install
@@ -63,4 +63,4 @@ jobs:
6363
- name: Publish to npm
6464
run: npm publish --provenance --access public
6565
env:
66-
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
66+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

.github/workflows/test-on-push.yml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,16 @@ jobs:
2424
--health-retries 5
2525
2626
steps:
27-
- name: Checkout code
28-
uses: actions/checkout@v3
27+
- name: Checkout code
28+
uses: actions/checkout@v3
2929

30-
- name: Set up Node.js
31-
uses: actions/setup-node@v3
32-
with:
33-
node-version: '16'
30+
- name: Set up Node.js
31+
uses: actions/setup-node@v3
32+
with:
33+
node-version: "16"
3434

35-
- name: Install dependencies
36-
run: npm install
35+
- name: Install dependencies
36+
run: npm install
3737

38-
- name: Run tests
39-
run: npm test
38+
- name: Run tests
39+
run: npm test

.github/workflows/test-on-release.yml

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ on:
55
types: [published]
66

77
jobs:
8-
test:
8+
test:
99
runs-on: ubuntu-latest
1010
services:
1111
postgres:
@@ -23,16 +23,16 @@ jobs:
2323
--health-retries 5
2424
2525
steps:
26-
- name: Checkout code
27-
uses: actions/checkout@v3
26+
- name: Checkout code
27+
uses: actions/checkout@v3
2828

29-
- name: Set up Node.js
30-
uses: actions/setup-node@v3
31-
with:
32-
node-version: '16'
29+
- name: Set up Node.js
30+
uses: actions/setup-node@v3
31+
with:
32+
node-version: "16"
3333

34-
- name: Install dependencies
35-
run: npm install
34+
- name: Install dependencies
35+
run: npm install
3636

37-
- name: Run tests
38-
run: npm test
37+
- name: Run tests
38+
run: npm test

__tests__/delete-builder.test.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ describe("DeleteQueryBuilder", () => {
6868

6969
expect(result.sql).toContain(`DELETE FROM "users"`);
7070
expect(result.sql).toContain(
71-
`WHERE ("users"."age" > $1 AND "users"."name" = $2)`
71+
`WHERE ("users"."age" > $1 AND "users"."name" = $2)`,
7272
);
7373
expect(result.sql).toContain("RETURNING *");
7474
expect(result.values).toEqual([18, "John"]);
@@ -85,7 +85,9 @@ describe("DeleteQueryBuilder", () => {
8585
const result = builder.where(where).build();
8686

8787
expect(result.sql).toContain(`DELETE FROM "users"`);
88-
expect(result.sql).toContain(`WHERE ("users"."age" > $1 OR "users"."name" = $2)`);
88+
expect(result.sql).toContain(
89+
`WHERE ("users"."age" > $1 OR "users"."name" = $2)`,
90+
);
8991
expect(result.sql).toContain("RETURNING *");
9092
expect(result.values).toEqual([18, "John"]);
9193
});
@@ -115,7 +117,7 @@ describe("DeleteQueryBuilder", () => {
115117

116118
expect(result.sql).toContain(`DELETE FROM "users"`);
117119
expect(result.sql).toContain(
118-
`WHERE ("users"."age" > $1 AND ("users"."name" = $2 OR "users"."name" = $3))`
120+
`WHERE ("users"."age" > $1 AND ("users"."name" = $2 OR "users"."name" = $3))`,
119121
);
120122
expect(result.sql).toContain("RETURNING *");
121123
expect(result.values).toEqual([18, "John", "Jane"]);
@@ -151,7 +153,7 @@ describe("DeleteQueryBuilder", () => {
151153

152154
expect(result.sql).toContain(`DELETE FROM "users"`);
153155
expect(result.sql).toContain(
154-
`WHERE ("users"."age" > $1 AND ("users"."name" = $2 OR "users"."name" = $3))`
156+
`WHERE ("users"."age" > $1 AND ("users"."name" = $2 OR "users"."name" = $3))`,
155157
);
156158
expect(result.sql).toContain("RETURNING id, name, email");
157159
expect(result.values).toEqual([18, "John", "Jane"]);

__tests__/insert-builder.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ describe("InsertQueryBuilder", () => {
3636
.build();
3737

3838
expect(result.sql).toContain(
39-
'INSERT INTO users ("name", "email", "age")'
39+
'INSERT INTO users ("name", "email", "age")',
4040
);
4141
expect(result.sql).toContain("VALUES ($1, $2, $3)");
4242
expect(result.sql).toContain(`RETURNING *`);

__tests__/repository/count.test.ts

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1-
import {Repository} from "../../src/repository/repository";
2-
import {and, eq, gt, like} from "../../src";
3-
import {cleanupTestData, DomainUser, executor, setupTestTables} from "../../test-setup";
4-
1+
import { Repository } from "../../src";
2+
import { and, eq, gt, like } from "../../src";
3+
import {
4+
cleanupTestData,
5+
DomainUser,
6+
executor,
7+
setupTestTables,
8+
} from "../../test-setup";
59

610
describe("Repository count", () => {
711
let repository: Repository<DomainUser>;
@@ -22,7 +26,7 @@ describe("Repository count", () => {
2226
// Insert test data
2327
await executor.executeSQL(
2428
`INSERT INTO users (name, email, age) VALUES ($1, $2, $3), ($4, $5, $6) RETURNING *`,
25-
["John Doe", "[email protected]", 30, "Jane Doe", "[email protected]", 25]
29+
["John Doe", "[email protected]", 30, "Jane Doe", "[email protected]", 25],
2630
);
2731

2832
const result = await repository.count(like("name", "%Doe%"));
@@ -33,7 +37,7 @@ describe("Repository count", () => {
3337
// Insert test data
3438
await executor.executeSQL(
3539
`INSERT INTO users (name, email, age) VALUES ($1, $2, $3), ($4, $5, $6) RETURNING *`,
36-
["John Doe", "[email protected]", 30, "Jane Doe", "[email protected]", 25]
40+
["John Doe", "[email protected]", 30, "Jane Doe", "[email protected]", 25],
3741
);
3842

3943
const result = await repository.count(gt("age", 25));
@@ -45,7 +49,7 @@ describe("Repository count", () => {
4549
// Insert test data
4650
await executor.executeSQL(
4751
`INSERT INTO users (name, email, age) VALUES ($1, $2, $3), ($4, $5, $6) RETURNING *`,
48-
["John Doe", "[email protected]", 30, "Jane Doe", "[email protected]", 25]
52+
["John Doe", "[email protected]", 30, "Jane Doe", "[email protected]", 25],
4953
);
5054

5155
const result = await repository.count(gt("age", 100));
@@ -57,11 +61,11 @@ describe("Repository count", () => {
5761
// Insert test data
5862
await executor.executeSQL(
5963
`INSERT INTO users (name, email, age) VALUES ($1, $2, $3), ($4, $5, $6) RETURNING *`,
60-
["John Doe", "[email protected]", 30, "Jane Doe", "[email protected]", 25]
64+
["John Doe", "[email protected]", 30, "Jane Doe", "[email protected]", 25],
6165
);
6266

6367
const result = await repository.count(
64-
and(gt("age", 25), like("name", "%Doe%"))
68+
and(gt("age", 25), like("name", "%Doe%")),
6569
);
6670

6771
expect(result).toBe(1);
@@ -70,7 +74,7 @@ describe("Repository count", () => {
7074
it("should handle errors during execution", async () => {
7175
// Try to count with an invalid column name
7276
await expect(
73-
repository.count(eq("invalid_column" as any, 1))
77+
repository.count(eq("invalid_column" as any, 1)),
7478
).rejects.toThrow();
7579
});
7680
});

__tests__/repository/delete.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { SqlExecutor, QueryResult } from "../../src";
2-
import { Repository } from "../../src/repository/repository";
2+
import { Repository } from "../../src";
33
import { eq, gt, and, like } from "../../src";
4-
import {DomainUser} from "../../test-setup";
4+
import { DomainUser } from "../../test-setup";
55

66
// Mock SqlExecutor
77
const mockExecutor: jest.Mocked<SqlExecutor> = {
@@ -17,7 +17,7 @@ describe("Repository delete", () => {
1717
});
1818

1919
it("should delete a record and return it", async () => {
20-
const mockUser: Omit<DomainUser, 'created_at'> = {
20+
const mockUser: Omit<DomainUser, "created_at"> = {
2121
id: "1",
2222
name: "John Doe",
2323
@@ -82,7 +82,7 @@ describe("Repository delete", () => {
8282
mockExecutor.executeSQL.mockResolvedValueOnce(mockResult);
8383

8484
const result = await repository.delete(
85-
and(gt("age", 25), like("name", "%Doe%"))
85+
and(gt("age", 25), like("name", "%Doe%")),
8686
);
8787

8888
expect(mockExecutor.executeSQL).toHaveBeenCalledTimes(1);
@@ -94,7 +94,7 @@ describe("Repository delete", () => {
9494
mockExecutor.executeSQL.mockRejectedValueOnce(error);
9595

9696
await expect(repository.delete(eq("id", "1"))).rejects.toThrow(
97-
"Database error"
97+
"Database error",
9898
);
9999
});
100100
});

__tests__/repository/find-row.test.ts

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,5 @@
1-
import { Repository } from "../../src/repository/repository";
2-
import { eq, and, gt, like } from "../../src";
3-
import {
4-
executor,
5-
setupTestTables,
6-
cleanupTestData,
7-
seedTestData,
8-
DomainUser,
9-
} from "../../test-setup";
1+
import {and, eq, gt, Repository} from "../../src";
2+
import {cleanupTestData, DomainUser, executor, seedTestData, setupTestTables,} from "../../test-setup";
103

114
describe("Repository findRow", () => {
125
let repository: Repository<DomainUser>;
@@ -25,7 +18,7 @@ describe("Repository findRow", () => {
2518
// Insert test data
2619
await executor.executeSQL(
2720
`INSERT INTO users (name, email, age) VALUES ($1, $2, $3)`,
28-
["John Doe", "[email protected]", 30]
21+
["John Doe", "[email protected]", 30],
2922
);
3023

3124
const result = await repository.findRow(eq("email", "[email protected]"));
@@ -39,7 +32,7 @@ describe("Repository findRow", () => {
3932

4033
it("should return null when no row is found", async () => {
4134
const result = await repository.findRow(
42-
eq("email", "[email protected]")
35+
eq("email", "[email protected]"),
4336
);
4437
expect(result).toBeNull();
4538
});
@@ -48,11 +41,11 @@ describe("Repository findRow", () => {
4841
// Insert test data
4942
await executor.executeSQL(
5043
`INSERT INTO users (name, email, age) VALUES ($1, $2, $3) RETURNING *`,
51-
["John Doe", "[email protected]", 30]
44+
["John Doe", "[email protected]", 30],
5245
);
5346

5447
const result = await repository.findRow(
55-
and(eq("name", "John Doe"), gt("age", 25))
48+
and(eq("name", "John Doe"), gt("age", 25)),
5649
);
5750

5851
expect(result).toMatchObject({
@@ -65,7 +58,7 @@ describe("Repository findRow", () => {
6558
it("should handle errors during execution", async () => {
6659
// Try to find a row with an invalid column name
6760
await expect(
68-
repository.findRow(eq("invalid_column" as any, "1"))
61+
repository.findRow(eq("invalid_column" as any, "1")),
6962
).rejects.toThrow();
7063
});
7164
});

__tests__/repository/find-rows.test.ts

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import {
22
between,
3-
eq,
43
gt,
54
gte,
65
ilike,
@@ -14,8 +13,8 @@ import {
1413
neq,
1514
notInArray,
1615
regexp,
16+
Repository,
1717
} from "../../src";
18-
import {Repository} from "../../src/repository/repository";
1918
import {cleanupTestData, DomainUser, executor, setupTestTables,} from "../../test-setup";
2019

2120
describe("Repository findRows", () => {
@@ -37,7 +36,7 @@ describe("Repository findRows", () => {
3736
});
3837

3938
expect(result.every((user) => user.email !== "[email protected]")).toBe(
40-
true
39+
true,
4140
);
4241
});
4342

@@ -79,7 +78,7 @@ describe("Repository findRows", () => {
7978
});
8079

8180
expect(
82-
result.every((user) => user.name.toLowerCase().includes("john"))
81+
result.every((user) => user.name.toLowerCase().includes("john")),
8382
).toBe(true);
8483
});
8584

@@ -89,7 +88,7 @@ describe("Repository findRows", () => {
8988
});
9089

9190
expect(
92-
result.every((user) => user.name.toLowerCase().includes("john"))
91+
result.every((user) => user.name.toLowerCase().includes("john")),
9392
).toBe(true);
9493
});
9594

@@ -100,8 +99,8 @@ describe("Repository findRows", () => {
10099

101100
expect(
102101
result.every((user) =>
103-
["[email protected]", "[email protected]"].includes(user.email)
104-
)
102+
["[email protected]", "[email protected]"].includes(user.email),
103+
),
105104
).toBe(true);
106105
});
107106

@@ -113,8 +112,8 @@ describe("Repository findRows", () => {
113112
expect(
114113
result.every(
115114
(user) =>
116-
!["[email protected]", "[email protected]"].includes(user.email)
117-
)
115+
!["[email protected]", "[email protected]"].includes(user.email),
116+
),
118117
).toBe(true);
119118
});
120119

@@ -140,7 +139,7 @@ describe("Repository findRows", () => {
140139
});
141140

142141
expect(result.every((user) => user.age! >= 25 && user.age! <= 35)).toBe(
143-
true
142+
true,
144143
);
145144
});
146145

0 commit comments

Comments
 (0)