Skip to content

Business intelligence made simple

Added comments to queries

Andrew Kane032b8fa6db29
diff --git a/CHANGELOG.md b/CHANGELOG.md
index ce0d2382..f7cb87fa 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,6 +1,7 @@
## 1.0.1 [unreleased]
- Added `user_method` option
+- Added comments to queries
## 1.0.0
diff --git a/app/controllers/blazer/queries_controller.rb b/app/controllers/blazer/queries_controller.rb
index 895f8b3b..382dcf05 100644
--- a/app/controllers/blazer/queries_controller.rb
+++ b/app/controllers/blazer/queries_controller.rb
@@ -65,7 +65,7 @@ module Blazer
end
@data_source = Blazer.data_sources[data_source]
- @rows, @error = @data_source.run_statement(@statement)
+ @rows, @error = @data_source.run_statement(@statement, user: blazer_user, query: @query)
if @query && [email protected]_s.include?("canceling statement due to statement timeout")
@query.checks.each do |check|
diff --git a/lib/blazer/data_source.rb b/lib/blazer/data_source.rb
index 0cd67973..f8ca46f5 100644
--- a/lib/blazer/data_source.rb
+++ b/lib/blazer/data_source.rb
@@ -34,13 +34,20 @@ module Blazer
settings["timeout"]
end
- def run_statement(statement)
+ def run_statement(statement, options = {})
rows = []
error = nil
begin
connection_model.transaction do
connection_model.connection.execute("SET statement_timeout = #{timeout.to_i * 1000}") if timeout && postgresql?
- result = connection_model.connection.select_all(statement)
+ comment = "blazer"
+ if options[:user].respond_to?(:id)
+ comment << ",user_id:#{options[:user].id}"
+ end
+ if options[:query].respond_to?(:id)
+ comment << ",query_id:#{options[:query].id}"
+ end
+ result = connection_model.connection.select_all("#{statement} /*#{comment}*/")
result.each do |untyped_row|
row = {}
untyped_row.each do |k, v|