From afcdf45cad657e6bb9639fa2d67f850ebc53895b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Garcia?= Date: Sun, 2 Jul 2023 22:14:30 -0300 Subject: [PATCH] Updated PGX Support (markdown) --- PGX-Support.md | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/PGX-Support.md b/PGX-Support.md index 89b41b1..72963df 100644 --- a/PGX-Support.md +++ b/PGX-Support.md @@ -21,10 +21,12 @@ The example query below also [available here][examples/pgxsupport] illustrates o [examples/pgxsupport]: https://github.com/VinGarcia/ksql/blob/master/examples/pgxsupport/main.go#L92 ```golang - // Find user iff user belongs to either team on the input list: - var user User - err = db.QueryOne(ctx, &user, - `SELECT u.* + // Check if user belongs to either of the input teams: + var row struct { + Count pgtype.Int8 `ksql:"c"` + } + err = db.QueryOne(ctx, &row, + `SELECT count(*) as c FROM users AS u JOIN team_members AS tm ON u.id = tm.user_id @@ -33,12 +35,9 @@ The example query below also [available here][examples/pgxsupport] illustrates o userID, []int{1, 2, 42}, // Int slices are supported by PGX ) - if err == ksql.ErrRecordNotFound { - fmt.Println("Input user does not exist or does not belong to any of the provided teams") - return - } else if err != nil { + if err != nil { log.Fatalf("unexpected error: %s", err) } - fmt.Printf("Found user: %+v\n", user) + fmt.Printf("Count: %+v\n", row.Count.Int) ``` \ No newline at end of file