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
139 def self.extended(db)
140   db.instance_variable_set(:@comment_hashes, {})
141   db.extend_datasets DatasetSQLComments
142 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
149 def with_comments(comment_hash)
150   hashes = @comment_hashes
151   t = Sequel.current
152   new_hash = if hash = Sequel.synchronize{hashes[t]}
153     hash.merge(comment_hash)
154   else
155     comment_hash.dup
156   end
157   yield Sequel.synchronize{hashes[t] = new_hash}
158 ensure
159   if hash
160     Sequel.synchronize{hashes[t] = hash}
161   else
162     t && Sequel.synchronize{hashes.delete(t)}
163   end
164 end