Skip to content

Commit f10150c

Browse files
authored
generate turso:// URLs for Turso databases (#1059)
Databases identified as Turso (via the UUID type byte, `id[5] == 0x10`) now display `turso://` URLs instead of `libsql://` in `db list`, `db show`, and the shell's connection banner. SQLite databases keep `libsql://`. The built-in shell also accepts `turso://` URLs: the scheme is rewritten to `libsql` right after parsing, since `libsql-shell-go` only understands `libsql`/`ws`/`wss`/`http`/`https`. The shell library is quite legacy at this point and the CLI should be moving to the tursodb binary anyway, so for now the rewrite is just hacked in on the CLI side rather than teaching the library about `turso://`. Instance URLs (`--instance-url`) still use `libsql://`, since instances are a sqld-only concept. Includes a new `TestGetDatabaseUrl` covering Turso, SQLite, and empty-ID cases, and updates the list test to expect the new scheme. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
2 parents e478563 + d2d8881 commit f10150c

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)