Debian Codegraph @

_example/vtable/main.go

raw
1 package main
2
3 import (
4 "database/sql"
5 "fmt"
6 "log"
7
8 "github.com/mattn/go-sqlite3"
9 )
10
11 func main() {
12 sql.Register("sqlite3_with_extensions", &sqlite3.SQLiteDriver{
13 ConnectHook: func(conn *sqlite3.SQLiteConn) error {
14 return conn.CreateModule("github", &githubModule{})
15 },
16 })
17 db, err := sql.Open("sqlite3_with_extensions", ":memory:")
18 if err != nil {
19 log.Fatal(err)
20 }
21 defer db.Close()
22
23 _, err = db.Exec("create virtual table repo using github(id, full_name, description, html_url)")
24 if err != nil {
25 log.Fatal(err)
26 }
27
28 rows, err := db.Query("select id, full_name, description, html_url from repo")
29 if err != nil {
30 log.Fatal(err)
31 }
32 defer rows.Close()
33 for rows.Next() {
34 var id, fullName, description, htmlURL string
35 rows.Scan(&id, &fullName, &description, &htmlURL)
36 fmt.Printf("%s: %s\n\t%s\n\t%s\n\n", id, fullName, description, htmlURL)
37 }
38 }