2016-12-11 17:49:48 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"database/sql"
|
|
|
|
"fmt"
|
|
|
|
"log"
|
2017-03-05 11:49:45 +00:00
|
|
|
|
|
|
|
"github.com/mattn/go-sqlite3"
|
2016-12-11 17:49:48 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
sql.Register("sqlite3_with_extensions", &sqlite3.SQLiteDriver{
|
|
|
|
ConnectHook: func(conn *sqlite3.SQLiteConn) error {
|
2017-03-05 11:49:45 +00:00
|
|
|
return conn.CreateModule("github", &githubModule{})
|
2016-12-11 17:49:48 +00:00
|
|
|
},
|
|
|
|
})
|
|
|
|
db, err := sql.Open("sqlite3_with_extensions", ":memory:")
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
defer db.Close()
|
|
|
|
|
|
|
|
_, 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() {
|
|
|
|
var id, full_name, description, html_url string
|
|
|
|
rows.Scan(&id, &full_name, &description, &html_url)
|
|
|
|
fmt.Printf("%s: %s\n\t%s\n\t%s\n\n", id, full_name, description, html_url)
|
|
|
|
}
|
|
|
|
}
|