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.
14
+
**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
15
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.
16
+
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
17
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.
18
+
> [!WARNING]
19
+
> The support for JSON is limited. There is a possibility of discontinuing JSON support in the future.
20
20
21
21
## How to install
22
22
### 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
-
```
23
+
```shell
25
24
$ go install github.com/nao1215/sqly@latest
26
25
```
27
26
※ Main dependency is [github.com/mattn/go-sqlite3](https://github.com/mattn/go-sqlite3) and gcc.
28
27
28
+
## Supported OS
29
+
- Windows
30
+
- macOS
31
+
- Linux
29
32
30
33
## 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)
34
+
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
35
33
-
### Syntax
34
-
```
36
+
The sqly automatically determines the file format from the file extension.
37
+
38
+
### Syntax and Options
39
+
```shell
40
+
[Usage]
35
41
sqly [OPTIONS] [FILE_PATH]
42
+
43
+
[OPTIONS]
44
+
-c, --csv change output format to csv (default: table)
45
+
-e, --excel change output format to excel (default: table)
46
+
-j, --json change output format to json (default: table)
47
+
-l, --ltsv change output format to ltsv (default: table)
48
+
-m, --markdown change output format to markdown table (default: table)
49
+
-t, --tsv change output format to tsv (default: table)
50
+
-S, --sheet string excel sheet name you want to import
※ The sqly option must be specified before the file to be imported.
38
58
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
-
```
59
+
### Execute sql in terminal: --sql option
60
+
--sql option takes an SQL statement as an optional argument.
61
+
62
+
```shell
42
63
$ sqly --sql "SELECT user_name, position FROM user INNER JOIN identifier ON user.identifier = identifier.id" testdata/user.csv testdata/identifier.csv
43
64
+-----------+-----------+
44
65
| user_name | position |
@@ -50,8 +71,14 @@ $ sqly --sql "SELECT user_name, position FROM user INNER JOIN identifier ON user
50
71
```
51
72
52
73
### 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
-
```
74
+
The sqly output sql query results in following formats:
75
+
- ASCII table format (default)
76
+
- CSV format (--csv option)
77
+
- TSV format (--tsv option)
78
+
- LTSV format (--ltsv option)
79
+
- JSON format (--json option)
80
+
81
+
```shell
55
82
$ sqly --sql "SELECT * FROM user LIMIT 2" --csv testdata/user.csv
56
83
user_name,identifier,first_name,last_name
57
84
booker12,1,Rachel,Booker
@@ -81,58 +108,29 @@ Rachel,1,Booker,booker12
81
108
Mary,2,Jenkins,jenkins46
82
109
```
83
110
84
-
### run sqly shell
85
-
If the --sql option is not specified, the sqly shell is started. When you execute sqly command, it is optional whether or not to specify file(s). The sqly shell 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.
86
-
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
-
```
111
+
### Run sqly shell
112
+

105
113
106
-

114
+
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.
115
+
116
+
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
117
108
118
### Output sql result to file
109
119
#### 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
-
```
120
+
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
126
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
127
+
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.
128
+
129
+
```shell
130
+
$ sqly --sql "SELECT * FROM user" --output=test.csv testdata/user.csv
133
131
```
134
132
135
-
### Key Binding
133
+
### Key Binding for sqly-shell
136
134
|Key Binding |Description|
137
135
|:--|:--|
138
136
|Ctrl + A |Go to the beginning of the line (Home)|
- [ ] Convert CSV character encoding to UTF-8 if necessary
157
-
-[ ] Support MySQL driver
158
-
-[ ] Support PostgreSQL driver
159
-
160
-
## Unit Test Coverage Treemap
161
-

162
154
163
155
## Limitions (Not support)
164
156
- DDL such as CREATE
@@ -170,11 +162,46 @@ First off, thanks for taking the time to contribute! ❤️ Contributions are no
170
162
171
163
[](https://star-history.com/#nao1215/sqly&Date)
172
164
173
-
174
-
## Contact
165
+
### Contact
175
166
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