Skip to content

Commit c4ceb0e

Browse files
authored
docs: update samples for HOW-TO GUIDES (#1953)
1 parent 4f8da00 commit c4ceb0e

File tree

4 files changed

+18
-12
lines changed

4 files changed

+18
-12
lines changed

docs/howto/delete.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import (
1919
)
2020

2121
type DBTX interface {
22-
ExecContext(context.Context, string, ...interface{}) error
22+
ExecContext(context.Context, string, ...interface{}) (sql.Result, error)
2323
}
2424

2525
func New(db DBTX) *Queries {

docs/howto/insert.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import (
1919
)
2020

2121
type DBTX interface {
22-
ExecContext(context.Context, string, ...interface{}) error
22+
ExecContext(context.Context, string, ...interface{}) (sql.Result, error)
2323
}
2424

2525
func New(db DBTX) *Queries {
@@ -79,8 +79,8 @@ type Author struct {
7979
}
8080

8181
type DBTX interface {
82-
ExecContext(context.Context, string, ...interface{}) error
83-
QueryRowContext(context.Context, string, ...interface{}) error
82+
ExecContext(context.Context, string, ...interface{}) (sql.Result, error)
83+
QueryRowContext(context.Context, string, ...interface{}) *sql.Row
8484
}
8585

8686
func New(db DBTX) *Queries {

docs/howto/prepared_query.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,11 @@ package db
1919
import (
2020
"context"
2121
"database/sql"
22+
"fmt"
2223
)
2324

2425
type Record struct {
25-
ID int
26+
ID int32
2627
}
2728

2829
type DBTX interface {
@@ -38,7 +39,7 @@ func Prepare(ctx context.Context, db DBTX) (*Queries, error) {
3839
q := Queries{db: db}
3940
var err error
4041
if q.getRecordStmt, err = db.PrepareContext(ctx, getRecord); err != nil {
41-
return nil, err
42+
return nil, fmt.Errorf("error preparing query GetRecord: %w", err)
4243
}
4344
return &q, nil
4445
}
@@ -73,11 +74,10 @@ SELECT id FROM records
7374
WHERE id = $1
7475
`
7576

76-
func (q *Queries) GetRecord(ctx context.Context, id int) (Record, error) {
77+
func (q *Queries) GetRecord(ctx context.Context, id int32) (int32, error) {
7778
row := q.queryRow(ctx, q.getRecordStmt, getRecord, id)
78-
var i Record
79-
err := row.Scan(&i.ID)
80-
return i, err
79+
err := row.Scan(&id)
80+
return id, err
8181
}
8282
```
8383

docs/howto/update.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import (
2626
)
2727

2828
type DBTX interface {
29-
ExecContext(context.Context, string, ...interface{}) error
29+
ExecContext(context.Context, string, ...interface{}) (sql.Result, error)
3030
}
3131

3232
func New(db DBTX) *Queries {
@@ -52,6 +52,12 @@ func (q *Queries) UpdateAuthorBios(ctx context.Context, bio string) error {
5252
If your query has more than one parameter, your Go method will accept a
5353
`Params` struct.
5454

55+
```sql
56+
-- name: UpdateAuthor :exec
57+
UPDATE authors SET bio = $2
58+
WHERE id = $1;
59+
```
60+
5561
```go
5662
package db
5763

@@ -61,7 +67,7 @@ import (
6167
)
6268

6369
type DBTX interface {
64-
ExecContext(context.Context, string, ...interface{}) error
70+
ExecContext(context.Context, string, ...interface{}) (sql.Result, error)
6571
}
6672

6773
func New(db DBTX) *Queries {

0 commit comments

Comments
 (0)