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/
4242
4343# IDE
4444.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
3535
3636## 使い方
3737
38- 以下のフラグが使用できます 。
38+ このツールは入力JSONファイルと以下のフラグを必要とします 。
3939
40- - ` -o <パス> ` : 出力先のSQLiteデータベースファイルを指定します。(デフォルト: ` output.db ` )
41- - ` -t <テーブル名> ` : 作成または更新するテーブル名を指定します。(デフォルト: ` data ` )
40+ - ` -o <パス> ` : ** 必須。 ** 出力先のSQLiteデータベースファイルを指定します。
41+ - ` -t <テーブル名> ` : ** 必須。 ** 作成または更新するテーブル名を指定します。
4242- ` --version ` : ツールのバージョン情報を表示します。
4343
4444### 使用例
4545
4646** 1. JSONファイルを新しいデータベースに変換する:**
4747``` bash
48- json-to-sqlite -o users.db -t users ./ users.json
48+ json-to-sqlite -o users.db -t users users.json
4949```
5050
5151** 2. 他のコマンド(例: ` curl ` )からJSONデータをパイプで渡す:**
5252``` 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 -
5454```
55+ * 注: 標準入力からパイプで渡す場合、` input_json_file ` 引数として` - ` を使用してください。*
5556
5657** 3. 新しいカラムを持つ可能性のあるデータを既存のデータベースに追加する:**
5758``` bash
5859# 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
6061```
6162
6263## 動作の詳細
Original file line number Diff line number Diff line change @@ -35,28 +35,29 @@ make build
3535
3636## Usage
3737
38- The tool accepts the following flags:
38+ The tool requires an input JSON file and the following flags:
3939
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.
4242- ` --version ` : Prints the current version of the tool.
4343
4444### Examples
4545
4646** 1. Convert a JSON file into a new database:**
4747``` bash
48- json-to-sqlite -o users.db -t users ./ users.json
48+ json-to-sqlite -o users.db -t users users.json
4949```
5050
5151** 2. Pipe JSON data from another command (e.g., ` curl ` ):**
5252``` 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 -
5454```
55+ * Note: When piping from stdin, use ` - ` as the input_json_file argument.*
5556
5657** 3. Add new data with potentially new columns to an existing database:**
5758``` bash
5859# 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
6061```
6162
6263## How It Works
Original file line number Diff line number Diff line change @@ -24,8 +24,8 @@ func main() {
2424 Version = "dev"
2525 }
2626
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) " )
2929 versionFlag := flag .Bool ("version" , false , "Print version information" )
3030
3131 flag .Parse ()
@@ -35,7 +35,25 @@ func main() {
3535 return
3636 }
3737
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+
3850 // --- 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+
3957 reader , err := getInputReader (flag .Args ())
4058 if err != nil {
4159 log .Fatal (err )
You can’t perform that action at this time.
0 commit comments