Skip to content

Commit d2d8881

Browse files
glommerclaude
andcommitted
generate turso:// URLs for Turso databases
Databases identified as Turso (via the UUID type byte) now display turso:// URLs instead of libsql:// in db list, db show, and the shell banner. The built-in shell also accepts turso:// URLs, rewriting the scheme to libsql before handing it to libsql-shell-go, which only understands libsql/ws/http schemes. The shell library is quite legacy at this point, and we should be moving the CLI to the tursodb binary anyway, so for now we just hack the scheme rewrite here rather than teaching the library about turso://. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
1 parent e478563 commit d2d8881

4 files changed

Lines changed: 47 additions & 1 deletion

File tree

internal/cmd/db_shell.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,10 @@ var shellCmd = &cobra.Command{
166166
if err != nil {
167167
return err
168168
}
169+
// the shell library only understands libsql/ws/http schemes
170+
if u.Scheme == "turso" {
171+
u.Scheme = "libsql"
172+
}
169173
query := u.Query()
170174
authTokenSnake := query.Get("auth_token")
171175
authTokenCamel := query.Get("authToken")

internal/cmd/list_databases_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ func TestDbListModelViewIncludesTypeColumn(t *testing.T) {
2929
expected := [][]string{
3030
{"NAME", "TYPE", "GROUP", "URL"},
3131
{"sqlite-db", "SQLite", "-", "libsql://sqlite-db.example.com"},
32-
{"turso-db", "Turso", "default", "libsql://turso-db.example.com"},
32+
{"turso-db", "Turso", "default", "turso://turso-db.example.com"},
3333
}
3434

3535
if len(lines) != len(expected) {

internal/cmd/utils.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,9 @@ func extractPrimary(instances []turso.Instance) (primary *turso.Instance, others
8181
}
8282

8383
func getDatabaseUrl(db *turso.Database) string {
84+
if isTursoDB(db.ID) {
85+
return getUrl(db, nil, "turso")
86+
}
8487
return getUrl(db, nil, "libsql")
8588
}
8689

internal/cmd/utils_test.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package cmd
2+
3+
import (
4+
"testing"
5+
6+
"github.com/tursodatabase/turso-cli/internal/turso"
7+
)
8+
9+
func TestGetDatabaseUrl(t *testing.T) {
10+
tests := []struct {
11+
name string
12+
db turso.Database
13+
want string
14+
}{
15+
{
16+
name: "turso database",
17+
db: turso.Database{ID: "019db7a2-9210-79e5-afed-0b1755901d50", Hostname: "turso-db.example.com"},
18+
want: "turso://turso-db.example.com",
19+
},
20+
{
21+
name: "sqlite database",
22+
db: turso.Database{ID: "00000000-1100-0000-0000-000000000000", Hostname: "sqlite-db.example.com"},
23+
want: "libsql://sqlite-db.example.com",
24+
},
25+
{
26+
name: "no id",
27+
db: turso.Database{Hostname: "db.example.com"},
28+
want: "libsql://db.example.com",
29+
},
30+
}
31+
32+
for _, tt := range tests {
33+
t.Run(tt.name, func(t *testing.T) {
34+
if got := getDatabaseUrl(&tt.db); got != tt.want {
35+
t.Fatalf("getDatabaseUrl() = %q, want %q", got, tt.want)
36+
}
37+
})
38+
}
39+
}

0 commit comments

Comments
 (0)