turboquery is a Go package that allows you to query multiple databases or replicas with the same query and returns the fastest result while canceling the remaining queries. It helps you find the fastest queries among multiple database sources if you don't care about extra load to every source and replication lag.
To use turboquery in your Go project, you need to have Go installed and set up. Then, you can install the package using the following command:
go get github.com/Yuni-sa/go-turboquery@v0.0.2
Here's an example of how to use turboquery with a mysql cluster:
package main
import (
"fmt"
"github.com/Yuni-sa/go-turboquery"
_ "github.com/go-sql-driver/mysql"
)
func main() {
replicas := []turboquery.ReplicaInfo{
{
Name: "replica1",
DSN: "replica1_connection_string",
},
{
Name: "replica2",
DSN: "replica2_connection_string",
},
// Add more replicas as needed
}
query := "SELECT * FROM your_table"
result := turboquery.MultiQuery(replicas, query)
fmt.Println(result)
}