Skip to content

Commit 02e541b

Browse files
authored
Merge pull request #34 from ryanrasti/ryan_sin_bug
bug: sin not generated
2 parents 19c95d4 + 30d9230 commit 02e541b

4 files changed

Lines changed: 87 additions & 11 deletions

File tree

src/demo/demo.test.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ describe("demo.ts examples", async () => {
77
"Example 1"?: { species: string }[];
88
"Example 2"?: { key: string; isNum: boolean }[];
99
"Example 3"?: { personName: string; petSpecies: string; petAge: number }[];
10+
"Example 4"?: { result: number }[];
1011
} = {};
1112

1213
const spyConsole = vi
@@ -21,6 +22,7 @@ describe("demo.ts examples", async () => {
2122
"Example 1": example1,
2223
"Example 2": example2,
2324
"Example 3": example3,
25+
"Example 4": example4,
2426
} = calls;
2527

2628
it("example1: grouping and aggregation on pets", async () => {
@@ -63,4 +65,9 @@ describe("demo.ts examples", async () => {
6365
{ personName: "Charlie", petSpecies: "dog", petAge: 10 },
6466
]);
6567
});
68+
69+
it("example4: math coverage", async () => {
70+
expect(Array.isArray(example4)).toBe(true);
71+
expect(example4).toEqual([{ result: 1.669026835867367 }]);
72+
});
6673
});

src/demo/demo.ts

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const tg = await typegres({ type: "pglite" });
66
const pets = values(
77
{ species: Text.new("cat"), age: Float8.new(2), id: Int8.new(1n) },
88
{ species: Text.new("dog"), age: Float8.new(3), id: Int8.new(2n) },
9-
{ species: Text.new("dog"), age: Float8.new(10), id: Int8.new(3n) },
9+
{ species: Text.new("dog"), age: Float8.new(10), id: Int8.new(3n) }
1010
);
1111

1212
const example1 = await pets
@@ -41,7 +41,7 @@ console.log("Example 2", example2);
4141
const people = values(
4242
{ id: Int8.new(1n), name: Text.new("Alice"), petId: Int8.new(1n) },
4343
{ id: Int8.new(2n), name: Text.new("Bob"), petId: Int8.new(2n) },
44-
{ id: Int8.new(3n), name: Text.new("Charlie"), petId: Int8.new(3n) },
44+
{ id: Int8.new(3n), name: Text.new("Charlie"), petId: Int8.new(3n) }
4545
);
4646

4747
const example3 = await people
@@ -55,3 +55,25 @@ const example3 = await people
5555
.execute(tg);
5656

5757
console.log("Example 3", example3);
58+
59+
// Example 4: Math coverage (https://x.com/dshukertjr/status/1948730454535798799)
60+
import { sin, cos, exp, ln, tan, abs, sqrt } from "typegres";
61+
const homework = await values({
62+
x: Float8.new(1.5),
63+
y: Float8.new(0.7),
64+
})
65+
.select(({ x, y }) => ({
66+
result: sin(x)
67+
["+"](cos(y))
68+
["/"](ln(x.power(2)["+"](1))["+"](1))
69+
.power(2)
70+
["+"](
71+
exp(Float8.new(0)["-"](y.power(2)))["*"](
72+
sqrt(abs(tan(x["*"](y)))["+"](1))
73+
)
74+
),
75+
}))
76+
.debug()
77+
.execute(tg);
78+
79+
console.log("Example 4", homework);

src/gen/gen.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,14 @@ type FunctionsFile = {
6868
};
6969

7070
const keepFunction = (name: string, definitionns: FunctionDefinition[]) => {
71+
const falsePositives = [
72+
// ends with `in`:
73+
"sin",
74+
];
75+
if (falsePositives.includes(name)) {
76+
return true;
77+
}
78+
7179
return (
7280
// Skip functions that start with _send/recv/in/out
7381
!/_?(?:send|recv|in|out)$/.test(name) &&

src/gen/tables.ts

Lines changed: 48 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,70 @@ import * as Types from "../types";
33
import { database } from "../query/db";
44

55
export const db = database({
6+
kysely_migration_lock: {
7+
id: Types.Text<1>,
8+
is_locked: Types.Int4<1>,
9+
},
10+
update_test_users: {
11+
id: Types.Int4<1>,
12+
active: Types.Int4<0>,
13+
name: Types.Text<1>,
14+
email: Types.Text<1>,
15+
role: Types.Text<0>,
16+
},
17+
kysely_migration: {
18+
name: Types.Text<1>,
19+
timestamp: Types.Text<1>,
20+
},
21+
example_3d_array: {
22+
data: Types.Array<0, Types.Int4<0 | 1>>,
23+
id: Types.Int4<1>,
24+
data_1d: Types.Array<0, Types.Int4<0 | 1>>,
25+
},
26+
users: {
27+
name: Types.Text<1>,
28+
email: Types.Text<1>,
29+
role: Types.Text<0>,
30+
id: Types.Int4<1>,
31+
active: Types.Int4<0>,
32+
},
633
person: {
734
firstName: Types.Text<1>,
835
lastName: Types.Text<0>,
936
gender: Types.Text<1>,
1037
id: Types.Int4<1>,
1138
createdAt: Types.Timestamp<1>,
1239
},
13-
kysely_migration_lock: {
14-
id: Types.Text<1>,
15-
is_locked: Types.Int4<1>,
16-
},
1740
pet: {
1841
name: Types.Text<1>,
1942
ownerId: Types.Int4<1>,
2043
species: Types.Text<1>,
2144
age: Types.Int4<1>,
2245
id: Types.Int4<1>,
2346
},
24-
kysely_migration: {
47+
update_test_posts: {
48+
title: Types.Text<1>,
49+
content: Types.Text<0>,
50+
user_id: Types.Int4<1>,
51+
id: Types.Int4<1>,
52+
published: Types.Int4<0>,
53+
},
54+
test_users: {
55+
id: Types.Int4<1>,
56+
balance: Types.Int4<0>,
2557
name: Types.Text<1>,
26-
timestamp: Types.Text<1>,
2758
},
28-
example_3d_array: {
29-
data: Types.Array<0, Types.Int4<0 | 1>>,
59+
posts: {
60+
title: Types.Text<1>,
61+
content: Types.Text<0>,
62+
user_id: Types.Int4<1>,
63+
id: Types.Int4<1>,
64+
published: Types.Int4<0>,
65+
},
66+
comments: {
67+
post_id: Types.Int4<1>,
68+
user_id: Types.Int4<1>,
69+
content: Types.Text<1>,
3070
id: Types.Int4<1>,
31-
data_1d: Types.Array<0, Types.Int4<0 | 1>>,
3271
},
3372
});

0 commit comments

Comments
 (0)