Skip to content

docs: fix SQLite tutorial CreateAuthor usage with RETURNING *#4511

Open
Abhineshhh wants to merge 1 commit into
sqlc-dev:mainfrom
Abhineshhh:fix/4468-sqlite-tutorial-create-author
Open

docs: fix SQLite tutorial CreateAuthor usage with RETURNING *#4511
Abhineshhh wants to merge 1 commit into
sqlc-dev:mainfrom
Abhineshhh:fix/4468-sqlite-tutorial-create-author

Conversation

@Abhineshhh

Copy link
Copy Markdown

Summary

  • The SQLite getting-started tutorial defines CreateAuthor as :one with RETURNING *, so sqlc generates (Author, error), not sql.Result.
  • The Go example incorrectly treated the return value as sql.Result and called LastInsertId(), which does not compile.
  • Update the example to use the returned Author (same pattern as the PostgreSQL tutorial) and compare full structs after GetAuthor.

Fixes #4468

Verification

  1. Generated code from the tutorial schema.sql / query.sql with a local sqlc build:
    • CreateAuthor(ctx, CreateAuthorParams) (Author, error)
    • GetAuthor(ctx, id int64) (Author, error)
    • Author{ID int64; Name string; Bio sql.NullString}
  2. Compiled and ran the fixed tutorial.go end-to-end with modernc.org/sqlite and an in-memory DB.
  3. Program output included true from reflect.DeepEqual(insertedAuthor, fetchedAuthor).

Test plan

  • Confirmed generated signatures match the fixed example
  • go build and run of the full tutorial program succeeds
  • Docs render as expected after merge

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 sqlc-dev#4468
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SQLite getting-started tutorial uses LastInsertId() on RETURNING * result

1 participant