ScalikeJDBC extension for Google BigQuery
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
project
src
.gitignore
.travis.yml
LICENSE
README.md
build.sbt
sonatype.sbt

README.md

scalikejdbc-bigquery

Build Status

ScalikeJDBC extension for Google BigQuery

Prerequisites

  • Java 8
  • Scala 2.11.x / 2.12.x
  • ScalikeJDBC 2.4.x or newer

Installation

libraryDependencies ++= Seq(
  "com.mayreh" %% "scalikejdbc-bigquery" % "0.1.1",
  "com.google.cloud" % "google-cloud-bigquery" % "1.41.0",
  "org.scalikejdbc" %% "scalikejdbc" % scalikejdbcVersion // specify scalikejdbc version you want. 
)

Usage

import com.google.auth.oauth2.GoogleCredentials
import com.google.cloud.bigquery.{BigQueryOptions, DatasetId}
import scalikejdbc._, bigquery._

// instantiate BigQuery service and DatsetId
val credentials = GoogleCredentials.fromStream(new FileInputStream("/path/to/key.json"))
val bigQuery = BigQueryOptions.newBuilder()
  .setCredentials(credentials)
  .setProjectId("your-gcp-project-id")
  .build()
  .getService
  
val dataset = DatasetId.of("your-gcp-project-id", "your-dataset")

// build query by QueryDSL then execute
val executor = new QueryExecutor(bigQuery, QueryConfig())

val response = bq {
  selectFrom(User in dataset as u)
    .where.eq(u.id, 42)
}.map(User(_)).single.run(executor)

response.result // => Option[User]

See also integration test.

Current status

This project is still in an early stage. Newer releases can include breaking changes.

Be careful using in production.