module Sequel::Database::SQLComments

Attributes

comment_hashes[R]

A map of threads to comment hashes, used for correctly setting comments for all queries inside with_comments blocks.

Public Class Methods

extended(db) click to toggle source
    # File lib/sequel/extensions/sql_comments.rb
143 def self.extended(db)
144   db.instance_variable_set(:@comment_hashes, {})
145   db.extend_datasets DatasetSQLComments
146 end

Public Instance Methods

with_comments(comment_hash) { |synchronize{hashes = new_hash}| ... } click to toggle source

Store the comment hash and use it to create comments inside the block

    # File lib/sequel/extensions/sql_comments.rb
153 def with_comments(comment_hash)
154   hashes = @comment_hashes
155   t = Sequel.current
156   new_hash = if hash = Sequel.synchronize{hashes[t]}
157     hash.merge(comment_hash)
158   else
159     comment_hash.dup
160   end
161   yield Sequel.synchronize{hashes[t] = new_hash}
162 ensure
163   if hash
164     Sequel.synchronize{hashes[t] = hash}
165   else
166     t && Sequel.synchronize{hashes.delete(t)}
167   end
168 end