module Sequel::Plugins::PreparedStatementsAssociations

  1. lib/sequel/plugins/prepared_statements_associations.rb

The prepared_statements_associations plugin modifies the regular association load method to use a cached prepared statement to load the associations. It will not work on all associations, but it should skip the use of prepared statements for associations where it will not work, assuming you load the plugin before defining the associations.

Note that in most cases, this plugin will probably make things slower, so you should only use it if you really want to use prepared statements to load associations.


# Make all model subclasses more safe when using prepared statements (called before loading subclasses)
Sequel::Model.plugin :prepared_statements_associations

# Make the Album class more safe when using prepared statements
Album.plugin :prepared_statements_associations



Synchronize access to the integer sequence so that no two calls get the same integer.

NEXT = lambda{MUTEX.synchronize{i += 1}}  

This plugin names prepared statements uniquely using an integer sequence, this lambda returns the next integer to use.