-
Notifications
You must be signed in to change notification settings - Fork 943
sqlc sqlite and go routines #1883
Unanswered
mrjawright
asked this question in
Issue Triage
-
is there anything special that needs to be done to use the generated code in a go routine?
I'm doing an asynchronous proof-of-concept using go routines and channels, and I keep getting 'no such table' errors when ever I try to read from the returned channels.
func (q *Queries) GetAllUsersAsync(ctx context.Context) (<-chan GetAllUsersAsyncResult, <-chan error) {
outCh := make(chan GetAllUsersAsyncResult)
errCh := make(chan error)
go func(ctx context.Context) {
out, err := q.GetAllUsers(ctx)
if err != nil {
errCh <- err
} else {
outCh <- GetAllUsersAsyncResult{Users: out}
}
close(outCh)
}(ctx)
return outCh, errCh
}
in my main.go, I call the async function:
usersOutCh, usersErrCh := queries.GetAllUsersAsync(ctx)
Then, later, I check the channels:
select {
case result := <-usersOutCh:
fmt.Println("Async Users Results...")
fmt.Println((result).AsString())
case err := <-usersErrCh:
fmt.Println(err.Error())
}
But, when it runs, I get no such table: users
event though I can query the table and pull back all the rows outside of a go routine.
Beta Was this translation helpful? Give feedback.
All reactions
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment