Skip to content

Commit f3798cd

Browse files
committed
chore: bump version to 1.0.15 in package.json and improve code formatting in tests and repository methods
1 parent 462503c commit f3798cd

File tree

4 files changed

+42
-38
lines changed

4 files changed

+42
-38
lines changed

__tests__/repository/find.test.ts

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,14 @@ import {
1313
neq,
1414
notInArray,
1515
regexp,
16-
Repository,
16+
Repository
1717
} from "../../src";
18-
import {cleanupTestData, DomainUser, executor, setupTestTables,} from "../../test-setup";
18+
import {
19+
cleanupTestData,
20+
DomainUser,
21+
executor,
22+
setupTestTables
23+
} from "../../test-setup";
1924

2025
describe("Repository findRows", () => {
2126
let repository: Repository<DomainUser>;
@@ -32,128 +37,128 @@ describe("Repository findRows", () => {
3237
describe("Comparison Operators", () => {
3338
it("should find rows with neq operator", async () => {
3439
const result = await repository.find({
35-
where: neq("email", "[email protected]"),
40+
where: neq("email", "[email protected]")
3641
});
3742

3843
expect(result.every((user) => user.email !== "[email protected]")).toBe(
39-
true,
44+
true
4045
);
4146
});
4247

4348
it("should find rows with gt operator", async () => {
4449
const result = await repository.find({
45-
where: gt("age", 30),
50+
where: gt("age", 30)
4651
});
4752

4853
expect(result.every((user) => user.age! > 30)).toBe(true);
4954
});
5055

5156
it("should find rows with gte operator", async () => {
5257
const result = await repository.find({
53-
where: gte("age", 30),
58+
where: gte("age", 30)
5459
});
5560

5661
expect(result.every((user) => user.age! >= 30)).toBe(true);
5762
});
5863

5964
it("should find rows with lt operator", async () => {
6065
const result = await repository.find({
61-
where: lt("age", 40),
66+
where: lt("age", 40)
6267
});
6368

6469
expect(result.every((user) => user.age! < 40)).toBe(true);
6570
});
6671

6772
it("should find rows with lte operator", async () => {
6873
const result = await repository.find({
69-
where: lte("age", 40),
74+
where: lte("age", 40)
7075
});
7176

7277
expect(result.every((user) => user.age! <= 40)).toBe(true);
7378
});
7479

7580
it("should find rows with like operator", async () => {
7681
const result = await repository.find({
77-
where: like("name", "%john%"),
82+
where: like("name", "%john%")
7883
});
7984

8085
expect(
81-
result.every((user) => user.name.toLowerCase().includes("john")),
86+
result.every((user) => user.name.toLowerCase().includes("john"))
8287
).toBe(true);
8388
});
8489

8590
it("should find rows with ilike operator", async () => {
8691
const result = await repository.find({
87-
where: ilike("name", "%JOHN%"),
92+
where: ilike("name", "%JOHN%")
8893
});
8994

9095
expect(
91-
result.every((user) => user.name.toLowerCase().includes("john")),
96+
result.every((user) => user.name.toLowerCase().includes("john"))
9297
).toBe(true);
9398
});
9499

95100
it("should find rows with inArray operator", async () => {
96101
const result = await repository.find({
97-
where: inArray("email", ["[email protected]", "[email protected]"]),
102+
where: inArray("email", ["[email protected]", "[email protected]"])
98103
});
99104

100105
expect(
101106
result.every((user) =>
102-
["[email protected]", "[email protected]"].includes(user.email),
103-
),
107+
["[email protected]", "[email protected]"].includes(user.email)
108+
)
104109
).toBe(true);
105110
});
106111

107112
it("should find rows with notInArray operator", async () => {
108113
const result = await repository.find({
109-
where: notInArray("email", ["[email protected]", "[email protected]"]),
114+
where: notInArray("email", ["[email protected]", "[email protected]"])
110115
});
111116

112117
expect(
113118
result.every(
114119
(user) =>
115-
!["[email protected]", "[email protected]"].includes(user.email),
116-
),
120+
!["[email protected]", "[email protected]"].includes(user.email)
121+
)
117122
).toBe(true);
118123
});
119124

120125
it("should find rows with isNull operator", async () => {
121126
const result = await repository.find({
122-
where: isNull("bio"),
127+
where: isNull("bio")
123128
});
124129

125130
expect(result.every((user) => user.bio === null)).toBe(true);
126131
});
127132

128133
it("should find rows with isNotNull operator", async () => {
129134
const result = await repository.find({
130-
where: isNotNull("bio"),
135+
where: isNotNull("bio")
131136
});
132137

133138
expect(result.every((user) => user.bio !== null)).toBe(true);
134139
});
135140

136141
it("should find rows with between operator", async () => {
137142
const result = await repository.find({
138-
where: between("age", 25, 35),
143+
where: between("age", 25, 35)
139144
});
140145

141146
expect(result.every((user) => user.age! >= 25 && user.age! <= 35)).toBe(
142-
true,
147+
true
143148
);
144149
});
145150

146151
it("should find rows with regexp operator", async () => {
147152
const result = await repository.find({
148-
where: regexp("name", "^[A-Z]"),
153+
where: regexp("name", "^[A-Z]")
149154
});
150155

151156
expect(result.every((user) => /^[A-Z]/.test(user.name))).toBe(true);
152157
});
153158

154159
it("should find rows with iregexp operator", async () => {
155160
const result = await repository.find({
156-
where: iregexp("name", "^[a-z]"),
161+
where: iregexp("name", "^[a-z]")
157162
});
158163

159164
expect(result.every((user) => /^[a-z]/i.test(user.name))).toBe(true);

__tests__/repository/insert.test.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ import {
22
setupTestTables,
33
cleanupTestData,
44
executor,
5-
DomainUser,
5+
DomainUser
66
} from "../../test-setup";
77
import { Repository } from "../../src";
88

9-
describe("Repository - insertMany", () => {
9+
describe("Repository - insert", () => {
1010
let repository: Repository<DomainUser>;
1111

1212
beforeAll(async () => {
@@ -21,7 +21,7 @@ describe("Repository - insertMany", () => {
2121
it("should insert multiple records into the database", async () => {
2222
const records = [
2323
{ name: "John Doe", email: "[email protected]", age: 30 },
24-
{ name: "Jane Smith", email: "[email protected]", age: 25 },
24+
{ name: "Jane Smith", email: "[email protected]", age: 25 }
2525
];
2626
const result = await repository.insert(records);
2727

@@ -31,25 +31,24 @@ describe("Repository - insertMany", () => {
3131

3232
const insertedRecords = await executor.executeSQL(
3333
"SELECT * FROM users WHERE email IN ($1, $2)",
34-
34+
3535
);
3636

3737
expect(insertedRecords.rows).toHaveLength(2);
3838
expect(insertedRecords.rows).toEqual(
3939
expect.arrayContaining([
4040
expect.objectContaining(records[0]),
41-
expect.objectContaining(records[1]),
42-
]),
41+
expect.objectContaining(records[1])
42+
])
4343
);
4444
});
4545

4646
it("should throw an error if one of the records violates constraints", async () => {
47-
const records: DomainUser[] | {[key:string]: any} = [
47+
const records: DomainUser[] | { [key: string]: any } = [
4848
{ name: "Valid User", email: "[email protected]", age: 40 },
49-
{ name: null, email: "[email protected]" }, // Assuming 'name' cannot be null
49+
{ name: null, email: "[email protected]" } // Assuming 'name' cannot be null
5050
];
5151

52-
5352
await expect(repository.insert(records as any)).rejects.toThrow();
5453
});
5554
});

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "sqlkit",
3-
"version": "1.0.14",
3+
"version": "1.0.15",
44
"description": "A lightweight SQL builder for TypeScript",
55
"license": "MIT",
66
"author": {

src/repository/repository.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export class Repository<T> {
4242
sql: builder.build().sql,
4343
values: builder.build().values,
4444
result: {
45-
rows: result.rows,
45+
rows: JSON.stringify(result.rows, null, 2),
4646
rowCount: result.rowCount
4747
}
4848
});
@@ -93,7 +93,7 @@ export class Repository<T> {
9393
sql: builder.build().sql,
9494
values: builder.build().values,
9595
result: {
96-
rows: result.rows,
96+
rows: JSON.stringify(result.rows, null, 2),
9797
rowCount: result.rowCount
9898
}
9999
});
@@ -120,7 +120,7 @@ export class Repository<T> {
120120
sql: builder.build().sql,
121121
values: builder.build().values,
122122
result: {
123-
rows: result.rows,
123+
rows: JSON.stringify(result.rows, null, 2),
124124
rowCount: result.rowCount
125125
}
126126
});
@@ -143,7 +143,7 @@ export class Repository<T> {
143143
sql: builder.build().sql,
144144
values: builder.build().values,
145145
result: {
146-
rows: result.rows,
146+
rows: JSON.stringify(result.rows, null, 2),
147147
rowCount: result.rowCount
148148
}
149149
});

0 commit comments

Comments
 (0)