Skip to content

Commit 64855b2

Browse files
committed
fix: use BigInt for playground stars column
pg type parser returns BigInt for int8 columns but the contract and queries were typed as string, causing HttpApiDecodeError on search.
1 parent cb0743b commit 64855b2

2 files changed

Lines changed: 11 additions & 11 deletions

File tree

server/httpapi/contract.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,13 @@ export const PlaygroundFile = S.Struct({ path: S.String, content: S.String });
3030

3131
export const PlaygroundListItem = Playground.json.pipe(
3232
S.pick("hash", "fork_hash", "name", "description", "created_at", "updated_at"),
33-
S.extend(S.Struct({ stars: S.String })),
33+
S.extend(S.Struct({ stars: S.BigInt })),
3434
);
3535

3636
export const PlaygroundListItemWithUser = Playground.json.pipe(
3737
S.pick("hash", "fork_hash", "name", "description", "created_at", "updated_at"),
3838
S.extend(S.Struct({
39-
stars: S.String,
39+
stars: S.BigInt,
4040
user: S.Struct({ username: S.String }),
4141
})),
4242
);
@@ -46,7 +46,7 @@ export const PlaygroundDetail = Playground.json.pipe(
4646
S.extend(S.Struct({
4747
expires_at: S.NullOr(S.DateTimeUtc),
4848
user: S.NullOr(S.Struct({ username: S.String })),
49-
stars: S.String,
49+
stars: S.BigInt,
5050
is_starred: S.Boolean,
5151
fork_of: S.NullOr(
5252
S.Struct({

server/services/playgroundService.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export class PlaygroundService extends Effect.Service<PlaygroundService>()("Play
5252
(eb) =>
5353
eb
5454
.selectFrom("app_public.playground_stars")
55-
.select((eb) => ["playground_hash", eb.fn.countAll<string>().as("stars")])
55+
.select((eb) => ["playground_hash", eb.fn.countAll<bigint>().as("stars")])
5656
.groupBy("playground_hash")
5757
.as("star_counts"),
5858
(join) => join.onRef("star_counts.playground_hash", "=", "p.hash"),
@@ -65,7 +65,7 @@ export class PlaygroundService extends Effect.Service<PlaygroundService>()("Play
6565
"p.fork_hash",
6666
"p.name",
6767
"p.description",
68-
eb.fn.coalesce(eb.ref("star_counts.stars"), sql.lit("0")).as("stars"),
68+
eb.fn.coalesce(eb.ref("star_counts.stars"), sql.lit(0n)).as("stars"),
6969
"p.created_at",
7070
"p.updated_at",
7171
]),
@@ -82,7 +82,7 @@ export class PlaygroundService extends Effect.Service<PlaygroundService>()("Play
8282
(eb) =>
8383
eb
8484
.selectFrom("app_public.playground_stars")
85-
.select((eb) => ["playground_hash", eb.fn.countAll<string>().as("stars")])
85+
.select((eb) => ["playground_hash", eb.fn.countAll<bigint>().as("stars")])
8686
.groupBy("playground_hash")
8787
.as("star_counts"),
8888
(join) => join.onRef("star_counts.playground_hash", "=", "p.hash"),
@@ -94,7 +94,7 @@ export class PlaygroundService extends Effect.Service<PlaygroundService>()("Play
9494
"p.fork_hash",
9595
"p.name",
9696
"p.description",
97-
eb.fn.coalesce(eb.ref("star_counts.stars"), sql.lit("0")).as("stars"),
97+
eb.fn.coalesce(eb.ref("star_counts.stars"), sql.lit(0n)).as("stars"),
9898
"p.created_at",
9999
"p.updated_at",
100100
jsonBuildObject({ username: eb.ref("u.username") }).as("user"),
@@ -114,7 +114,7 @@ export class PlaygroundService extends Effect.Service<PlaygroundService>()("Play
114114
(eb) =>
115115
eb
116116
.selectFrom("app_public.playground_stars")
117-
.select((eb) => ["playground_hash", eb.fn.countAll<string>().as("stars")])
117+
.select((eb) => ["playground_hash", eb.fn.countAll<bigint>().as("stars")])
118118
.groupBy("playground_hash")
119119
.as("star_counts"),
120120
(join) => join.onRef("star_counts.playground_hash", "=", "p.hash"),
@@ -146,7 +146,7 @@ export class PlaygroundService extends Effect.Service<PlaygroundService>()("Play
146146
"p.fork_hash",
147147
"p.name",
148148
"p.description",
149-
eb.fn.coalesce(eb.ref("star_counts.stars"), sql.lit("0")).as("stars"),
149+
eb.fn.coalesce(eb.ref("star_counts.stars"), sql.lit(0n)).as("stars"),
150150
"p.created_at",
151151
"p.updated_at",
152152
jsonBuildObject({ username: eb.ref("u.username") }).as("user"),
@@ -197,7 +197,7 @@ export class PlaygroundService extends Effect.Service<PlaygroundService>()("Play
197197
(eb) =>
198198
eb
199199
.selectFrom("app_public.playground_stars")
200-
.select((eb) => ["playground_hash", eb.fn.countAll<string>().as("stars")])
200+
.select((eb) => ["playground_hash", eb.fn.countAll<bigint>().as("stars")])
201201
.groupBy("playground_hash")
202202
.as("star_counts"),
203203
(join) => join.onRef("star_counts.playground_hash", "=", "p.hash"),
@@ -210,7 +210,7 @@ export class PlaygroundService extends Effect.Service<PlaygroundService>()("Play
210210
.selectAll("p")
211211
.select((eb) => [
212212
jsonBuildObject({ username: eb.ref("u.username") }).as("user"),
213-
eb.fn.coalesce(eb.ref("star_counts.stars"), sql.lit("0")).as("stars"),
213+
eb.fn.coalesce(eb.ref("star_counts.stars"), sql.lit(0n)).as("stars"),
214214
eb("my_star.playground_hash", "is not", null).$castTo<boolean>().as("is_starred"),
215215
eb
216216
.case()

0 commit comments

Comments
 (0)