Skip to content

Commit

Permalink
Merge pull request #12 from thedumbterminal/script-fix
Browse files Browse the repository at this point in the history
Allow the jsbq command to be run directly
  • Loading branch information
thedumbterminal authored Oct 27, 2018
2 parents 4d11808 + 396b05c commit ed49cee
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 21 deletions.
Empty file added .eslintrc
Empty file.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ Note that some features involve bespoke interpretation of schema details suited

## Consume

node jsbq.js -p <gbq project> -d <gbq dataset> -j <json schema file>
jsbq -p <gbq project> -d <gbq dataset> -j <json schema file>

For embedded usage the following will allow and support runtime schema conversion and table maintenance:

const jsonSchemaBigquery = require('jsonschema-bigquery')
Expand All @@ -31,7 +31,7 @@ Please ensure that the input JSON schema is dereferenced so that all external re
## Test

npm test

A standalone test script is also included that supports batch creation of tables in a nominated test dataset

## TODO
Expand Down
18 changes: 10 additions & 8 deletions src/jsbq.js → bin/jsbq
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
#!/usr/bin/env node

const jsbq = module.exports = {}

const gbq = require('./gbq')
const util = require('./util')
const converter = require('./converter')
const gbq = require('../src/gbq')
const util = require('../src/util')
const converter = require('../src/converter')
const logger = require('log-driver').logger
const fs = require('fs')
const { promisify } = require('util')

jsbq.process = async (project, datasetName, jsonSchema) => {
logger.info('Processing json schema...')
// const tableOptions = jsonSchemaBigquery.convert(jsonSchema)
const tableOptions = converter.run(jsonSchema,'p','t')
logger.info(JSON.stringify(tableOptions))

Expand Down Expand Up @@ -35,16 +38,15 @@ jsbq.process = async (project, datasetName, jsonSchema) => {
}

jsbq.run = async () => {
const fs = require('fs')
const p = require('util')
const readFile = p.promisify(fs.readFile)
const readFile = promisify(fs.readFile)

const argv = require('yargs')
.usage('Usage: $0 -p [project] -d [dataset] -j [json schema file]')
.demandOption(['p', 'd', 'j'])
.argv

const jsonSchema = require('./' + argv.j)
const schemaData = await readFile(argv.j)
const jsonSchema = JSON.parse(schemaData)
logger.debug('Schema is: ' + JSON.stringify(jsonSchema))
await jsbq.process(argv.p, argv.d, jsonSchema)
}
Expand Down
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
"test": "mocha test",
"lint": "eslint ."
},
"bin": {
"jsbq": "./bin/jsbq"
},
"engines": {
"node": ">=8"
},
Expand Down
2 changes: 1 addition & 1 deletion test/samples/allOf/expected.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
{
"name": "names",
"type": "RECORD",
"mode": "NULLABLE",
"mode": "NULLABLE",
"fields": [
{
"name": "first_name",
Expand Down
2 changes: 1 addition & 1 deletion test/samples/allOf_nested/expected.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
{
"name": "address",
"type": "RECORD",
"mode": "NULLABLE",
"mode": "NULLABLE",
"fields": [
{
"name": "street_address",
Expand Down
2 changes: 1 addition & 1 deletion test/samples/complex/expected.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
{
"name": "address",
"type": "RECORD",
"mode": "NULLABLE",
"mode": "NULLABLE",
"fields":[
{
"name": "street_address",
Expand Down
14 changes: 7 additions & 7 deletions test/samples/oneof/expected.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@
},
{
"name": "string",
"description": "A string type data point for the tag",
"description": "A string type data point for the tag",
"type": "STRING",
"mode": "NULLABLE"
},
{
"name": "number",
"description": "A integer type data point for the tag",
"type": "INTEGER",
"mode": "NULLABLE"
}
{
"name": "number",
"description": "A integer type data point for the tag",
"type": "INTEGER",
"mode": "NULLABLE"
}
]
}
]
Expand Down

0 comments on commit ed49cee

Please sign in to comment.