I started using the Sequel Gem in early 2020, and my first code is now 
hitting our production servers.  I really love the clean DSL and the 
performance of Sequel.  Far better than the Rails ActiveRecord ORM.

I'm using ruby 2.7, MySQL 5.6, and Sequel 5.28.0.

One of the challenges I've had is around the connection pool.  There are 
times when I want to guarantee that a consecutive set of calls is run on 
the same DB connection.  For example:

    DB.transaction do
      DB.run "drop temporary table if exists mav_left_right"
      DB.run "create temporary table mav_left_right(
        id int(11),
        lft int(11) DEFAULT NULL,
        rgt int(11) DEFAULT NULL, 
        primary key (id))
      "

I currently have that wrapped in a DB transaction to ensure that both 
statements execute on the same connection.  I'd prefer not to use a 
transaction here.

The problem I'm having is occasionally I hit an exception in the above code 
where 
Sequel::DatabaseError:  Mysql2::Error: Table 'mav_left_right' already exists

If those 2 statements are running in a transaction, it should be impossible 
that that happens.  If they are hitting separate connections, however, it 
could happen.  

So my question is whether there is a way to temporarily check out a 
connection from the pool, execute a few statements, and then return the 
connection to the pool?  I tried to find this myself from the code but have 
not succeeded yet.

Thank you very much,
Eric Hansen

-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sequel-talk/745de698-0016-4b0f-b030-a1a1dd32338cn%40googlegroups.com.

Reply via email to