A Go package that makes it easier to run SQL queries async
go get -u github.com/danielgatis/go-asql
And then import the package in your code:
import "github.com/danielgatis/go-asql"
package main
import (
"fmt"
"github.com/danielgatis/go-asql"
_ "github.com/mattn/go-sqlite3"
)
func main() {
type TestTable struct {
ID int
Name string
}
db, _ := asql.Open("sqlite3", "file::memory:")
db.Load("testdata/schema.sql")
rc, _ := db.Query(`select * from test_table`)
rows := <-rc
records := make([]TestTable, 0)
for rows.Next() {
var record TestTable
rows.Scan(&record.ID, &record.Name)
records = append(records, record)
}
fmt.Print(records)
}
Copyright (c) 2023-present Daniel Gatis
Licensed under MIT License
Liked some of my work? Buy me a coffee (or more likely a beer)