@@ -10,7 +10,17 @@ This CLI tool reads a JSON file and produces BigQuery compatible SQL views from
1010## Usage
1111
1212``` bash
13- npx @nealwp/blobview < filepath>
13+ npx @nealwp/blobview@latest [options] < filepath>
14+ ```
15+
16+ ``` text
17+ Arguments:
18+ filepath path to valid JSON file
19+
20+ Options:
21+ -t TABLE, --table=TABLE specify a table name to use in FROM clause. default: "<table>"
22+ -d DATASET, --dataset=DATASET specify a dataset to use in FROM clause. default: "<dataset>"
23+ -h, --help show help
1424```
1525
1626## Examples:
@@ -19,9 +29,16 @@ Default output to STDOUT:
1929npx @nealwp/blobview ./path/to/file.json
2030```
2131
32+ Dataset and table as input options:
33+ ``` bash
34+ npx @nealwp/blobview --dataset=myDataset --table=myTable ./path/to/file.json
35+ # shorthand options
36+ npx @nealwp/blobview -d myDataset -t myTable ./path/to/file.json
37+ ```
38+
2239Redirect output to file:
2340``` bash
24- npx @nealwp/blobview ./path/to/file.json > my-view-file.sql
41+ npx @nealwp/blobview@latest ./path/to/file.json > my-view-file.sql
2542```
2643
2744## Features
@@ -32,6 +49,7 @@ npx @nealwp/blobview ./path/to/file.json > my-view-file.sql
3249* Auto-formats column names to snake_case from camelCase and PascalCase
3350* Detects deeply-nested objects and formats to JSON string
3451* Pre-populates FROM clause with BigQuery-style placeholders
52+ * BigQuery dataset and table name can be supplied as input options
3553
3654## Limitations
3755* Does not detect DATE or TIMESTAMP types, or other types like BOOLEAN
@@ -40,7 +58,7 @@ npx @nealwp/blobview ./path/to/file.json > my-view-file.sql
4058* Does not create SQL views in any syntax other than BigQuery
4159* Requires a local JSON file to read
4260* 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
61+ * BigQuery project name cannot be supplied as input
4462
4563## Example Output
4664
@@ -100,20 +118,52 @@ SELECT
100118 , CAST(JSON_VALUE(json_blob .integerField ) as INTEGER ) as integer_field
101119 , CAST(JSON_VALUE(json_blob .decimalField ) as DECIMAL ) as decimal_field
102120 , TO_JSON_STRING(json_blob .exampleGeoJson ) as example_geo_json
103- FROM < project> .< datastream> .< dataset>
104- -- ------
121+ FROM < project> .< dataset> .< table>
122+ /**/
123+ SELECT
124+ CAST(JSON_VALUE(json_blob .childField1 .gender) as STRING) as gender
125+ , CAST(JSON_VALUE(json_blob .childField1 .latitude) as DECIMAL ) as latitude
126+ FROM < project> .< dataset> .< table>
127+ /**/
128+ SELECT
129+ CAST(JSON_VALUE(json_blob .childField2 .favoriteFruit) as STRING) as favorite_fruit
130+ , CAST(JSON_VALUE(json_blob .childField2 .longitude) as DECIMAL ) as longitude
131+ FROM < project> .< dataset> .< table>
132+ /**/
133+ SELECT
134+ CAST(JSON_VALUE(json_blob .childWithNestedObject .isNormal) as STRING) as is_normal
135+ , TO_JSON_STRING(json_blob .childWithNestedObject .nestedObject) as nested_object
136+ FROM < project> .< dataset> .< table>
137+ ```
138+
139+ ``` bash
140+ # terminal command with input options
141+ npx @nealwp/blobview --dataset=myDataset --table=myTable sample-data.json
142+ ```
143+
144+ Will produce the following output:
145+
146+ ``` sql
147+ /* stdout */
148+ SELECT
149+ CAST(JSON_VALUE(json_blob .stringField ) as STRING) as string_field
150+ , CAST(JSON_VALUE(json_blob .integerField ) as INTEGER ) as integer_field
151+ , CAST(JSON_VALUE(json_blob .decimalField ) as DECIMAL ) as decimal_field
152+ , TO_JSON_STRING(json_blob .exampleGeoJson ) as example_geo_json
153+ FROM < project> .myDataset .myTable
154+ /**/
105155SELECT
106156 CAST(JSON_VALUE(json_blob .childField1 .gender) as STRING) as gender
107157 , CAST(JSON_VALUE(json_blob .childField1 .latitude) as DECIMAL ) as latitude
108- FROM < project> .< datastream > . < dataset >
109- -- ------
158+ FROM < project> .myDataset . myTable
159+ /**/
110160SELECT
111161 CAST(JSON_VALUE(json_blob .childField2 .favoriteFruit) as STRING) as favorite_fruit
112162 , CAST(JSON_VALUE(json_blob .childField2 .longitude) as DECIMAL ) as longitude
113- FROM < project> .< datastream > . < dataset >
114- -- ------
163+ FROM < project> .myDataset . myTable
164+ /**/
115165SELECT
116166 CAST(JSON_VALUE(json_blob .childWithNestedObject .isNormal) as STRING) as is_normal
117167 , TO_JSON_STRING(json_blob .childWithNestedObject .nestedObject) as nested_object
118- FROM < project> .< datastream > . < dataset >
168+ FROM < project> .myDataset . myTable
119169```
0 commit comments