You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
**sqly**command imports CSV/TSV/LTSV/JSON and Microsoft Excel™ (XLAM / XLSM / XLSX / XLTM / XLTX) file(s) into an in-memory DB and executes SQL against them. sqly uses [SQLite3](https://www.sqlite.org/index.html)as its DB. So, sql syntax is same as SQLite3.
15
+
**sqly**is a powerful command-line tool that can execute SQL against CSV, TSV, LTSV, JSON, and even Microsoft Excel™ files. The sqly import those files into [SQLite3](https://www.sqlite.org/index.html)in-memory database.
12
16
13
-
The sqly command has sqly-shell. You can interactively execute SQL with sql completion and command history. Of course, you can also execute SQL without running the sqly-shell.
17
+
The sqly has **sqly-shell**. You can interactively execute SQL with sql completion and command history. Of course, you can also execute SQL without running the sqly-shell.
14
18
15
-
## Features
16
-
✅ execute SQL against CSV / TSV / LTSV / JSON and Microsoft Excel™ (XLAM / XLSM / XLSX / XLTM / XLTX).
17
-
✅ output SQL result to CSV / TSV / LTSV / JSON and Microsoft Excel™ (XLAM / XLSM / XLSX / XLTM / XLTX).
18
-
✅ print SQL result in ASCII Table / CSV / TSV / LTSV / JSON file format.
19
-
✅ interactive sqly shell with input completion, emacs-keybindings, input history.
19
+
> [!WARNING]
20
+
> The support for JSON is limited. There is a possibility of discontinuing JSON support in the future.
20
21
21
22
## How to install
22
23
### Use "go install"
23
-
If you does not have the golang development environment installed on your system, please install golang from the [golang official website](https://go.dev/doc/install).
24
-
```
24
+
```shell
25
25
$ go install github.com/nao1215/sqly@latest
26
26
```
27
27
※ Main dependency is [github.com/mattn/go-sqlite3](https://github.com/mattn/go-sqlite3) and gcc.
28
28
29
+
## Supported OS
30
+
- Windows
31
+
- macOS
32
+
- Linux
29
33
30
34
## How to use
31
-
sqly command automatically imports the CSV/TSV/LTSV/JSON file into the DB when you pass a CSV/TSV/LTSV/JSON file as an argument. DB table name is the same as the file name (e.g., if you import user.csv, sqly command create the user table)
35
+
The sqly automatically imports the CSV/TSV/LTSV/JSON/Excel file into the DB when you pass file path as an argument. DB table name is the same as the file name or sheet name (e.g., if you import user.csv, sqly command create the user table).
32
36
33
-
### Syntax
34
-
```
37
+
The sqly automatically determines the file format from the file extension.
38
+
39
+
### Syntax and Options
40
+
```shell
41
+
[Usage]
35
42
sqly [OPTIONS] [FILE_PATH]
43
+
44
+
[OPTIONS]
45
+
-c, --csv change output format to csv (default: table)
46
+
-e, --excel change output format to excel (default: table)
47
+
-j, --json change output format to json (default: table)
48
+
-l, --ltsv change output format to ltsv (default: table)
49
+
-m, --markdown change output format to markdown table (default: table)
50
+
-t, --tsv change output format to tsv (default: table)
51
+
-S, --sheet string excel sheet name you want to import
※ The sqly option must be specified before the file to be imported.
38
59
39
-
### --sql option: execute sql in terminal
40
-
--sql option takes an SQL statement as an optional argument. You pass file path(s) as arguments to the sqly command. sqly command import them. sqly command automatically determines the file format from the file extension.
41
-
```
60
+
### Execute sql in terminal: --sql option
61
+
--sql option takes an SQL statement as an optional argument.
62
+
63
+
```shell
42
64
$ sqly --sql "SELECT user_name, position FROM user INNER JOIN identifier ON user.identifier = identifier.id" testdata/user.csv testdata/identifier.csv
43
65
+-----------+-----------+
44
66
| user_name | position |
@@ -50,8 +72,14 @@ $ sqly --sql "SELECT user_name, position FROM user INNER JOIN identifier ON user
50
72
```
51
73
52
74
### Change output format
53
-
sqly command output sql results in ASCII table format, CSV format (--csv option), TSV format (--tsv option), LTSV format (--ltsv option) and JSON format (--json option). This means that conversion between csv and json is supported.
54
-
```
75
+
The sqly output sql query results in following formats:
76
+
- ASCII table format (default)
77
+
- CSV format (--csv option)
78
+
- TSV format (--tsv option)
79
+
- LTSV format (--ltsv option)
80
+
- JSON format (--json option)
81
+
82
+
```shell
55
83
$ sqly --sql "SELECT * FROM user LIMIT 2" --csv testdata/user.csv
56
84
user_name,identifier,first_name,last_name
57
85
booker12,1,Rachel,Booker
@@ -81,58 +109,29 @@ Rachel,1,Booker,booker12
81
109
Mary,2,Jenkins,jenkins46
82
110
```
83
111
84
-
### run sqly shell
85
-
If the --sql option is not specified, the sqlyshell is started. When you execute sqly command, it is optional whether or not to specify file(s). The sqlyshell functions similarly to a common SQL client (e.g., sqlite3 command or mysql command). sqly shell has helper commands, SQL execution history management and input complement.
112
+
### Run sqly shell
113
+

86
114
87
-
#### sqly helper command
88
-
The command beginning with a dot is the sqly helper command; I plan to add more features in the future to make the sqly shell run more comfortably.
89
-
```
90
-
$ sqly
91
-
sqly v0.5.0 (work in progress)
92
-
93
-
enter "SQL query" or "sqly command that begins with a dot".
94
-
.help print usage, .exit exit sqly.
95
-
96
-
sqly> .help
97
-
.dump: dump db table to file in a format according to output mode (default: csv)
98
-
.exit: exit sqly
99
-
.header: print table header
100
-
.help: print help message
101
-
.import: import csv file(s)
102
-
.mode: change output mode
103
-
.tables: print tables
104
-
```
105
-
106
-

115
+
The sqly-shell starts when you run the sqly command without the --sql option. When you execute sqly command with file path, the sqly-shell starts after importing the file into the SQLite3 in-memory database.
116
+
117
+
The sqly shell functions similarly to a common SQL client (e.g., `sqlite3`command or `mysql` command). The sqly-shell has helper commands that begin with a dot. The sqly-shell also supports command history, and input completion.
107
118
108
119
### Output sql result to file
109
120
#### For linux user
110
-
sqly command can save SQL execution results to a file using shell redirection. The --csv option outputs SQL execution results in CSV format instead of table format.
111
-
```
121
+
The sqly can save SQL execution results to the file using shell redirection. The --csv option outputs SQL execution results in CSV format instead of table format.
$ sqly --sql "SELECT * FROM user" --output=test.csv testdata/user.csv
117
-
```
118
127
119
-
### All options
120
-
```
121
-
[OPTIONS]
122
-
-c, --csv change output format to csv (default: table)
123
-
-e, --excel change output format to excel (default: table)
124
-
-j, --json change output format to json (default: table)
125
-
-l, --ltsv change output format to ltsv (default: table)
126
-
-m, --markdown change output format to markdown table (default: table)
127
-
-t, --tsv change output format to tsv (default: table)
128
-
-S, --sheet string excel sheet name you want to import
129
-
-s, --sql string sql query you want to execute
130
-
-o, --output string destination path for SQL results specified in --sql option
131
-
-h, --help print help message
132
-
-v, --version print sqly version
128
+
The sqly can save SQL execution results to the file using the --output option. The --output option specifies the destination path forSQL results specifiedin the --sql option.
129
+
130
+
```shell
131
+
$ sqly --sql "SELECT * FROM user" --output=test.csv testdata/user.csv
133
132
```
134
133
135
-
### Key Binding
134
+
### Key Binding for sqly-shell
136
135
|Key Binding |Description|
137
136
|:--|:--|
138
137
|Ctrl + A |Go to the beginning of the line (Home)|
|[harelba/q](https://github.com/harelba/q)|Run SQL directly on delimited files and multi-file sqlite databases|
167
+
|[dinedal/textql](https://github.com/dinedal/textql)|Execute SQL against structured text like CSV or TSV|
168
+
|[noborus/trdsql](https://github.com/noborus/trdsql)|CLI tool that can execute SQL queries on CSV, LTSV, JSON, YAML and TBLN. Can output to various formats.|
169
+
|[mithrandie/csvq](https://github.com/mithrandie/csvq)|SQL-like query language for csv|
159
170
160
-
## Unit Test Coverage Treemap
161
-

162
171
163
172
## Limitions (Not support)
164
173
- DDL such as CREATE
@@ -170,11 +179,46 @@ First off, thanks for taking the time to contribute! ❤️ Contributions are no
170
179
171
180
[](https://star-history.com/#nao1215/sqly&Date)
172
181
173
-
174
-
## Contact
182
+
### Contact
175
183
If you would like to send comments such as "find a bug" or "request for additional features" to the developer, please use one of the following contacts.
0 commit comments