In Go, you can simply create a CreateDatabase() function which initializes
your prepared statements, in lieu of the constructor.

When doing a SQL query, you must use the correct prepared statement for it,
so whether you have an array of them, or each is its own field, each
handler would have to use the correct Statement. Is this different in Java
somehow, does it automatically use the correct prepared statement or
something?

-- Marcin

On Sun, Apr 14, 2019 at 3:17 AM Shrinath agarwal <shrinath...@gmail.com>
wrote:

> Hi Marcin,
>
> I know about Prepare function supported by sql package .My initial
> question was what is better way to pass multiple prepare statements on
> different http handlers .
> ex: we can construct struct like this
>
> type Database struct {
>     db *sql.DB
>
>     someStmt *sql.Stmt
>     // etc.
> }
> but since we have multiple prepare statements this struct will keep on
> increasing so my question was is there any better way provided in golang
> like in java (where we can initialize prepare statement in class
> constructor and use that )
>
> On Sun, Apr 14, 2019 at 7:59 AM Marcin Romaszewicz <marc...@gmail.com>
> wrote:
>
>> Do you mean a SQL prepared statement?
>>
>> Check out the database/sql package. The database connection abstraction
>> has a Prepare function which creates a statement. Keep in mind, that based
>> on your level of concurrency, the statement will be re-prepared in each new
>> connection that's opened up on your behalf. So, what you need to do is keep
>> a persistent instance of sql.DB, which will try to maintain your prepared
>> statements for you.
>>
>>
>> On Sat, Apr 13, 2019 at 10:58 AM <shrinath...@gmail.com> wrote:
>>
>>> Hi Team ,
>>> I am new in go lang ,I want to know is there any recommended way in go
>>> lang to create prepare statement in go lang on application start and pass
>>> it to multiple http handler so that query can be done inside those http
>>> handlers.
>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "golang-nuts" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to golang-nuts+unsubscr...@googlegroups.com.
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>
> --
>
> Thanks and Regards,
>
>
>
> Shri Nath Agarwal
>
> Mobile 9482060723
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to