Running db sqlite query within a go call #24203
Unanswered
ImmanuelSamuel
asked this question in
Questions and Answers
Replies: 3 comments 4 replies
-
test could be used by several threads so is important to use fn test(shared dbs Dbs) ! {
lock dbs {
eprintln('test called')
login := Login{name: 'Test'}
sql dbs.db { insert login into Login } or { panic(err) }
foo := sql dbs.db { select count from Login } or { panic(err) }
eprintln('${foo}')
eprintln('test finished')
}
} |
Beta Was this translation helpful? Give feedback.
0 replies
-
Or, slightly nicer to the rest of the code: fn test(shared dbs Dbs) ! {
eprintln('test called')
login := Login{name: 'Test'}
lock dbs {
sql dbs.db { insert login into Login } or { panic(err) }
foo := sql dbs.db { select count from Login } or { panic(err) }
}
eprintln('${foo}')
eprintln('test finished')
} In other words, only lock when you need it. It's not needed around the |
Beta Was this translation helpful? Give feedback.
3 replies
-
If your data must be accessed by more than one user you can use the veb
module and share the database object in the endpoints functions and using
lock and the context to manage timeouts and the like.
…On Sun, Apr 13, 2025, 7:04 AM ImmanuelSamuel ***@***.***> wrote:
Thanks for the response - Yes, I already have a table that I am creating
things into and Yes I have already run the code without using 'go' and it
works for me too - my main question as stated in the discussion title is
how to do what you have shown above using 'go' and 'spawn' (async sql ops
essentially) - Thank you for the self-contained code above - hopefully
others can use this for testing.
—
Reply to this email directly, view it on GitHub
<#24203 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AA6A4WT7SB4TVCJTONWTUPD2ZJOGDAVCNFSM6AAAAAB3ANES62VHI2DSMVQWIX3LMV43URDJONRXK43TNFXW4Q3PNVWWK3TUHMYTEOBRHE2DGMA>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
The following code works without the 'go' based function call - what am I doing wrong here?
Beta Was this translation helpful? Give feedback.
All reactions