go-sqlite3/_examples/mod_vtable/extension.go

45 lines
872 B
Go
Raw Normal View History

package main
import (
"database/sql"
"fmt"
"log"
2018-06-15 18:53:32 +03:00
"os"
2017-03-05 16:29:09 +03:00
"github.com/mattn/go-sqlite3/driver"
)
func main() {
sql.Register("sqlite3_with_extensions",
&sqlite3.SQLiteDriver{
Extensions: []string{
"sqlite3_mod_vtable",
},
})
db, err := sql.Open("sqlite3_with_extensions", ":memory:")
if err != nil {
log.Fatal(err)
}
defer db.Close()
2018-06-15 18:53:32 +03:00
_, err = db.Exec("create virtual table repo using github(id, full_name, description, html_url)")
if err != nil {
log.Fatal(err)
}
rows, err := db.Query("select id, full_name, description, html_url from repo")
if err != nil {
log.Fatal(err)
}
defer rows.Close()
for rows.Next() {
2017-03-05 16:29:09 +03:00
var id, fullName, description, htmlURL string
rows.Scan(&id, &fullName, &description, &htmlURL)
fmt.Printf("%s: %s\n\t%s\n\t%s\n\n", id, fullName, description, htmlURL)
}
2018-06-15 18:53:32 +03:00
fmt.Println("Clean Exit")
os.Exit(0)
}