Skip to content

Commit 32b6a0a

Browse files
authored
Allow connecting local dbs just by name (#997)
Currently, if I am connecting to a local db server, I need to specify the full URL: ``` turso db shell http://sunny-doomsday-local-user.localhost:9090 ``` if I just specify the name, I get an error: ``` turso db shell sunny-doomsday Error: failed to connect to database. err: failed to execute SQL: Post "https://sunny-doomsday-local-user.localhost:9090/v2/pipeline": http: server gave HTTP response to HTTPS client exit status 1 ``` so to fix this, if we find the db to be running locally, then we fallback to http and then we can connect to the local dbs just by the name
2 parents a9214f9 + 89a8f8e commit 32b6a0a

2 files changed

Lines changed: 15 additions & 1 deletion

File tree

internal/cmd/db_shell.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ func getURL(db *turso.Database, client *turso.Client, http bool, primaryOnly boo
4040
scheme = "https"
4141
}
4242

43+
if isLocalDevelopmentDb(db) {
44+
// for locally running dbs, we fallback to http scheme
45+
scheme = "http"
46+
}
47+
4348
if instanceFlag == "" && locationFlag == "" {
4449
if !primaryOnly {
4550
return getUrl(db, nil, scheme), nil

internal/cmd/utils.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,11 @@ func getInstanceUrl(db *turso.Database, inst *turso.Instance) string {
8787
}
8888

8989
func getDatabaseHttpUrl(db *turso.Database) string {
90-
return getUrl(db, nil, "https")
90+
scheme := "https"
91+
if isLocalDevelopmentDb(db) {
92+
scheme = "http"
93+
}
94+
return getUrl(db, nil, scheme)
9195
}
9296

9397
func getUrl(db *turso.Database, inst *turso.Instance, scheme string) string {
@@ -372,3 +376,8 @@ func isInteractive() bool {
372376
func isTerminal(f *os.File) bool {
373377
return isatty.IsTerminal(f.Fd()) || isatty.IsCygwinTerminal(f.Fd())
374378
}
379+
380+
// isLocalDevelopmentDb checks if the db is running on a local server.
381+
func isLocalDevelopmentDb(db *turso.Database) bool {
382+
return db.PrimaryRegion == "local"
383+
}

0 commit comments

Comments
 (0)