tursodatabase / libsql-client-go

Go client API for libSQL
MIT License
159 stars 23 forks source link

bug: `db.Ping` is a no op #96

Closed avinassh closed 6 months ago

avinassh commented 6 months ago

Connection interface has a Ping method which pings the server and checks if the server is up: https://pkg.go.dev/database/sql#DB.PingContext

Since we don't implement it, even if the server is unreachable, ping does not report any errors. To fix it, we can use a simple query like SELECT 1

Here is a regression test:

import (
    "database/sql"
    "fmt"
    "os"

    _ "github.com/tursodatabase/libsql-client-go/libsql"
)

var dbUrl = "http://127.0.0.1:8080" // some non existent server
db, err := sql.Open("libsql", dbUrl)
if err != nil {
   //
}
db, err := db.Ping()
if err != nil {
  // this never runs
}
webstradev commented 6 months ago

I can take a look at this one

avinassh commented 6 months ago

feel free to @webstradev! 😄