| 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", |
| 13 |
&sqlite3.SQLiteDriver{ |
| 14 |
Extensions: []string{ |
| 15 |
"sqlite3_mod_vtable", |
| 16 |
}, |
| 17 |
}) |
| 18 |
|
| 19 |
db, err := sql.Open("sqlite3_with_extensions", ":memory:") |
| 20 |
if err != nil { |
| 21 |
log.Fatal(err) |
| 22 |
} |
| 23 |
defer db.Close() |
| 24 |
|
| 25 |
db.Exec("create virtual table repo using github(id, full_name, description, html_url)") |
| 26 |
|
| 27 |
rows, err := db.Query("select id, full_name, description, html_url from repo") |
| 28 |
if err != nil { |
| 29 |
log.Fatal(err) |
| 30 |
} |
| 31 |
defer rows.Close() |
| 32 |
for rows.Next() { |
| 33 |
var id, fullName, description, htmlURL string |
| 34 |
rows.Scan(&id, &fullName, &description, &htmlURL) |
| 35 |
fmt.Printf("%s: %s\n\t%s\n\t%s\n\n", id, fullName, description, htmlURL) |
| 36 |
} |
| 37 |
} |