Skip to content

Commit 3fa3e6e

Browse files
committed
feat(first): added documentation to query-annnotations.md
1 parent e6bf21c commit 3fa3e6e

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

docs/reference/query-annotations.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,25 @@ func (q *Queries) GetAuthor(ctx context.Context, id int64) (Author, error) {
113113
}
114114
```
115115

116+
## `:first`
117+
118+
The generated method will return a pointer to a single record via
119+
[QueryRowContext](https://golang.org/pkg/database/sql/#DB.QueryRowContext).
120+
If there are no results, it returns `nil, nil`.
121+
122+
```sql
123+
-- name: GetAuthor :first
124+
SELECT * FROM authors
125+
WHERE id = $1 LIMIT 1;
126+
```
127+
128+
```go
129+
func (q *Queries) GetAuthor(ctx context.Context, id int64) (*Author, error) {
130+
row := q.db.QueryRowContext(ctx, getAuthor, id)
131+
// ...
132+
}
133+
```
134+
116135
## `:batchexec`
117136

118137
__NOTE: This command only works with PostgreSQL using the `pgx/v4` and `pgx/v5` drivers and outputting Go code.__

0 commit comments

Comments
 (0)