Project

bigqueryid

0.0
Repository is archived
No commit activity in last 3 years
No release in over 3 years
Simple ORM for Google BigQuery
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.13
~> 5.0
~> 10.0

Runtime

 Project Readme

BigQueryID

BigQueryID is an ORM (Object-Relational-Mapper) framework for Google BigQuery in Ruby.

Install

gem build bigqueryid.gem
gem install bigqueryid-<version>.gem

or

gem 'bigqueryid'

Configure

export GCLOUD_PROJECT=my-todo-project-id
export GCLOUD_KEYFILE_JSON=/path/to/keyfile.json

Use

# Define product model product.rb
class Product

  include Bigquery::Base

  dataset 'core'
  table 'products'

  field :name,  type: String
  field :price, type: Float
  field :barcode

  def self.create_table
    bigquery.dataset(self.dataset_name).create_table self.table_name do |schema|
      schema.string 'barcode'
      schema.timestamp 'created_at'
      schema.integer 'id'
      schema.string 'name'
      schema.float 'price'
      schema.timestamp 'updated_at'
    end unless table_exist?
  end

  def self.fetch_all
    sql = <<-SQL.squish
      SELECT
       *
      FROM core.products
      ORDER BY
        P.name
    SQL
    fetch sql
  end
end

# Return if table exists
Product.table_exist?

# Delete table
Product.delete_table

# Delete and create table
Product.flush

# Fetch all rows
Product.fetch_all