Skip to content

Commit

Permalink
Merge pull request #45 from thedumbterminal/table_id_formats
Browse files Browse the repository at this point in the history
Support more ID formats when generating table IDs
  • Loading branch information
thedumbterminal authored Feb 12, 2021
2 parents 9c152ef + b6b845e commit 5737ccf
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 7 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## v4.0.1 (12/02/2021)

* Support more formats for table ID utility.

## v4.0.0 (24/12/2020)

* Dropped support for node 8.
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "jsonschema-bigquery",
"version": "4.0.0",
"version": "4.0.1",
"description": "Convert JSON schema to Google BigQuery schema",
"main": "src/converter.js",
"scripts": {
Expand Down
8 changes: 3 additions & 5 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@ const utils = module.exports = {}

// Expected format is "id": "/events/server/ecommerce/v5.1.5/schema.json"
utils.get_table_id = id => {
const idArr = id.split('/')
const type = idArr.slice(-4, -3)[0]
const name = idArr.slice(-3, -2)[0]
const version = idArr.slice(-2, -1)[0]
return type + '_' + name + '_' + version.split('.')[0]
const idArr = id.split('/').slice(2, -1)
const version = idArr.pop()
return idArr.join('_') + '_' + version.split('.')[0]
}

utils.inspector = obj => util.inspect(obj, {
Expand Down
14 changes: 14 additions & 0 deletions test/unit/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const utils = require('../../src/utils')
const assert = require('assert')

describe('utils', () => {
describe('get_table_id()', () => {
it('it supports a short path', () => {
assert.equal(utils.get_table_id('/events/one/two/v1.2.3/schema.json'), 'one_two_v1')
})

it('it supports a long path', () => {
assert.equal(utils.get_table_id('/events/one/two/three/four/v1.2.3/schema.json'), 'one_two_three_four_v1')
})
})
})

0 comments on commit 5737ccf

Please sign in to comment.