Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

54 Commits

Repository files navigation

Blanton

  • Blanton is a BigQuery library written by Elixir.

Installation

  1. Add Blanton to your list of dependencies in mix.exs:
defdepsdo[{:blanton,"~> 0.1.4"}]end
  1. Pass in your credentials json downloaded from your GCE account:
config:goth,json: "path/to/google/json/creds.json"|>File.read!
  1. If you have one dataset to operate on, you can also set it first.
config:blanton,project_id: "",dataset_id: ""

You can do

  • Dataset
    • Create
    • Delete
  • Table
    • Select
    • Create
    • Create(Option usable)
    • Update
    • Delete
  • Record
    • Insert

Usage

  • Create table
columns=[%{name: "name",mode: :string,type: :required},%{name: "age",mode: :int64,type: :nullable}]table=Blanton.Table.new("users",columns)Blanton.Table.create("PROJECT_ID","DATASET_ID",table)# if you set dataset_id and project_id to config.exsBlanton.Table.create(table)
  • Insert record
records=[%{name: "安室透",age: 29},%{name: "赤井秀一",age: 32},]table_name="users"Blanton.Record.insert("PROJECT_ID","DATASET_ID",table_name,records)# if you set dataset_id and project_id to config.exsBlanton.Record.insert(table_name,records)
  • Create migration file
# lib/APP_NAME/bq_schema/TABLE_NAME.exdefmoduleAPP_NAME.BqSchema.TABLE_NAMEdouseBlanton.Schemaschema:TABLE_NAMEdofield:column_name,:string,:requiredfield:some_field_column,:record,:repeated,[sub_field(:name,:string,:nullable),sub_field(:price,:int64,:nullable),]end# options do# partitiondate# register :timePartitioning, %GoogleApi.BigQuery.V2.Model.TimePartitioning{type: "DAY"}# endend
  • Select records
Query.table("users")|>Query.pluck(["name","age"])|>Query.where([age: 31])|>Query.limit(10)|>Query.run|>Query.to_records
  • After creating the file, run the following command.
    • mix bq.migrate lib/bq_schema
  • If you want to delete the table use the following command
    • mix bq.drop
    • Please be careful because it cannot be stopped even if you execute it by mistake.

About

BigQuery API wrapped by Elixir

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages