Skip to content

Instantly share code, notes, and snippets.

@stephenplusplus
Last active February 27, 2019 20:54
Show Gist options
  • Save stephenplusplus/66844bf76a78b455633e1f86c0b4b7e1 to your computer and use it in GitHub Desktop.
Save stephenplusplus/66844bf76a78b455633e1f86c0b4b7e1 to your computer and use it in GitHub Desktop.
GOOGLE_APPLICATION_CREDENTIALS=/Users/stephen/dev/key.json
We can make this file beautiful and searchable if this error is corrected: No commas found in this CSV file in line 0.
{ "name": "name1" }
{ "name": "name2" }
{ "name": "name3" }
'use strict'
require('dotenv').config()
const {BigQuery} = require('@google-cloud/bigquery')
const bigquery = new BigQuery()
const dataset = bigquery.dataset(`dataset_${Date.now()}`)
const table = dataset.table('names')
dataset.create()
.then(() => table.create({schema:'name:string'}))
.then(() => table.createLoadJob('./data.csv'))
.then(([job]) => new Promise((y, n) => job.on('error', n).on('complete', y)))
.then(() => table.query('SELECT * FROM `names`'))
.then(([rows]) => console.log(`${rows.length === 3 ? 'Yay!' : 'No :('}`))
.then(() => dataset.delete({force:true}), () => dataset.delete({force:true}))
{
"name": "gissue-361",
"version": "1.0.0",
"description": "",
"main": "index.js",
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"@google-cloud/bigquery": "^2.0.6",
"dotenv": "^6.2.0"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment