@@ -10,7 +10,17 @@ This CLI tool reads a JSON file and produces BigQuery compatible SQL views from
10
10
## Usage
11
11
12
12
``` 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
14
24
```
15
25
16
26
## Examples:
@@ -19,9 +29,16 @@ Default output to STDOUT:
19
29
npx @nealwp/blobview ./path/to/file.json
20
30
```
21
31
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
+
22
39
Redirect output to file:
23
40
``` 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
25
42
```
26
43
27
44
## Features
@@ -32,6 +49,7 @@ npx @nealwp/blobview ./path/to/file.json > my-view-file.sql
32
49
* Auto-formats column names to snake_case from camelCase and PascalCase
33
50
* Detects deeply-nested objects and formats to JSON string
34
51
* Pre-populates FROM clause with BigQuery-style placeholders
52
+ * BigQuery dataset and table name can be supplied as input options
35
53
36
54
## Limitations
37
55
* 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
40
58
* Does not create SQL views in any syntax other than BigQuery
41
59
* Requires a local JSON file to read
42
60
* 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
44
62
45
63
## Example Output
46
64
@@ -100,20 +118,52 @@ SELECT
100
118
, CAST(JSON_VALUE(json_blob .integerField ) as INTEGER ) as integer_field
101
119
, CAST(JSON_VALUE(json_blob .decimalField ) as DECIMAL ) as decimal_field
102
120
, 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
+ /**/
105
155
SELECT
106
156
CAST(JSON_VALUE(json_blob .childField1 .gender) as STRING) as gender
107
157
, CAST(JSON_VALUE(json_blob .childField1 .latitude) as DECIMAL ) as latitude
108
- FROM < project> .< datastream > . < dataset >
109
- -- ------
158
+ FROM < project> .myDataset . myTable
159
+ /**/
110
160
SELECT
111
161
CAST(JSON_VALUE(json_blob .childField2 .favoriteFruit) as STRING) as favorite_fruit
112
162
, CAST(JSON_VALUE(json_blob .childField2 .longitude) as DECIMAL ) as longitude
113
- FROM < project> .< datastream > . < dataset >
114
- -- ------
163
+ FROM < project> .myDataset . myTable
164
+ /**/
115
165
SELECT
116
166
CAST(JSON_VALUE(json_blob .childWithNestedObject .isNormal) as STRING) as is_normal
117
167
, TO_JSON_STRING(json_blob .childWithNestedObject .nestedObject) as nested_object
118
- FROM < project> .< datastream > . < dataset >
168
+ FROM < project> .myDataset . myTable
119
169
```
0 commit comments