Package fastsql is a library which extends Go's standard database/sql library. It provides performance that's easy to take advantage of.
Even better, the fastsql.DB object embeds the standard sql.DB object meaning access to all the standard database/sql library functionality is preserved. It also means that integrating fastsql into existing codebases is a breeze.
Additional functionality inclues:
- Easy, readable, and performant batch insert queries using the BatchInsert method.
- Automatic creation and re-use of prepared statements.
- A convenient holder for manually used prepared statements.
##Example usage
package main
import (
_ "github.com/go-sql-driver/mysql"
"github.com/rmulley/go-fast-sql"
"log"
"net/url"
)
func main() {
var (
err error
i uint = 1
dbh *fastsql.DB
)
// Create new FastSQL DB object with a flush-interval of 100 rows
if dbh, err = fastsql.Open("mysql", "user:pass@tcp(localhost:3306)/db_name?"+url.QueryEscape("charset=utf8mb4,utf8&loc=America/New_York"), 100); err != nil {
log.Fatalln(err)
}
defer dbh.Close()
// Some loop performing SQL INSERTs
for i <= 250 {
if err = dbh.BatchInsert("INSERT INTO test_table(id, id2, id3) VALUES(?, ?, ?);", i, i + 1, i + 2); err != nil {
log.Fatalln(err)
}
i++
}
}