From 075249370ba6622bbfa99d6e9fced3453c18aa10 Mon Sep 17 00:00:00 2001 From: s441433 Date: Fri, 28 Dec 2018 22:14:28 +0100 Subject: [PATCH] Create extension.go --- .../_example/mod_vtable/extension.go | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 src/github.com/mattn/go-sqlite3/_example/mod_vtable/extension.go diff --git a/src/github.com/mattn/go-sqlite3/_example/mod_vtable/extension.go b/src/github.com/mattn/go-sqlite3/_example/mod_vtable/extension.go new file mode 100644 index 0000000..f738af6 --- /dev/null +++ b/src/github.com/mattn/go-sqlite3/_example/mod_vtable/extension.go @@ -0,0 +1,37 @@ +package main + +import ( + "database/sql" + "fmt" + "log" + + "github.com/mattn/go-sqlite3" +) + +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() + + db.Exec("create virtual table repo using github(id, full_name, description, html_url)") + + 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, 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) + } +}