File tree Expand file tree Collapse file tree 4 files changed +38
-14
lines changed Expand file tree Collapse file tree 4 files changed +38
-14
lines changed Original file line number Diff line number Diff line change @@ -42,3 +42,7 @@ testdata/
42
42
43
43
# IDE
44
44
.vscode /
45
+
46
+ # Local test artifacts
47
+ * .db
48
+ * .json
Original file line number Diff line number Diff line change @@ -35,28 +35,29 @@ make build
35
35
36
36
## 使い方
37
37
38
- 以下のフラグが使用できます 。
38
+ このツールは入力JSONファイルと以下のフラグを必要とします 。
39
39
40
- - ` -o <パス> ` : 出力先のSQLiteデータベースファイルを指定します。(デフォルト: ` output.db ` )
41
- - ` -t <テーブル名> ` : 作成または更新するテーブル名を指定します。(デフォルト: ` data ` )
40
+ - ` -o <パス> ` : ** 必須。 ** 出力先のSQLiteデータベースファイルを指定します。
41
+ - ` -t <テーブル名> ` : ** 必須。 ** 作成または更新するテーブル名を指定します。
42
42
- ` --version ` : ツールのバージョン情報を表示します。
43
43
44
44
### 使用例
45
45
46
46
** 1. JSONファイルを新しいデータベースに変換する:**
47
47
``` bash
48
- json-to-sqlite -o users.db -t users ./ users.json
48
+ json-to-sqlite -o users.db -t users users.json
49
49
```
50
50
51
51
** 2. 他のコマンド(例: ` curl ` )からJSONデータをパイプで渡す:**
52
52
``` bash
53
- curl " https://api.example.com/data" | json-to-sqlite -o api_data.db -t records
53
+ curl " https://api.example.com/data" | json-to-sqlite -o api_data.db -t records -
54
54
```
55
+ * 注: 標準入力からパイプで渡す場合、` input_json_file ` 引数として` - ` を使用してください。*
55
56
56
57
** 3. 新しいカラムを持つ可能性のあるデータを既存のデータベースに追加する:**
57
58
``` bash
58
59
# new_users.jsonに新しいフィールドがあれば、この2回目のコマンドで'users'テーブルに新しいカラムが追加されます
59
- json-to-sqlite -o users.db -t users ./ new_users.json
60
+ json-to-sqlite -o users.db -t users new_users.json
60
61
```
61
62
62
63
## 動作の詳細
Original file line number Diff line number Diff line change @@ -35,28 +35,29 @@ make build
35
35
36
36
## Usage
37
37
38
- The tool accepts the following flags:
38
+ The tool requires an input JSON file and the following flags:
39
39
40
- - ` -o <path> ` : Specifies the path for the output SQLite database file. (Default: ` output.db ` )
41
- - ` -t <name> ` : Specifies the name of the table to create or update. (Default: ` data ` )
40
+ - ` -o <path> ` : ** Required. ** Specifies the path for the output SQLite database file.
41
+ - ` -t <name> ` : ** Required. ** Specifies the name of the table to create or update.
42
42
- ` --version ` : Prints the current version of the tool.
43
43
44
44
### Examples
45
45
46
46
** 1. Convert a JSON file into a new database:**
47
47
``` bash
48
- json-to-sqlite -o users.db -t users ./ users.json
48
+ json-to-sqlite -o users.db -t users users.json
49
49
```
50
50
51
51
** 2. Pipe JSON data from another command (e.g., ` curl ` ):**
52
52
``` bash
53
- curl " https://api.example.com/data" | json-to-sqlite -o api_data.db -t records
53
+ curl " https://api.example.com/data" | json-to-sqlite -o api_data.db -t records -
54
54
```
55
+ * Note: When piping from stdin, use ` - ` as the input_json_file argument.*
55
56
56
57
** 3. Add new data with potentially new columns to an existing database:**
57
58
``` bash
58
59
# This second command might add new columns to the 'users' table if new_users.json has different fields
59
- json-to-sqlite -o users.db -t users ./ new_users.json
60
+ json-to-sqlite -o users.db -t users new_users.json
60
61
```
61
62
62
63
## How It Works
Original file line number Diff line number Diff line change @@ -24,8 +24,8 @@ func main() {
24
24
Version = "dev"
25
25
}
26
26
27
- outputDB := flag .String ("o" , "output.db " , "Output SQLite database file" )
28
- tableName := flag .String ("t" , "data " , "Table name to insert data into" )
27
+ outputDB := flag .String ("o" , "" , "Output SQLite database file (required) " )
28
+ tableName := flag .String ("t" , "" , "Table name to insert data into (required) " )
29
29
versionFlag := flag .Bool ("version" , false , "Print version information" )
30
30
31
31
flag .Parse ()
@@ -35,7 +35,25 @@ func main() {
35
35
return
36
36
}
37
37
38
+ if * outputDB == "" {
39
+ fmt .Println ("Error: Output database file (-o) is required." )
40
+ flag .PrintDefaults ()
41
+ os .Exit (1 )
42
+ }
43
+
44
+ if * tableName == "" {
45
+ fmt .Println ("Error: Table name (-t) is required." )
46
+ flag .PrintDefaults ()
47
+ os .Exit (1 )
48
+ }
49
+
38
50
// --- Input Handling ---
51
+ if len (flag .Args ()) == 0 {
52
+ fmt .Println ("Usage: json-to-sqlite [options] <input_json_file>" )
53
+ flag .PrintDefaults ()
54
+ os .Exit (1 )
55
+ }
56
+
39
57
reader , err := getInputReader (flag .Args ())
40
58
if err != nil {
41
59
log .Fatal (err )
You can’t perform that action at this time.
0 commit comments