@@ -7,17 +7,23 @@ SELECT id, name, bio FROM authors
77WHERE id = $1 LIMIT 1` ;
88
99export interface GetAuthorArgs {
10- id : string ;
10+ id : number ;
1111}
1212
1313export interface GetAuthorRow {
14- id : string ;
14+ id : number ;
1515 name : string ;
1616 bio : string | null ;
1717}
1818
19+ export type GetAuthorRowValues = [
20+ number ,
21+ string ,
22+ string | null
23+ ] ;
24+
1925export async function getAuthor ( sql : SQL , args : GetAuthorArgs ) : Promise < GetAuthorRow | null > {
20- const rows = await sql . unsafe ( getAuthorQuery , [ args . id ] ) . values ( ) ;
26+ const rows = await sql . unsafe ( getAuthorQuery , [ args . id ] ) . values ( ) as GetAuthorRowValues [ ] ;
2127 if ( rows . length !== 1 ) {
2228 return null ;
2329 }
@@ -26,7 +32,7 @@ export async function getAuthor(sql: SQL, args: GetAuthorArgs): Promise<GetAutho
2632 return null ;
2733 }
2834 return {
29- id : row [ 0 ] ,
35+ id : Number ( row [ 0 ] ) ,
3036 name : row [ 1 ] ,
3137 bio : row [ 2 ]
3238 } ;
@@ -37,14 +43,20 @@ SELECT id, name, bio FROM authors
3743ORDER BY name` ;
3844
3945export interface ListAuthorsRow {
40- id : string ;
46+ id : number ;
4147 name : string ;
4248 bio : string | null ;
4349}
4450
51+ export type ListAuthorsRowValues = [
52+ number ,
53+ string ,
54+ string | null
55+ ] ;
56+
4557export async function listAuthors ( sql : SQL ) : Promise < ListAuthorsRow [ ] > {
46- return ( await sql . unsafe ( listAuthorsQuery , [ ] ) . values ( ) ) . map ( row => ( {
47- id : row [ 0 ] ,
58+ return ( await sql . unsafe ( listAuthorsQuery , [ ] ) . values ( ) as ListAuthorsRowValues [ ] ) . map ( row => ( {
59+ id : Number ( row [ 0 ] ) ,
4860 name : row [ 1 ] ,
4961 bio : row [ 2 ]
5062 } ) ) ;
@@ -64,13 +76,19 @@ export interface CreateAuthorArgs {
6476}
6577
6678export interface CreateAuthorRow {
67- id : string ;
79+ id : number ;
6880 name : string ;
6981 bio : string | null ;
7082}
7183
84+ export type CreateAuthorRowValues = [
85+ number ,
86+ string ,
87+ string | null
88+ ] ;
89+
7290export async function createAuthor ( sql : SQL , args : CreateAuthorArgs ) : Promise < CreateAuthorRow | null > {
73- const rows = await sql . unsafe ( createAuthorQuery , [ args . name , args . bio ] ) . values ( ) ;
91+ const rows = await sql . unsafe ( createAuthorQuery , [ args . name , args . bio ] ) . values ( ) as CreateAuthorRowValues [ ] ;
7492 if ( rows . length !== 1 ) {
7593 return null ;
7694 }
@@ -79,7 +97,7 @@ export async function createAuthor(sql: SQL, args: CreateAuthorArgs): Promise<Cr
7997 return null ;
8098 }
8199 return {
82- id : row [ 0 ] ,
100+ id : Number ( row [ 0 ] ) ,
83101 name : row [ 1 ] ,
84102 bio : row [ 2 ]
85103 } ;
@@ -90,7 +108,7 @@ DELETE FROM authors
90108WHERE id = $1` ;
91109
92110export interface DeleteAuthorArgs {
93- id : string ;
111+ id : number ;
94112}
95113
96114export async function deleteAuthor ( sql : SQL , args : DeleteAuthorArgs ) : Promise < void > {
0 commit comments