tursodatabase / turso-cli

Command line interface to Turso.
https://turso.tech
MIT License
215 stars 35 forks source link

Turso shell no longer recognizes localhost or 127.0.0.1 URLs #440

Closed CodingDoug closed 1 year ago

CodingDoug commented 1 year ago

I'm pretty certain that the shell used to work with sqld running locally, but it no longer does. This might have broken with #419. This was a great feature to have, and will be important also to work with turso dev in the future (see #435).

haaawk commented 1 year ago

FYI @luisfvieirasilva

glommer commented 1 year ago

this is the reason:

func databaseFromURL(dbURL string, client *turso.Client) (*turso.Database, error) {
        parsed, err := url.ParseRequestURI(dbURL)
        if err != nil {
                return nil, err
        }

        dbs, err := client.Databases.List()
        if err != nil {
                return nil, err
        }

        for _, db := range dbs {
                if strings.HasSuffix(parsed.Hostname(), db.Hostname) {
                        return &db, nil
                }
        }

        return nil, fmt.Errorf("hostname '%s' not found", parsed.Hostname())
}

We always try to map a URL to a database, we shouldn't do that for obvious reasons (localhost)