Skip to content

Commit

Permalink
Add schemaDb to ShellConfig
Browse files Browse the repository at this point in the history
Signed-off-by: Piotr Jastrzebski <piotr@chiselstrike.com>
  • Loading branch information
haaawk committed Jul 16, 2024
1 parent 8b5a15f commit 7e54436
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 18 deletions.
14 changes: 7 additions & 7 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
module github.com/libsql/libsql-shell-go

go 1.21
go 1.22

toolchain go1.21.0
toolchain go1.22.1

require (
github.com/antlr4-go/antlr/v4 v4.13.0
github.com/antlr4-go/antlr/v4 v4.13.1
github.com/fatih/color v1.14.1
github.com/frankban/quicktest v1.14.4
github.com/go-playground/validator/v10 v10.11.2
Expand All @@ -17,7 +17,7 @@ require (
github.com/mattn/go-sqlite3 v1.14.16
github.com/spf13/cobra v1.6.1
github.com/stretchr/testify v1.9.0
github.com/tursodatabase/libsql-client-go v0.0.0-20240715111033-518abad12431
github.com/tursodatabase/libsql-client-go v0.0.0-20240716175905-469d2977ed53
)

require (
Expand All @@ -26,7 +26,7 @@ require (
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/google/go-cmp v0.5.9 // indirect
github.com/google/go-cmp v0.6.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/knadh/koanf/maps v0.1.1 // indirect
github.com/kr/pretty v0.3.1 // indirect
Expand All @@ -44,9 +44,9 @@ require (
github.com/rogpeppe/go-internal v1.9.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
golang.org/x/crypto v0.5.0 // indirect
golang.org/x/exp v0.0.0-20240325151524-a685a6edb6d8 // indirect
golang.org/x/exp v0.0.0-20240716160929-1d5bc16f04a8 // indirect
golang.org/x/sys v0.12.0 // indirect
golang.org/x/text v0.7.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
nhooyr.io/websocket v1.8.10 // indirect
nhooyr.io/websocket v1.8.11 // indirect
)
17 changes: 10 additions & 7 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
github.com/antlr4-go/antlr/v4 v4.13.0 h1:lxCg3LAv+EUK6t1i0y1V6/SLeUi0eKEKdhQAlS8TVTI=
github.com/antlr4-go/antlr/v4 v4.13.0/go.mod h1:pfChB/xh/Unjila75QW7+VU4TSnWnnk9UTnmpPaOR2g=
github.com/antlr4-go/antlr/v4 v4.13.1 h1:SqQKkuVZ+zWkMMNkjy5FZe5mr5WURWnlpmOuzYWrPrQ=
github.com/antlr4-go/antlr/v4 v4.13.1/go.mod h1:GKmUxMtwp6ZgGwZSva4eWPC5mS6vUAmOABFgjdkM7Nw=
github.com/chzyer/logex v1.2.1 h1:XHDu3E6q+gdHgsdTPH6ImJMIp436vR6MPtH8gP05QzM=
github.com/chzyer/logex v1.2.1/go.mod h1:JLbx6lG2kDbNRFnfkgvh4eRJRPX1QCoOIWomwysCBrQ=
github.com/chzyer/readline v1.5.1 h1:upd/6fQk4src78LMRzh5vItIt361/o4uq553V8B5sGI=
Expand All @@ -25,8 +25,9 @@ github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJn
github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY=
github.com/go-playground/validator/v10 v10.11.2 h1:q3SHpufmypg+erIExEKUmsgmhDTyhcJ38oeKGACXohU=
github.com/go-playground/validator/v10 v10.11.2/go.mod h1:NieE624vt4SCTJtD87arVLvdmjPAeV8BQlHtMnw9D7s=
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/inconshreveable/mousetrap v1.0.1/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
Expand Down Expand Up @@ -90,10 +91,12 @@ github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsT
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/tursodatabase/libsql-client-go v0.0.0-20240715111033-518abad12431 h1:92bBPzYCsSLCvpWHgmKBUHCtqwMX62rxhGxs/QCvQgs=
github.com/tursodatabase/libsql-client-go v0.0.0-20240715111033-518abad12431/go.mod h1:3Y9LlWC05q63NdmViO+2qV22LUjpfYLZWEYfE7ndpmU=
github.com/tursodatabase/libsql-client-go v0.0.0-20240716175905-469d2977ed53 h1:wLyk9KCragFMWOwkXsWvJ6RbBDkSrV4Q5oiI49haozc=
github.com/tursodatabase/libsql-client-go v0.0.0-20240716175905-469d2977ed53/go.mod h1:3Y9LlWC05q63NdmViO+2qV22LUjpfYLZWEYfE7ndpmU=
golang.org/x/crypto v0.5.0 h1:U/0M97KRkSFvyD/3FSmdP5W5swImpNgle/EHFhOsQPE=
golang.org/x/crypto v0.5.0/go.mod h1:NK/OQwhpMQP3MwtdjgLlYHnH9ebylxKWv3e0fK+mkQU=
golang.org/x/exp v0.0.0-20240325151524-a685a6edb6d8 h1:aAcj0Da7eBAtrTp03QXWvm88pSyOt+UgdZw2BFZ+lEw=
golang.org/x/exp v0.0.0-20240325151524-a685a6edb6d8/go.mod h1:CQ1k9gNrJ50XIzaKCRR2hssIjF07kZFEiieALBM/ARQ=
golang.org/x/exp v0.0.0-20240716160929-1d5bc16f04a8 h1:Z+vTUQyBb738QmIhbJx3z4htsxDeI+rd0EHvNm8jHkg=
golang.org/x/exp v0.0.0-20240716160929-1d5bc16f04a8/go.mod h1:M4RDyNAINzryxdtnbRXRL/OHtkFuWGRjvuhBJpk2IlY=
golang.org/x/sys v0.0.0-20220310020820-b874c991c1a5/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
Expand All @@ -108,5 +111,5 @@ gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EV
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
nhooyr.io/websocket v1.8.10 h1:mv4p+MnGrLDcPlBoWsvPP7XCzTYMXP9F9eIGoKbgx7Q=
nhooyr.io/websocket v1.8.10/go.mod h1:rN9OFWIUwuxg4fR5tELlYC04bXYowCP9GX47ivo2l+c=
nhooyr.io/websocket v1.8.11 h1:f/qXNc2/3DpoSZkHt1DQu6rj4zGC8JmkkLkWss0MgN0=
nhooyr.io/websocket v1.8.11/go.mod h1:rN9OFWIUwuxg4fR5tELlYC04bXYowCP9GX47ivo2l+c=
5 changes: 4 additions & 1 deletion internal/db/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func newRowResultWithError(err error) *rowResult {
return &rowResult{Err: treatedErr}
}

func NewDb(dbUri, authToken, proxy string) (*Db, error) {
func NewDb(dbUri, authToken, proxy string, schemaDb bool) (*Db, error) {
var err error

var db = Db{Uri: dbUri, AuthToken: authToken}
Expand All @@ -87,6 +87,9 @@ func NewDb(dbUri, authToken, proxy string) (*Db, error) {
if proxy != "" {
options = append(options, libsql.WithProxy(proxy))
}
if schemaDb {
options = append(options, libsql.WithSchemaDb(schemaDb))
}
connector, err := libsql.NewConnector(dbUri, options...)
if err != nil {
return nil, err
Expand Down
5 changes: 3 additions & 2 deletions pkg/shell/shell.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,13 @@ type ShellConfig struct {
WelcomeMessage *string
AfterDbConnectionCallback func()
DisableAutoCompletion bool
SchemaDb bool
}

func RunShell(config ShellConfig) error {
signals := make(chan os.Signal, 1)
signal.Notify(signals, os.Interrupt, syscall.SIGTERM)
db, err := db.NewDb(config.DbUri, config.AuthToken, config.Proxy)
db, err := db.NewDb(config.DbUri, config.AuthToken, config.Proxy, config.SchemaDb)
if err != nil {
return err
}
Expand Down Expand Up @@ -59,7 +60,7 @@ func RunShell(config ShellConfig) error {
func RunShellLine(config ShellConfig, line string) error {
signals := make(chan os.Signal, 1)
signal.Notify(signals, os.Interrupt, syscall.SIGTERM)
db, err := db.NewDb(config.DbUri, config.AuthToken, config.Proxy)
db, err := db.NewDb(config.DbUri, config.AuthToken, config.Proxy, config.SchemaDb)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion test/utils/db_test_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ type DbTestContext struct {
}

func NewTestContext(t *testing.T, dbUri string, authToken string) *DbTestContext {
db, err := db.NewDb(dbUri, authToken, "")
db, err := db.NewDb(dbUri, authToken, "", false)
if err != nil {
t.Fatalf("Fail to create new db. err: %v", err)
}
Expand Down

0 comments on commit 7e54436

Please sign in to comment.