File tree Expand file tree Collapse file tree 2 files changed +8
-28
lines changed
Expand file tree Collapse file tree 2 files changed +8
-28
lines changed Load Diff This file was deleted.
Original file line number Diff line number Diff line change @@ -2,8 +2,9 @@ import type { RequestHandler } from "@hattip/compose";
22import { type TinyRpcRoutes , createTinyRpcHandler } from "@hiogawa/tiny-rpc" ;
33import { zodFn } from "@hiogawa/tiny-rpc/dist/zod" ;
44import { tinyassert } from "@hiogawa/utils" ;
5+ import { sql } from "kysely" ;
56import { z } from "zod" ;
6- import { sql } from "../db/sql " ;
7+ import { db } from "../db" ;
78import { env } from "../utils/worker-env" ;
89
910export type RpcRoutes = typeof rpcRoutes ;
@@ -47,17 +48,19 @@ const counterD1 = {
4748 id : 1 ,
4849
4950 async get ( ) {
50- const rows = await sql < {
51+ const { rows } = await sql < {
5152 value : number ;
52- } > `SELECT value from counter where id = ${ this . id } ` ;
53+ } > `SELECT value from counter where id = ${ this . id } ` . execute ( db ) ;
5354 tinyassert ( rows . length === 1 ) ;
5455 return rows [ 0 ] . value ;
5556 } ,
5657
5758 async update ( delta : number ) {
58- const rows = await sql < {
59+ const { rows } = await sql < {
5960 value : number ;
60- } > `UPDATE Counter SET value = value + ${ delta } WHERE id = ${ this . id } RETURNING value` ;
61+ } > `UPDATE Counter SET value = value + ${ delta } WHERE id = ${ this . id } RETURNING value` . execute (
62+ db ,
63+ ) ;
6164 tinyassert ( rows . length === 1 ) ;
6265 return rows [ 0 ] . value ;
6366 } ,
You can’t perform that action at this time.
0 commit comments