Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

sqlc sqlite and go routines #1883

Unanswered
mrjawright asked this question in Issue Triage
Discussion options

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.

You must be logged in to vote

Replies: 0 comments

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
1 participant

AltStyle によって変換されたページ (->オリジナル) /