Skip to content

Commit 81e200c

Browse files
authored
feat: sql server (#222)
* build(compose): add the mssql service to the compose service * build(dbmigrate): add everything necessary to run migrations on mssql * feat(client): add mssql client * feat(connection): add a parser to generate or process a dsn connection string to connnect with sql server * feat(command): add new connection as flags to connect with sql server * feat(config): add a sql as an option to connect through a config file * build(make): add targets to connect with sql server container * fix: remove sql migrations * feat(form): add sql to the bubbletea app * docs(readme): add docs on how to connect with the sql server
1 parent 61b20d3 commit 81e200c

23 files changed

+562
-128
lines changed

Diff for: .dblab.yaml

+18
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,22 @@ database:
1616
user: "postgres"
1717
schema: "public"
1818
driver: "postgres"
19+
- name: "oracle"
20+
host: "localhost"
21+
port: 1521
22+
db: "FREEPDB1 "
23+
password: "password"
24+
user: "system"
25+
driver: "oracle"
26+
ssl: "enable"
27+
wallet: "path/to/wallet"
28+
ssl-verify: true
29+
trace: "trace.log"
30+
- name: "sqlserver"
31+
driver: "sqlserver"
32+
host: "localhost"
33+
port: 1433
34+
db: "msdb"
35+
password: "5@klkbN#ABC"
36+
user: "SA"
1937
limit: 50

Diff for: Makefile

+10-4
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,6 @@ run: build
4646
run-mysql: build
4747
./dblab --host localhost --user myuser --db mydb --pass 5@klkbN#ABC --ssl enable --port 3306 --driver mysql
4848

49-
.PHONY: run-oracle
50-
## run-oracle: Runs the application making a connection to the Oreacle database
51-
run-oracle: build
52-
./dblab --host localhost --user system --db FREEPDB1 --pass password --port 1521 --driver oracle --limit 50
5349

5450
.PHONY: run-mysql-socket
5551
## run-mysql-socket: Runs the application with a connection to mysql through a socket file. In this example the socke file is located in /var/lib/mysql/mysql.sock.
@@ -61,6 +57,16 @@ run-mysql-socket: build
6157
run-postgres-socket: build
6258
./dblab --socket /var/run/postgresql --user myuser --db my_project --pass postgres --ssl disable --port 5432 --driver postgres --limit 50
6359

60+
.PHONY: run-oracle
61+
## run-oracle: Runs the application making a connection to the Oracle database
62+
run-oracle: build
63+
./dblab --host localhost --user system --db FREEPDB1 --pass password --port 1521 --driver oracle --limit 50
64+
65+
.PHONY: run-sql-server
66+
## run-sql-server: Runs the application making a connection to the SQL Server database
67+
run-sql-server: build
68+
./dblab --host localhost --user SA --db msdb --pass '5@klkbN#ABC' --port 1433 --driver sqlserver --limit 50
69+
6470
.PHONY: run-mysql-socket-url
6571
## run-mysql-socket-url: Runs the application with a connection to mysql through a socket file. In this example the socke file is located in /var/lib/mysql/mysql.sock.
6672
run-mysql-socket-url: build

Diff for: README.md

+35-23
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ dblab ![integration tests](https://github.com/danvergara/dblab/actions/workflows
55
<img style="float: right;" src="assets/gopher-dblab.png" alt="dblab logo"/ width=200>
66
</p>
77

8-
__Interactive client for PostgreSQL, MySQL, SQLite3 and Oracle.__
8+
__Interactive client for PostgreSQL, MySQL, SQLite3, Oracle and SQL Server.__
99

1010
<img src="screenshots/dblab-cover.png" />
1111

@@ -37,7 +37,7 @@ dblab is a fast and lightweight interactive terminal based UI application for Po
3737
written in Go and works on OSX, Linux and Windows machines. Main idea behind using Go for backend development
3838
is to utilize ability of the compiler to produce zero-dependency binaries for
3939
multiple platforms. dblab was created as an attempt to build very simple and portable
40-
application to work with local or remote PostgreSQL/MySQL/SQLite3/Oracle databases.
40+
application to work with local or remote PostgreSQL/MySQL/SQLite3/Oracle/SQL Server databases.
4141

4242
## Features
4343

@@ -91,27 +91,30 @@ Available Commands:
9191
version The version of the project
9292
9393
Flags:
94-
--cfg-name string Database config name section
95-
--config Get the connection data from a config file (default locations are: current directory, $HOME/.dblab.yaml or $XDG_CONFIG_HOME/.dblab.yaml)
96-
--db string Database name
97-
--driver string Database driver
98-
-h, --help help for dblab
99-
--host string Server host name or IP
100-
--limit uint Size of the result set from the table content query (should be greater than zero, otherwise the app will error out) (default 100)
101-
--pass string Password for user
102-
--port string Server port
103-
--schema string Database schema (postgres only)
104-
--socket string Path to a Unix socket file
105-
--ssl string SSL mode
106-
--ssl-verify string [enable|disable] or [true|false] enable ssl verify for the server
107-
--sslcert string This parameter specifies the file name of the client SSL certificate, replacing the default ~/.postgresql/postgresql.crt
108-
--sslkey string This parameter specifies the location for the secret key used for the client certificate. It can either specify a file name that will be used instead of the default ~/.postgresql/postgresql.key, or it can specify a key obtained from an external “engine”
109-
--sslpassword string This parameter specifies the password for the secret key specified in sslkey
110-
--sslrootcert string This parameter specifies the name of a file containing SSL certificate authority (CA) certificate(s) The default is ~/.postgresql/root.crt
111-
--trace-file string File name for trace log
112-
-u, --url string Database connection string
113-
--user string Database user
114-
--wallet string Path for auto-login oracle wallet
94+
--cfg-name string Database config name section
95+
--config Get the connection data from a config file (default locations are: current directory, $HOME/.dblab.yaml or $XDG_CONFIG_HOME/.dblab.yaml)
96+
--db string Database name
97+
--driver string Database driver
98+
--encrypt string [strict|disable|false|true] data sent between client and server is encrypted or not
99+
-h, --help help for dblab
100+
--host string Server host name or IP
101+
--limit uint Size of the result set from the table content query (should be greater than zero, otherwise the app will error out) (default 100)
102+
--pass string Password for user
103+
--port string Server port
104+
--schema string Database schema (postgres only)
105+
--socket string Path to a Unix socket file
106+
--ssl string SSL mode
107+
--ssl-verify string [enable|disable] or [true|false] enable ssl verify for the server
108+
--sslcert string This parameter specifies the file name of the client SSL certificate, replacing the default ~/.postgresql/postgresql.crt
109+
--sslkey string This parameter specifies the location for the secret key used for the client certificate. It can either specify a file name that will be used instead of the default ~/.postgresql/postgresql.key, or it can specify a key obtained from an external “engine”
110+
--sslpassword string This parameter specifies the password for the secret key specified in sslkey
111+
--sslrootcert string This parameter specifies the name of a file containing SSL certificate authority (CA) certificate(s) The default is ~/.postgresql/root.crt
112+
--timeout string in seconds (default is 0 for no timeout), set to 0 for no timeout. Recommended to set to 0 and use context to manage query and connection timeouts
113+
--trace-file string File name for trace log
114+
--trust-server-certificate string [false|true] server certificate is checked or not
115+
-u, --url string Database connection string
116+
--user string Database user
117+
--wallet string Path for auto-login oracle wallet
115118
116119
Use "dblab [command] --help" for more information about a command.
117120
```
@@ -126,6 +129,7 @@ You can start the app passing no flags or parameters, you'll be asked for connec
126129
$ dblab --host localhost --user myuser --db users --pass password --ssl disable --port 5432 --driver postgres --limit 50
127130
$ dblab --db path/to/file.sqlite3 --driver sqlite
128131
$ dblab --host localhost --user system --db FREEPDB1 --pass password --port 1521 --driver oracle --limit 50
132+
$ dblab --host localhost --user SA --db msdb --pass '5@klkbN#ABC' --port 1433 --driver sqlserver --limit 50
129133
```
130134

131135
Connection URL scheme is also supported:
@@ -135,6 +139,7 @@ $ dblab --url 'postgres://user:password@host:port/database?sslmode=[mode]'
135139
$ dblab --url 'mysql://user:password@tcp(host:port)/db'
136140
$ dblab --url 'file:test.db?_pragma=foreign_keys(1)&_time_format=sqlite'
137141
$ dblab --url 'oracle://user:password@localhost:1521/db'
142+
$ dblab --url 'sqlserver://SA:myStrong(!)Password@localhost:1433?database=tempdb&encrypt=true&trustservercertificate=false&connection+timeout=30'
138143
```
139144

140145
if you're using PostgreSQL, you have the option to define the schema you want to work with, the default value is `public`.
@@ -223,6 +228,13 @@ database:
223228
ssl: "enable"
224229
wallet: "path/to/wallet"
225230
ssl-verify: true
231+
- name: "sqlserver"
232+
driver: "sqlserver"
233+
host: "localhost"
234+
port: 1433
235+
db: "msdb"
236+
password: "5@klkbN#ABC"
237+
user: "SA"
226238
# should be greater than 0, otherwise the app will error out
227239
limit: 50
228240
```

Diff for: cmd/dbmigrate/cmd/migratedown.go

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"github.com/golang-migrate/migrate/v4"
2222
_ "github.com/golang-migrate/migrate/v4/database/mysql"
2323
_ "github.com/golang-migrate/migrate/v4/database/postgres"
24+
_ "github.com/golang-migrate/migrate/v4/database/sqlserver"
2425
_ "github.com/golang-migrate/migrate/v4/source/file"
2526
"github.com/spf13/cobra"
2627
)

Diff for: cmd/root.go

+32-18
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ var (
3434
traceFile string
3535
sslVerify string
3636
wallet string
37+
// sql server.
38+
encrypt string
39+
trustServerCertificate string
40+
connectionTimeout string
3741
)
3842

3943
// NewRootCmd returns the root command.
@@ -53,24 +57,27 @@ func NewRootCmd() *cobra.Command {
5357
}
5458
} else {
5559
opts = command.Options{
56-
Driver: driver,
57-
URL: url,
58-
Host: host,
59-
Port: port,
60-
User: user,
61-
Pass: pass,
62-
DBName: db,
63-
Schema: schema,
64-
SSL: ssl,
65-
Limit: limit,
66-
Socket: socket,
67-
SSLCert: sslcert,
68-
SSLKey: sslkey,
69-
SSLPassword: sslpassword,
70-
SSLRootcert: sslrootcert,
71-
SSLVerify: sslVerify,
72-
TraceFile: traceFile,
73-
Wallet: wallet,
60+
Driver: driver,
61+
URL: url,
62+
Host: host,
63+
Port: port,
64+
User: user,
65+
Pass: pass,
66+
DBName: db,
67+
Schema: schema,
68+
SSL: ssl,
69+
Limit: limit,
70+
Socket: socket,
71+
SSLCert: sslcert,
72+
SSLKey: sslkey,
73+
SSLPassword: sslpassword,
74+
SSLRootcert: sslrootcert,
75+
SSLVerify: sslVerify,
76+
TraceFile: traceFile,
77+
Wallet: wallet,
78+
Encrypt: encrypt,
79+
TrustServerCertificate: trustServerCertificate,
80+
ConnectionTimeout: connectionTimeout,
7481
}
7582

7683
if form.IsEmpty(opts) {
@@ -166,4 +173,11 @@ func init() {
166173
StringVarP(&sslVerify, "ssl-verify", "", "", "[enable|disable] or [true|false] enable ssl verify for the server")
167174
rootCmd.Flags().StringVarP(&traceFile, "trace-file", "", "", "File name for trace log")
168175
rootCmd.Flags().StringVarP(&wallet, "wallet", "", "", "Path for auto-login oracle wallet")
176+
177+
rootCmd.Flags().
178+
StringVarP(&encrypt, "encrypt", "", "", "[strict|disable|false|true] data sent between client and server is encrypted or not")
179+
rootCmd.Flags().
180+
StringVarP(&trustServerCertificate, "trust-server-certificate", "", "", "[false|true] server certificate is checked or not")
181+
rootCmd.Flags().
182+
StringVarP(&connectionTimeout, "timeout", "", "", "in seconds (default is 0 for no timeout), set to 0 for no timeout. Recommended to set to 0 and use context to manage query and connection timeouts")
169183
}

Diff for: docker-compose.yml

+10
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,16 @@ services:
3333
networks:
3434
- dblab
3535

36+
mssql:
37+
image: mcr.microsoft.com/mssql/server:2022-latest
38+
environment:
39+
MSSQL_SA_PASSWORD: 5@klkbN#ABC
40+
ACCEPT_EULA: Y
41+
ports:
42+
- '1433:1433'
43+
networks:
44+
- dblab
45+
3646
dblab:
3747
build:
3848
context: .

Diff for: go.mod

+18-8
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,31 @@ require (
1717
github.com/jmoiron/sqlx v1.3.5
1818
github.com/kkyr/fig v0.3.0
1919
github.com/lib/pq v1.10.6
20+
github.com/microsoft/go-mssqldb v1.7.2
2021
github.com/muesli/termenv v0.12.0
2122
github.com/olekukonko/tablewriter v0.0.5
2223
github.com/sijms/go-ora/v2 v2.8.19
2324
github.com/spf13/cobra v1.4.0
24-
github.com/stretchr/testify v1.7.2
25-
golang.org/x/text v0.3.7
25+
github.com/stretchr/testify v1.8.4
26+
golang.org/x/text v0.14.0
2627
modernc.org/sqlite v1.22.1
2728
)
2829

2930
require (
31+
github.com/Azure/go-autorest v14.2.0+incompatible // indirect
32+
github.com/Azure/go-autorest/autorest/adal v0.9.16 // indirect
33+
github.com/Azure/go-autorest/autorest/date v0.3.0 // indirect
34+
github.com/Azure/go-autorest/logger v0.2.1 // indirect
35+
github.com/Azure/go-autorest/tracing v0.6.0 // indirect
3036
github.com/atotto/clipboard v0.1.4 // indirect
3137
github.com/containerd/console v1.0.3 // indirect
3238
github.com/davecgh/go-spew v1.1.1 // indirect
39+
github.com/denisenkom/go-mssqldb v0.10.0 // indirect
3340
github.com/dustin/go-humanize v1.0.1 // indirect
34-
github.com/google/uuid v1.3.0 // indirect
41+
github.com/golang-jwt/jwt/v4 v4.1.0 // indirect
42+
github.com/golang-sql/civil v0.0.0-20220223132316-b832511892a9 // indirect
43+
github.com/golang-sql/sqlexp v0.1.0 // indirect
44+
github.com/google/uuid v1.6.0 // indirect
3545
github.com/hashicorp/errwrap v1.1.0 // indirect
3646
github.com/hashicorp/go-multierror v1.1.1 // indirect
3747
github.com/inconshreveable/mousetrap v1.0.0 // indirect
@@ -54,11 +64,11 @@ require (
5464
github.com/rivo/uniseg v0.2.0 // indirect
5565
github.com/spf13/pflag v1.0.5 // indirect
5666
go.uber.org/atomic v1.9.0 // indirect
57-
golang.org/x/mod v0.5.0 // indirect
58-
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab // indirect
59-
golang.org/x/term v0.0.0-20220526004731-065cf7ba2467 // indirect
60-
golang.org/x/tools v0.1.5 // indirect
61-
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
67+
golang.org/x/crypto v0.18.0 // indirect
68+
golang.org/x/mod v0.8.0 // indirect
69+
golang.org/x/sys v0.16.0 // indirect
70+
golang.org/x/term v0.16.0 // indirect
71+
golang.org/x/tools v0.6.0 // indirect
6272
gopkg.in/yaml.v2 v2.4.0 // indirect
6373
gopkg.in/yaml.v3 v3.0.1 // indirect
6474
lukechampine.com/uint128 v1.2.0 // indirect

0 commit comments

Comments
 (0)