diff --git a/Makefile b/Makefile index 6024f4b..13818ef 100644 --- a/Makefile +++ b/Makefile @@ -19,7 +19,7 @@ EXE=$(shell $(GO) env GOEXE) build: $(GO) fmt ./... - $(SET) "CGO_ENABLED=0" && $(GO) build $(GOOPT) "./cmd/$(NAME)" + $(SET) "CGO_ENABLED=0" && $(GO) build -tags debug $(GOOPT) "./cmd/$(NAME)" test: $(GO) test ./... diff --git a/edit.go b/edit.go index ebba82d..b60e136 100644 --- a/edit.go +++ b/edit.go @@ -47,13 +47,14 @@ func askN(msg string, getKey func() (string, error), options ...string) (int, er func newViewer(ss *session) *spread.Viewer { var hl int if ss.Debug { - hl = 3 + hl = 2 } else { hl = 1 } return &spread.Viewer{ Entry: ss.Dialect, HeaderLines: hl, + Debug: ss.Debug, Comma: ss.comma(), Null: ss.Null, Spool: ss.spool, @@ -80,10 +81,17 @@ func chooseTable(ctx context.Context, tables []string, d *dialect.Entry, ttyout } func doEdit(ctx context.Context, ss *session, command string, pilot commandIn) error { + var hl int + if ss.Debug { + hl = 2 + } else { + hl = 1 + } editor := &spread.Editor{ Viewer: &spread.Viewer{ Entry: ss.Dialect, - HeaderLines: 1, + HeaderLines: hl, + Debug: ss.Debug, Comma: ss.comma(), Null: ss.Null, }, diff --git a/go.mod b/go.mod index 2a4cac9..54d4687 100644 --- a/go.mod +++ b/go.mod @@ -16,6 +16,7 @@ require ( github.com/nyaosorg/go-box/v3 v3.1.1 github.com/nyaosorg/go-readline-ny v1.15.1 github.com/nyaosorg/go-ttyadapter v0.7.0 + github.com/nyaosorg/go-windows-dbg v0.1.0 github.com/sijms/go-ora/v2 v2.8.22 ) diff --git a/go.sum b/go.sum index b7d51c1..0f2c0b0 100644 --- a/go.sum +++ b/go.sum @@ -68,6 +68,8 @@ github.com/nyaosorg/go-readline-skk v0.6.2 h1:UUBt4qS0UwEaqKgaju8yQOogSF0Ozs4KXH github.com/nyaosorg/go-readline-skk v0.6.2/go.mod h1:afNC+dqTeuu+5KHNFjbv/up7bfehvHp6HULXljTzvyw= github.com/nyaosorg/go-ttyadapter v0.7.0 h1:iBOlx7WJ+A0Fn1x28qYJNedjiFt/kWivlrn1+PTSViU= github.com/nyaosorg/go-ttyadapter v0.7.0/go.mod h1:w6ySb/Y8rpr0uIju4vN/TMRHC/6ayabORHmEVs6d/qE= +github.com/nyaosorg/go-windows-dbg v0.1.0 h1:nJt8s4GVavdaHW8TFUyjsCDQkXS+CH3sqalu7y9Z5OY= +github.com/nyaosorg/go-windows-dbg v0.1.0/go.mod h1:2KBQW9Jv7m6jB8WDgvZOVsJXwtbk4MRIpOWt/n/EDwg= github.com/nyaosorg/go-windows-mbcs v0.4.4 h1:x5MqDvOsfRO8F2a9Uedlm3I6SB/H0whN4KZknTOLe3w= github.com/nyaosorg/go-windows-mbcs v0.4.4/go.mod h1:P610Wyc6LcgDbx2VZhwUQn02XRuwjqGK2l/3wox3auA= github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c h1:+mdjkGKdHQG3305AYmdv1U2eRNDiU2ErMBj1gwrq8eQ= diff --git a/internal/dbg/debug.go b/internal/dbg/debug.go new file mode 100644 index 0000000..d18a455 --- /dev/null +++ b/internal/dbg/debug.go @@ -0,0 +1,11 @@ +//go:build debug + +package dbg + +import ( + "github.com/nyaosorg/go-windows-dbg" +) + +func Println(v ...any) { + dbg.Println(v...) +} diff --git a/internal/dbg/ndebug.go b/internal/dbg/ndebug.go new file mode 100644 index 0000000..dca2048 --- /dev/null +++ b/internal/dbg/ndebug.go @@ -0,0 +1,5 @@ +//go:build !debug + +package dbg + +func Println(v ...any) {} diff --git a/run-mssql.cmd b/run-mssql.cmd deleted file mode 100644 index 64afcda..0000000 --- a/run-mssql.cmd +++ /dev/null @@ -1,7 +0,0 @@ -@rem Sample script to launch SQL-Bless with Microsoft SQL Server -@rem Do NOT include production credentials here. - -@setlocal -@set PROMPT=$G$S - -sqlbless sqlserver "Server=localhost\SQLEXPRESS;Database=master;Trusted_Connection=True;protocol=lpc;" diff --git a/run-mysql.cmd b/run-mysql.cmd deleted file mode 100644 index ec05338..0000000 --- a/run-mysql.cmd +++ /dev/null @@ -1,9 +0,0 @@ -@rem Sample script to launch SQL-Bless with MySQL -@rem Do NOT include production credentials here. - -@setlocal -@set PROMPT=$G$S - -@rem Example connection: root:@/mydb -sqlbless %* mysql "root:@/mydb" - diff --git a/run-oracle.cmd b/run-oracle.cmd deleted file mode 100644 index 708bc3e..0000000 --- a/run-oracle.cmd +++ /dev/null @@ -1,6 +0,0 @@ -@rem Sample script to launch SQL-Bless with Oracle DB - -@setlocal -@set PROMPT=$G$S -@rem $ sqlbless oracle://USERNAME:PASSWORD@HOST:PORT/SERVICE -sqlbless %* oracle://scott:tiger@localhost:1521/xepdb1 diff --git a/run-psql.cmd b/run-psql.cmd deleted file mode 100644 index 786a0c9..0000000 --- a/run-psql.cmd +++ /dev/null @@ -1,11 +0,0 @@ -@rem Sample script to launch SQL-Bless with a local PostgreSQL DB -@rem Do NOT include production credentials here. - -@setlocal -@set PROMPT=$G$S - -@rem Examples: -@rem sqlbless postgres host=127.0.0.1 port=5432 user=postgres dbname=postgres sslmode=disable -@rem sqlbless postgres://postgres@127.0.0.1:5432/postgres?sslmode=disable -@rem Same as psql "host=127.0.0.1 port=5432 user=postgres dbname=postgres sslmode=disable" -sqlbless %* postgres://postgres@127.0.0.1:5432/postgres?sslmode=disable diff --git a/run-sqlite3.cmd b/run-sqlite3.cmd deleted file mode 100644 index 97056a9..0000000 --- a/run-sqlite3.cmd +++ /dev/null @@ -1,5 +0,0 @@ -@rem Sample script to launch SQL-Bless with SQLite3 local DB -@ -@setlocal -@set PROMPT=$G$S -sqlbless %* sqlite3 mytestdb diff --git a/run.cmd b/run.cmd new file mode 100644 index 0000000..7083685 --- /dev/null +++ b/run.cmd @@ -0,0 +1,34 @@ +@setlocal +@set PROMPT=$G$S +@call :"%~1" %2 %3 %4 %5 %6 %7 %8 %9 +@endlocal +@exit /b + +:"sqlite" +:"sqlite3" +sqlbless %* sqlite3 mytestdb +@exit /b + +:"mssql" +:"sqlserver" +sqlbless %* sqlserver "Server=localhost\SQLEXPRESS;Database=master;Trusted_Connection=True;protocol=lpc;" +@exit /b + +:"mysql" +sqlbless %* mysql "root:@/mydb" +@exit /b + +:"oracle" +sqlbless %* oracle://scott:tiger@localhost:1521/xepdb1 +@exit /b + +:"psql" +@rem Driver: https://github.com/lib/pq +@rem Schema postgresql://${username}:${password}@localhost:${port}/${database}?options=--search_path%3D${schema}" +sqlbless %* postgres://postgres@127.0.0.1:5432/chinook?sslmode=disable +@exit /b + +:"-psql" +psql -h 127.0.0.1 -p 5432 -d postgres -U postgres +@exit /b + diff --git a/spread/edit.go b/spread/edit.go index 95aea0f..ffd856d 100644 --- a/spread/edit.go +++ b/spread/edit.go @@ -194,6 +194,7 @@ func (editor *Editor) Edit(ctx context.Context, tableAndWhere string, termOut io Null: editor.Viewer.Null, Comma: rune(editor.Viewer.Comma), AutoClose: true, + Debug: editor.Viewer.Debug, Conv: func(_ int, ct *sql.ColumnType, v any) (string, bool) { if f := editor.Entry.FormatValue; f != nil { return f(ct.DatabaseTypeName(), v) diff --git a/spread/view.go b/spread/view.go index a8561c2..5549b2b 100644 --- a/spread/view.go +++ b/spread/view.go @@ -21,6 +21,7 @@ type KeyBinding struct { type Viewer struct { *dialect.Entry HeaderLines int + Debug bool Comma byte Null string Spool io.Writer @@ -44,6 +45,7 @@ func (viewer *Viewer) View(ctx context.Context, title string, rows rowstocsv.Sou Null: viewer.Null, Comma: rune(viewer.Comma), AutoClose: true, + Debug: viewer.Debug, Conv: func(_ int, ct *sql.ColumnType, v any) (string, bool) { if f := viewer.Entry.FormatValue; f != nil { return f(ct.DatabaseTypeName(), v)