lib/etht/bigquery.rb in etht-0.1.8 vs lib/etht/bigquery.rb in etht-0.1.9
- old
+ new
@@ -13,10 +13,12 @@
attr_reader :api
# @return [Google::Cloud::Bigquery::QueryJob] job bigquery
attr_reader :job
# @return [Thor::CoreExt::HashWithIndifferentAccess] opcoes trabalho
attr_reader :ops
+ # @return (see sql)
+ attr_reader :sqr
# @param [Thor::CoreExt::HashWithIndifferentAccess] pop opcoes trabalho
# @option pop [Hash] :h ({}) configuracao ajuste reposicionamento temporal
# @option pop [Boolean] :v (false) mostra transacoes normais & token?
# @option pop [Boolean] :t (false) mostra transacoes todas ou somente novas?
@@ -129,31 +131,32 @@
"#{Integer(ops[:h][hes['blockNumber']] || 0)})"
end
# cria job bigquery & verifica execucao
#
- # @param [String] sql a executar
+ # @param cmd (see sql)
# @return [Boolean] job ok?
- def job?(sql)
- @job = api.query_job(sql)
+ def job?(cmd)
+ @job = api.query_job(cmd)
@job.wait_until_done!
puts(@job.error['message']) if @job.failed?
@job.failed?
end
- # cria Data Manipulation Language (DML) job bigquery
+ # cria Structured Query Language (SQL) job bigquery
#
- # @param (see job?)
- # @return [Integer] numero linhas afetadas
- def dml(sql)
- job?(sql) ? 0 : job.num_dml_affected_rows
+ # @param [String] cmd comando SQL a executar
+ # @param [String] red resultado quando SQL tem erro
+ # @return [Google::Cloud::Bigquery::Data] resultado do SQL
+ def sql(cmd, red = [])
+ @sqr = job?(cmd) ? red : job.data
end
- # cria Structured Query Language (SQL) job bigquery
+ # cria Data Manipulation Language (DML) job bigquery
#
- # @param (see job?)
- # @return [Array<Hash>] resultados do SQL
- def sql(sql)
- job?(sql) ? [] : job.data
+ # @param cmd (see sql)
+ # @return [Integer] numero linhas afetadas
+ def dml(cmd)
+ job?(cmd) ? 0 : job.num_dml_affected_rows
end
end
end