Skip to content
This repository has been archived by the owner on Apr 4, 2024. It is now read-only.

Add method .where to search rows #6

Merged
merged 3 commits into from
Jan 10, 2017
Merged

Add method .where to search rows #6

merged 3 commits into from
Jan 10, 2017

Conversation

vyper
Copy link
Contributor

@vyper vyper commented Jan 9, 2017

No description provided.

" WHERE #{where.join(' AND ')}"

result = bigquery.query(query, params: filter)
result.map do |row|
Copy link
Contributor

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?

Copy link
Contributor Author

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
Copy link
Contributor

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}"
Copy link

@tiagopog tiagopog Jan 9, 2017

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}" 🤔

Copy link
Contributor Author

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

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.

@vyper vyper merged commit 802ea87 into master Jan 10, 2017
@vyper vyper deleted the feature/where branch January 10, 2017 13:20
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants