Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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-20240902231107-85af5b9d094d
github.com/tursodatabase/libsql-client-go v0.0.0-20251205113610-b69dd6e475fc
)

require (
Expand Down
3 changes: 2 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,9 @@ github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO
github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/tursodatabase/libsql-client-go v0.0.0-20240902231107-85af5b9d094d h1:dOMI4+zEbDI37KGb0TI44GUAwxHF9cMsIoDTJ7UmgfU=
github.com/tursodatabase/libsql-client-go v0.0.0-20240902231107-85af5b9d094d/go.mod h1:l8xTsYB90uaVdMHXMCxKKLSgw5wLYBwBKKefNIUnm9s=
github.com/tursodatabase/libsql-client-go v0.0.0-20251205113610-b69dd6e475fc h1:uhpFwk9G+wp9JpPnaABzwyIUz1P4EYIkEKKivyJVO14=
github.com/tursodatabase/libsql-client-go v0.0.0-20251205113610-b69dd6e475fc/go.mod h1:08inkKyguB6CGGssc/JzhmQWwBgFQBgjlYFjxjRh7nU=
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-20240716160929-1d5bc16f04a8 h1:Z+vTUQyBb738QmIhbJx3z4htsxDeI+rd0EHvNm8jHkg=
Expand Down
25 changes: 14 additions & 11 deletions internal/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ import (
)

type RootArgs struct {
statements string
quiet bool
authToken string
statements string
quiet bool
authToken string
remoteEncryptionKey string
}

func NewRootCmd() *cobra.Command {
Expand All @@ -26,14 +27,15 @@ func NewRootCmd() *cobra.Command {
Args: cobra.MatchAll(cobra.ExactArgs(1), cobra.OnlyValidArgs),
RunE: func(cmd *cobra.Command, args []string) error {
shellConfig := shell.ShellConfig{
DbUri: args[0],
InF: cmd.InOrStdin(),
OutF: cmd.OutOrStdout(),
ErrF: cmd.ErrOrStderr(),
HistoryMode: enums.PerDatabaseHistory,
HistoryName: "libsql",
QuietMode: rootArgs.quiet,
AuthToken: rootArgs.authToken,
DbUri: args[0],
InF: cmd.InOrStdin(),
OutF: cmd.OutOrStdout(),
ErrF: cmd.ErrOrStderr(),
HistoryMode: enums.PerDatabaseHistory,
HistoryName: "libsql",
QuietMode: rootArgs.quiet,
AuthToken: rootArgs.authToken,
RemoteEncryptionKey: rootArgs.remoteEncryptionKey,
}

if cmd.Flag("exec").Changed {
Expand All @@ -51,6 +53,7 @@ func NewRootCmd() *cobra.Command {
rootCmd.Flags().StringVarP(&rootArgs.statements, "exec", "e", "", "SQL statements separated by ;")
rootCmd.Flags().BoolVarP(&rootArgs.quiet, "quiet", "q", false, "Don't print welcome message")
rootCmd.Flags().StringVar(&rootArgs.authToken, "auth", "", "Add a JWT Token.")
rootCmd.Flags().StringVar(&rootArgs.remoteEncryptionKey, "remote-encryption-key", "", "Add an encryption key for encrypted databases.")

return rootCmd
}
Expand Down
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, schemaDb bool) (*Db, error) {
func NewDb(dbUri, authToken, proxy string, schemaDb bool, remoteEncryptionKey string) (*Db, error) {
var err error

var db = Db{Uri: dbUri, AuthToken: authToken}
Expand All @@ -90,6 +90,9 @@ func NewDb(dbUri, authToken, proxy string, schemaDb bool) (*Db, error) {
if schemaDb {
options = append(options, libsql.WithSchemaDb(schemaDb))
}
if remoteEncryptionKey != "" {
options = append(options, libsql.WithRemoteEncryptionKey(remoteEncryptionKey))
}
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 @@ -14,6 +14,7 @@ import (
type ShellConfig struct {
DbUri string
AuthToken string
RemoteEncryptionKey string
Proxy string
InF io.Reader
OutF io.Writer
Expand All @@ -30,7 +31,7 @@ type ShellConfig struct {
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, config.SchemaDb)
db, err := db.NewDb(config.DbUri, config.AuthToken, config.Proxy, config.SchemaDb, config.RemoteEncryptionKey)
if err != nil {
return err
}
Expand Down Expand Up @@ -60,7 +61,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, config.SchemaDb)
db, err := db.NewDb(config.DbUri, config.AuthToken, config.Proxy, config.SchemaDb, config.RemoteEncryptionKey)
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, "", false)
db, err := db.NewDb(dbUri, authToken, "", false, "")
if err != nil {
t.Fatalf("Fail to create new db. err: %v", err)
}
Expand Down
Loading