module Sequel::Database::SQLComments

def self.extended(db)

def self.extended(db)
  db.instance_variable_set(:@comment_hashes, {})
  db.extend_datasets DatasetSQLComments
end

def with_comments(comment_hash)

Store the comment hash and use it to create comments inside the block
def with_comments(comment_hash)
  hashes = @comment_hashes
  t = Sequel.current
  new_hash = if hash = Sequel.synchronize{hashes[t]}
    hash.merge(comment_hash)
  else
    comment_hash.dup
  end
  yield Sequel.synchronize{hashes[t] = new_hash}
ensure
  if hash
    Sequel.synchronize{hashes[t] = hash}
  else
    t && Sequel.synchronize{hashes.delete(t)}
  end
end