22
33import type { Sql } from "postgres" ;
44
5+ export type AuthorStatus = "active" | "inactive" | "pending" ;
6+
57export interface GetAuthorArgs {
68 id : number ;
79}
@@ -10,10 +12,11 @@ export interface GetAuthorRow {
1012 id : number ;
1113 name : string ;
1214 bio : string | null ;
15+ status : AuthorStatus ;
1316}
1417
1518export async function getAuthor ( sql : Sql , args : GetAuthorArgs ) : Promise < GetAuthorRow | null > {
16- const rows = await sql < GetAuthorRow [ ] > `SELECT id, name, bio FROM authors
19+ const rows = await sql < GetAuthorRow [ ] > `SELECT id, name, bio, status FROM authors
1720WHERE id = ${ args . id } LIMIT 1` ;
1821 return rows [ 0 ] ?? null ;
1922}
@@ -22,34 +25,54 @@ export interface ListAuthorsRow {
2225 id : number ;
2326 name : string ;
2427 bio : string | null ;
28+ status : AuthorStatus ;
2529}
2630
2731export async function listAuthors ( sql : Sql ) : Promise < ListAuthorsRow [ ] > {
28- return await sql < ListAuthorsRow [ ] > `SELECT id, name, bio FROM authors
32+ return await sql < ListAuthorsRow [ ] > `SELECT id, name, bio, status FROM authors
2933ORDER BY name` ;
3034}
3135
3236export interface CreateAuthorArgs {
3337 name : string ;
3438 bio : string | null ;
39+ status : AuthorStatus ;
3540}
3641
3742export interface CreateAuthorRow {
3843 id : number ;
3944 name : string ;
4045 bio : string | null ;
46+ status : AuthorStatus ;
4147}
4248
4349export async function createAuthor ( sql : Sql , args : CreateAuthorArgs ) : Promise < CreateAuthorRow | null > {
4450 const rows = await sql < CreateAuthorRow [ ] > `INSERT INTO authors (
45- name, bio
51+ name, bio, status
4652) VALUES (
47- ${ args . name } , ${ args . bio }
53+ ${ args . name } , ${ args . bio } , ${ args . status }
4854)
49- RETURNING id, name, bio` ;
55+ RETURNING id, name, bio, status ` ;
5056 return rows [ 0 ] ?? null ;
5157}
5258
59+ export interface ListAuthorsByStatusArgs {
60+ status : AuthorStatus ;
61+ }
62+
63+ export interface ListAuthorsByStatusRow {
64+ id : number ;
65+ name : string ;
66+ bio : string | null ;
67+ status : AuthorStatus ;
68+ }
69+
70+ export async function listAuthorsByStatus ( sql : Sql , args : ListAuthorsByStatusArgs ) : Promise < ListAuthorsByStatusRow [ ] > {
71+ return await sql < ListAuthorsByStatusRow [ ] > `SELECT id, name, bio, status FROM authors
72+ WHERE status = ${ args . status }
73+ ORDER BY name` ;
74+ }
75+
5376export interface DeleteAuthorArgs {
5477 id : number ;
5578}
0 commit comments