module Database::SQLComments

  1. lib/sequel/extensions/sql_comments.rb

Methods

Public Class

  1. extended

Public Instance

  1. comment_hashes
  2. with_comments

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)
[show 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)

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

[show source]
    # 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