Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/oliveroneill/bigqueryswift
BigQuery client for Swift
https://github.com/oliveroneill/bigqueryswift
bigquery google-cloud-platform swift
Last synced: 4 months ago
JSON representation
BigQuery client for Swift
- Host: GitHub
- URL: https://github.com/oliveroneill/bigqueryswift
- Owner: oliveroneill
- License: mit
- Created: 2018-11-06T10:24:53.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2019-04-29T09:50:42.000Z (over 5 years ago)
- Last Synced: 2023-02-26T13:36:38.752Z (almost 2 years ago)
- Topics: bigquery, google-cloud-platform, swift
- Language: Swift
- Homepage:
- Size: 20.5 KB
- Stars: 12
- Watchers: 2
- Forks: 5
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# BigQuerySwift
[![Build Status](https://travis-ci.org/oliveroneill/BigQuerySwift.svg?branch=master)](https://travis-ci.org/oliveroneill/BigQuerySwift)
[![Platform](https://img.shields.io/badge/Swift-4.2-orange.svg)](https://img.shields.io/badge/Swift-4.2-orange.svg)
[![Swift Package Manager](https://img.shields.io/badge/spm-compatible-brightgreen.svg?style=flat)](https://swift.org/package-manager)
![macOS](https://img.shields.io/badge/os-macOS-green.svg?style=flat)
![Linux](https://img.shields.io/badge/os-linux-green.svg?style=flat)A [BigQuery](https://cloud.google.com/bigquery/) client for Swift.
## Installation
Add this to your Package.swift:```swift
.package(url: "https://github.com/oliveroneill/BigQuerySwift.git", .upToNextMajor(from: "0.0.1")),
```## Usage
To get an authentication from your service account:
```swift
let provider = BigQueryAuthProvider()
try! provider.getAuthenticationToken { response in
switch response {
case .token(let token):
// Your token to be passed into BigQueryClient
print(token)
case .error(_):
fatalError("Something went wrong.")
}
}
```
You'll need to copy your credentials file at `$GOOGLE_APPLICATION_CREDENTIALS`
to `credentials.json` in the directory that the binary is run in.To insert:
```swift
let client = BigQueryClient(
authenticationToken: "",
projectID: "",
datasetID: "",
tableName: ""
)
try client.insert(rows: rows) { response in
switch response {
case .error(let error):
fatalError("Error: " + error.localizedDescription)
case .bigQueryResponse(let response):
checkErrors(response.insertErrors)
}
}
```To query:
```swift
let query = "SELECT * FROM users"
try db.query(query) { (r: QueryCallResponse) in
switch r {
case .error(let e):
fatalError("Something went wrong.")
case .queryResponse(let result):
guard let result = result.rows else {
guard let errors = result.errors else {
fatalError("No errors and no rows.")
}
print("BigQuery errors: \(errors)")
return
}
printQueryResult(result)
}
}
```## Examples
For a working example, see [here](https://github.com/oliveroneill/WiltCollector/blob/bigquery-switch/Sources/WiltCollectorCore/BigQuery.swift).## Contributing
Feel free to help out. Currently only
[insertAll](https://cloud.google.com/bigquery/docs/reference/rest/v2/tabledata/insertAll)
is supported.