On Monday, September 17, 2018 at 12:56:39 PM UTC-7, p...@affinity.co wrote:
>
> We want to use DB.synchronize to make multiple requests using the same 
> connection. How do you use the `conn` variable passed to the synchronize 
> block? Or do calls to DB inside the block automatically use the connection?
>

The same connection will be used inside the block if the thread is the same 
and the server is the same (the server is always the same if not using a 
sharded connection pool).
 

> If it's the second (requests just automatically use the reserved 
> connection), is there any to get access to the regular connection pool 
> while inside that block? (We have some messy stuff where we want to make 
> some queries outside of a transaction while the transaction is running.)
>

The easiest way is to use a separate thread for that, which can be joined 
immediately if you want synchronous behavior:

  Thread.new{...}.join
 
If you are using a sharded connection pool, you can also use a separate 
shard.  It's possible to use the sharded connection pool with a single 
database:

  DB = Sequel.connect(..., :servers=>{:alt=>{}})

Then you can specify the :alt shard to use the alternative connection pool, 
with all connection parameters being the same as the default pool.  If 
using the sharded connection pool approach, consider also using the 
server_block extension.

Related, given an instance of a Sequel::Model, how can we be sure that an 
> `update` or `save` command uses a specific database connection?
>

Same principal applies here (separate thread or shard). With a sharded 
connection pool you can also specify the shard when calling Model#save via 
the :server option.

Thanks,
Jeremy 

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

Reply via email to