Skip to content

Commit 784bf52

Browse files
committed
update readme
1 parent de38b6f commit 784bf52

File tree

1 file changed

+54
-6
lines changed

1 file changed

+54
-6
lines changed

README.md

+54-6
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,15 @@ This CLI tool reads a JSON file and produces BigQuery compatible SQL views from
1010
## Usage
1111

1212
```bash
13-
npx @nealwp/blobview@latest <filepath>
13+
npx @nealwp/blobview [options] <filepath>
14+
15+
Arguments:
16+
filepath path to valid JSON file
17+
18+
Options:
19+
-t TABLE, --table=TABLE specify a table name to use in FROM clause. default: "<table>"
20+
-d DATASET, --dataset=DATASET specify a dataset to use in FROM clause. default: "<dataset>"
21+
-h, --help show help
1422
```
1523

1624
## Examples:
@@ -19,6 +27,13 @@ Default output to STDOUT:
1927
npx @nealwp/blobview@latest ./path/to/file.json
2028
```
2129

30+
Dataset and table as input options:
31+
```bash
32+
npx @nealwp/blobview@latest --dataset=myDataset --table=myTable ./path/to/file.json
33+
# shorthand options
34+
npx @nealwp/blobview@latest -d myDataset -t myTable ./path/to/file.json
35+
```
36+
2237
Redirect output to file:
2338
```bash
2439
npx @nealwp/blobview@latest ./path/to/file.json > my-view-file.sql
@@ -32,6 +47,7 @@ npx @nealwp/blobview@latest ./path/to/file.json > my-view-file.sql
3247
* Auto-formats column names to snake_case from camelCase and PascalCase
3348
* Detects deeply-nested objects and formats to JSON string
3449
* Pre-populates FROM clause with BigQuery-style placeholders
50+
* BigQuery dataset and table name can be supplied as input options
3551

3652
## Limitations
3753
* Does not detect DATE or TIMESTAMP types, or other types like BOOLEAN
@@ -40,7 +56,7 @@ npx @nealwp/blobview@latest ./path/to/file.json > my-view-file.sql
4056
* Does not create SQL views in any syntax other than BigQuery
4157
* Requires a local JSON file to read
4258
* Does not include option to write queries to separate files instead of STDOUT
43-
* BigQuery project, dataset, and datastream names cannot be supplied as input
59+
* BigQuery project name cannot be supplied as input
4460

4561
## Example Output
4662

@@ -100,20 +116,52 @@ SELECT
100116
, CAST(JSON_VALUE(json_blob.integerField) as INTEGER) as integer_field
101117
, CAST(JSON_VALUE(json_blob.decimalField) as DECIMAL) as decimal_field
102118
, TO_JSON_STRING(json_blob.exampleGeoJson) as example_geo_json
103-
FROM <project>.<datastream>.<dataset>
119+
FROM <project>.<dataset>.<table>
120+
/**/
121+
SELECT
122+
CAST(JSON_VALUE(json_blob.childField1.gender) as STRING) as gender
123+
, CAST(JSON_VALUE(json_blob.childField1.latitude) as DECIMAL) as latitude
124+
FROM <project>.<dataset>.<table>
125+
/**/
126+
SELECT
127+
CAST(JSON_VALUE(json_blob.childField2.favoriteFruit) as STRING) as favorite_fruit
128+
, CAST(JSON_VALUE(json_blob.childField2.longitude) as DECIMAL) as longitude
129+
FROM <project>.<dataset>.<table>
130+
/**/
131+
SELECT
132+
CAST(JSON_VALUE(json_blob.childWithNestedObject.isNormal) as STRING) as is_normal
133+
, TO_JSON_STRING(json_blob.childWithNestedObject.nestedObject) as nested_object
134+
FROM <project>.<dataset>.<table>
135+
```
136+
137+
```bash
138+
# terminal command with input options
139+
npx @nealwp/blobview --dataset=myDataset --table=myTable sample-data.json
140+
```
141+
142+
Will produce the following output:
143+
144+
```sql
145+
/* stdout */
146+
SELECT
147+
CAST(JSON_VALUE(json_blob.stringField) as STRING) as string_field
148+
, CAST(JSON_VALUE(json_blob.integerField) as INTEGER) as integer_field
149+
, CAST(JSON_VALUE(json_blob.decimalField) as DECIMAL) as decimal_field
150+
, TO_JSON_STRING(json_blob.exampleGeoJson) as example_geo_json
151+
FROM <project>.myDataset.myTable
104152
/**/
105153
SELECT
106154
CAST(JSON_VALUE(json_blob.childField1.gender) as STRING) as gender
107155
, CAST(JSON_VALUE(json_blob.childField1.latitude) as DECIMAL) as latitude
108-
FROM <project>.<datastream>.<dataset>
156+
FROM <project>.myDataset.myTable
109157
/**/
110158
SELECT
111159
CAST(JSON_VALUE(json_blob.childField2.favoriteFruit) as STRING) as favorite_fruit
112160
, CAST(JSON_VALUE(json_blob.childField2.longitude) as DECIMAL) as longitude
113-
FROM <project>.<datastream>.<dataset>
161+
FROM <project>.myDataset.myTable
114162
/**/
115163
SELECT
116164
CAST(JSON_VALUE(json_blob.childWithNestedObject.isNormal) as STRING) as is_normal
117165
, TO_JSON_STRING(json_blob.childWithNestedObject.nestedObject) as nested_object
118-
FROM <project>.<datastream>.<dataset>
166+
FROM <project>.myDataset.myTable
119167
```

0 commit comments

Comments
 (0)