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

how to use sqlc without context ? #1837

Answered by kyleconroy
topben asked this question in Q&A
Discussion options

hi guys: I have a cron job to do ( fetch third party data and save it to DB)
and have to write to the postgres database.
sqlc requires ctx context.Context but i am not writing an api for a client to call.
that means no request context via browser. all i want to do is simply write the fetched data to database.
I guess i have three options:

  1. just remove the ctx of the generated codes
  2. fake a useless ctx in order to write things into db
  3. use other golang tools and directly write sql statement (any recommendation ?
    is there any better solution ? or i am just wrong with something ?
You must be logged in to vote

Contexts are very easy to create. A simple context.Background() will suffice.

Replies: 1 comment 1 reply

Comment options

Contexts are very easy to create. A simple context.Background() will suffice.

You must be logged in to vote
1 reply
Comment options

got it , thank you!

Answer selected by kyleconroy
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet

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