-
Notifications
You must be signed in to change notification settings - Fork 0
Conversation
" WHERE #{where.join(' AND ')}" | ||
|
||
result = bigquery.query(query, params: filter) | ||
result.map do |row| |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Acho que é uma boa a gente não misturar a parte da query
com a de pegar os resultados e instancializar os registros. Deixando separado viabiliza até a gente transformar esse where
num método passível de composição que nem no ActiveRecord: MyModel.where(...).where(...)
.
A gem do Bigqueryid
já não tem um método de classe .fetch_all
pra instancializar os registros?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Eu acho que esse caminho é o futuro sim, até para esse objeto retornar um queryable em si e que possa receber outros filtros... até de ordenação.
Mas por enquanto, para não prolongar muito a coisa, pensei apenas na assinatura da coisa com um where, um hash de filtros e acabou...
@@ -0,0 +1,72 @@ | |||
module Bigqueryid | |||
class Coercer |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Boa sacada essa de separar a parte de coerção numa classe à parte!
where = [] | ||
filter.each do |key, value| | ||
filter[key] = coercer.coerce(key, value) | ||
where << "#{key} = @#{key}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Essa linha era pra ser assim mesmo? Não saquei qualé a do trecho: ... = @#{key}"
🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Retirado da documentação
require "google/cloud/bigquery"
bigquery = Google::Cloud::Bigquery.new
data = bigquery.query "SELECT name FROM my_table WHERE id = @id",
params: { id: 1 }
data.each do |row|
puts row["name"]
end
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Legal, @vyper! Valeu pelo esclarecimento.
No description provided.