scalikejdbc-bigquery

Build Status

ScalikeJDBC extension for Google BigQuery

Prerequisites

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

Installation

libraryDependencies ++= Seq(
  "com.mayreh" %% "scalikejdbc-bigquery" % "0.1.4",
  "com.google.cloud" % "google-cloud-bigquery" % "1.51.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.