Skip to content

Commit cd27c25

Browse files
committed
docs: fix SQLite tutorial CreateAuthor usage with RETURNING *
CreateAuthor is defined as :one with RETURNING *, so sqlc generates a method that returns Author, not sql.Result. The tutorial incorrectly called LastInsertId() on the result, which does not compile. Use the returned Author (matching the PostgreSQL tutorial) and compare the full structs after GetAuthor. Fixes #4468
1 parent 22d878a commit cd27c25

1 file changed

Lines changed: 4 additions & 9 deletions

File tree

docs/tutorials/getting-started-sqlite.md

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -159,28 +159,23 @@ func run() error {
159159
log.Println(authors)
160160
161161
// create an author
162-
result, err := queries.CreateAuthor(ctx, tutorial.CreateAuthorParams{
162+
insertedAuthor, err := queries.CreateAuthor(ctx, tutorial.CreateAuthorParams{
163163
Name: "Brian Kernighan",
164164
Bio: sql.NullString{String: "Co-author of The C Programming Language and The Go Programming Language", Valid: true},
165165
})
166166
if err != nil {
167167
return err
168168
}
169-
170-
insertedAuthorID, err := result.LastInsertId()
171-
if err != nil {
172-
return err
173-
}
174-
log.Println(insertedAuthorID)
169+
log.Println(insertedAuthor)
175170
176171
// get the author we just inserted
177-
fetchedAuthor, err := queries.GetAuthor(ctx, insertedAuthorID)
172+
fetchedAuthor, err := queries.GetAuthor(ctx, insertedAuthor.ID)
178173
if err != nil {
179174
return err
180175
}
181176
182177
// prints true
183-
log.Println(reflect.DeepEqual(insertedAuthorID, fetchedAuthor.ID))
178+
log.Println(reflect.DeepEqual(insertedAuthor, fetchedAuthor))
184179
return nil
185180
}
186181

0 commit comments

Comments
 (0)