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
4 changes: 4 additions & 0 deletions internal/cmd/db_shell.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,10 @@ var shellCmd = &cobra.Command{
if err != nil {
return err
}
// the shell library only understands libsql/ws/http schemes
if u.Scheme == "turso" {
u.Scheme = "libsql"
}
query := u.Query()
authTokenSnake := query.Get("auth_token")
authTokenCamel := query.Get("authToken")
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/list_databases_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func TestDbListModelViewIncludesTypeColumn(t *testing.T) {
expected := [][]string{
{"NAME", "TYPE", "GROUP", "URL"},
{"sqlite-db", "SQLite", "-", "libsql://sqlite-db.example.com"},
{"turso-db", "Turso", "default", "libsql://turso-db.example.com"},
{"turso-db", "Turso", "default", "turso://turso-db.example.com"},
}

if len(lines) != len(expected) {
Expand Down
3 changes: 3 additions & 0 deletions internal/cmd/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ func extractPrimary(instances []turso.Instance) (primary *turso.Instance, others
}

func getDatabaseUrl(db *turso.Database) string {
if isTursoDB(db.ID) {
return getUrl(db, nil, "turso")
}
return getUrl(db, nil, "libsql")
}

Expand Down
39 changes: 39 additions & 0 deletions internal/cmd/utils_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package cmd

import (
"testing"

"github.com/tursodatabase/turso-cli/internal/turso"
)

func TestGetDatabaseUrl(t *testing.T) {
tests := []struct {
name string
db turso.Database
want string
}{
{
name: "turso database",
db: turso.Database{ID: "019db7a2-9210-79e5-afed-0b1755901d50", Hostname: "turso-db.example.com"},
want: "turso://turso-db.example.com",
},
{
name: "sqlite database",
db: turso.Database{ID: "00000000-1100-0000-0000-000000000000", Hostname: "sqlite-db.example.com"},
want: "libsql://sqlite-db.example.com",
},
{
name: "no id",
db: turso.Database{Hostname: "db.example.com"},
want: "libsql://db.example.com",
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := getDatabaseUrl(&tt.db); got != tt.want {
t.Fatalf("getDatabaseUrl() = %q, want %q", got, tt.want)
}
})
}
}
Loading