summaryrefslogtreecommitdiffstats
path: root/dependencies/pkg/mod/github.com/mattn/go-sqlite3@v1.14.16/_example/vtable
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--dependencies/pkg/mod/github.com/mattn/go-sqlite3@v1.14.16/_example/vtable/main.go38
-rw-r--r--dependencies/pkg/mod/github.com/mattn/go-sqlite3@v1.14.16/_example/vtable/vtable.go116
-rw-r--r--dependencies/pkg/mod/github.com/mattn/go-sqlite3@v1.14.16/_example/vtable_eponymous_only/main.go33
-rw-r--r--dependencies/pkg/mod/github.com/mattn/go-sqlite3@v1.14.16/_example/vtable_eponymous_only/vtable.go118
4 files changed, 305 insertions, 0 deletions
diff --git a/dependencies/pkg/mod/github.com/mattn/go-sqlite3@v1.14.16/_example/vtable/main.go b/dependencies/pkg/mod/github.com/mattn/go-sqlite3@v1.14.16/_example/vtable/main.go
new file mode 100644
index 0000000..aad8dda
--- /dev/null
+++ b/dependencies/pkg/mod/github.com/mattn/go-sqlite3@v1.14.16/_example/vtable/main.go
@@ -0,0 +1,38 @@
+package main
+
+import (
+ "database/sql"
+ "fmt"
+ "log"
+
+ "github.com/mattn/go-sqlite3"
+)
+
+func main() {
+ sql.Register("sqlite3_with_extensions", &sqlite3.SQLiteDriver{
+ ConnectHook: func(conn *sqlite3.SQLiteConn) error {
+ return conn.CreateModule("github", &githubModule{})
+ },
+ })
+ 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, 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)
+ }
+}
diff --git a/dependencies/pkg/mod/github.com/mattn/go-sqlite3@v1.14.16/_example/vtable/vtable.go b/dependencies/pkg/mod/github.com/mattn/go-sqlite3@v1.14.16/_example/vtable/vtable.go
new file mode 100644
index 0000000..dd457ea
--- /dev/null
+++ b/dependencies/pkg/mod/github.com/mattn/go-sqlite3@v1.14.16/_example/vtable/vtable.go
@@ -0,0 +1,116 @@
+package main
+
+import (
+ "encoding/json"
+ "fmt"
+ "io/ioutil"
+ "net/http"
+
+ "github.com/mattn/go-sqlite3"
+)
+
+type githubRepo struct {
+ ID int `json:"id"`
+ FullName string `json:"full_name"`
+ Description string `json:"description"`
+ HTMLURL string `json:"html_url"`
+}
+
+type githubModule struct {
+}
+
+func (m *githubModule) Create(c *sqlite3.SQLiteConn, args []string) (sqlite3.VTab, error) {
+ err := c.DeclareVTab(fmt.Sprintf(`
+ CREATE TABLE %s (
+ id INT,
+ full_name TEXT,
+ description TEXT,
+ html_url TEXT
+ )`, args[0]))
+ if err != nil {
+ return nil, err
+ }
+ return &ghRepoTable{}, nil
+}
+
+func (m *githubModule) Connect(c *sqlite3.SQLiteConn, args []string) (sqlite3.VTab, error) {
+ return m.Create(c, args)
+}
+
+func (m *githubModule) DestroyModule() {}
+
+type ghRepoTable struct {
+ repos []githubRepo
+}
+
+func (v *ghRepoTable) Open() (sqlite3.VTabCursor, error) {
+ resp, err := http.Get("https://api.github.com/repositories")
+ if err != nil {
+ return nil, err
+ }
+ defer resp.Body.Close()
+
+ body, err := ioutil.ReadAll(resp.Body)
+ if err != nil {
+ return nil, err
+ }
+
+ var repos []githubRepo
+ if err := json.Unmarshal(body, &repos); err != nil {
+ return nil, err
+ }
+ return &ghRepoCursor{0, repos}, nil
+}
+
+func (v *ghRepoTable) BestIndex(cst []sqlite3.InfoConstraint, ob []sqlite3.InfoOrderBy) (*sqlite3.IndexResult, error) {
+ used := make([]bool, len(csts))
+ return &sqlite3.IndexResult{
+ IdxNum: 0,
+ IdxStr: "default",
+ Used: used,
+ }, nil
+}
+
+func (v *ghRepoTable) Disconnect() error { return nil }
+func (v *ghRepoTable) Destroy() error { return nil }
+
+type ghRepoCursor struct {
+ index int
+ repos []githubRepo
+}
+
+func (vc *ghRepoCursor) Column(c *sqlite3.SQLiteContext, col int) error {
+ switch col {
+ case 0:
+ c.ResultInt(vc.repos[vc.index].ID)
+ case 1:
+ c.ResultText(vc.repos[vc.index].FullName)
+ case 2:
+ c.ResultText(vc.repos[vc.index].Description)
+ case 3:
+ c.ResultText(vc.repos[vc.index].HTMLURL)
+ }
+ return nil
+}
+
+func (vc *ghRepoCursor) Filter(idxNum int, idxStr string, vals []interface{}) error {
+ vc.index = 0
+ return nil
+}
+
+func (vc *ghRepoCursor) Next() error {
+ vc.index++
+ return nil
+}
+
+func (vc *ghRepoCursor) EOF() bool {
+ return vc.index >= len(vc.repos)
+}
+
+func (vc *ghRepoCursor) Rowid() (int64, error) {
+ return int64(vc.index), nil
+}
+
+func (vc *ghRepoCursor) Close() error {
+ return nil
+}
diff --git a/dependencies/pkg/mod/github.com/mattn/go-sqlite3@v1.14.16/_example/vtable_eponymous_only/main.go b/dependencies/pkg/mod/github.com/mattn/go-sqlite3@v1.14.16/_example/vtable_eponymous_only/main.go
new file mode 100644
index 0000000..17b58af
--- /dev/null
+++ b/dependencies/pkg/mod/github.com/mattn/go-sqlite3@v1.14.16/_example/vtable_eponymous_only/main.go
@@ -0,0 +1,33 @@
+package main
+
+import (
+ "database/sql"
+ "fmt"
+ "log"
+
+ "github.com/mattn/go-sqlite3"
+)
+
+func main() {
+ sql.Register("sqlite3_with_extensions", &sqlite3.SQLiteDriver{
+ ConnectHook: func(conn *sqlite3.SQLiteConn) error {
+ return conn.CreateModule("series", &seriesModule{})
+ },
+ })
+ db, err := sql.Open("sqlite3_with_extensions", ":memory:")
+ if err != nil {
+ log.Fatal(err)
+ }
+ defer db.Close()
+
+ rows, err := db.Query("select * from series")
+ if err != nil {
+ log.Fatal(err)
+ }
+ defer rows.Close()
+ for rows.Next() {
+ var value int
+ rows.Scan(&value)
+ fmt.Printf("value: %d\n", value)
+ }
+}
diff --git a/dependencies/pkg/mod/github.com/mattn/go-sqlite3@v1.14.16/_example/vtable_eponymous_only/vtable.go b/dependencies/pkg/mod/github.com/mattn/go-sqlite3@v1.14.16/_example/vtable_eponymous_only/vtable.go
new file mode 100644
index 0000000..49fc0b7
--- /dev/null
+++ b/dependencies/pkg/mod/github.com/mattn/go-sqlite3@v1.14.16/_example/vtable_eponymous_only/vtable.go
@@ -0,0 +1,118 @@
+package main
+
+import (
+ "fmt"
+
+ "github.com/mattn/go-sqlite3"
+)
+
+type seriesModule struct{}
+
+func (m *seriesModule) EponymousOnlyModule() {}
+
+func (m *seriesModule) Create(c *sqlite3.SQLiteConn, args []string) (sqlite3.VTab, error) {
+ err := c.DeclareVTab(fmt.Sprintf(`
+ CREATE TABLE %s (
+ value INT,
+ start HIDDEN,
+ stop HIDDEN,
+ step HIDDEN
+ )`, args[0]))
+ if err != nil {
+ return nil, err
+ }
+ return &seriesTable{0, 0, 1}, nil
+}
+
+func (m *seriesModule) Connect(c *sqlite3.SQLiteConn, args []string) (sqlite3.VTab, error) {
+ return m.Create(c, args)
+}
+
+func (m *seriesModule) DestroyModule() {}
+
+type seriesTable struct {
+ start int64
+ stop int64
+ step int64
+}
+
+func (v *seriesTable) Open() (sqlite3.VTabCursor, error) {
+ return &seriesCursor{v, 0}, nil
+}
+
+func (v *seriesTable) BestIndex(csts []sqlite3.InfoConstraint, ob []sqlite3.InfoOrderBy) (*sqlite3.IndexResult, error) {
+ used := make([]bool, len(csts))
+ for c, cst := range csts {
+ if cst.Usable && cst.Op == sqlite3.OpEQ {
+ used[c] = true
+ }
+ }
+
+ return &sqlite3.IndexResult{
+ IdxNum: 0,
+ IdxStr: "default",
+ Used: used,
+ }, nil
+}
+
+func (v *seriesTable) Disconnect() error { return nil }
+func (v *seriesTable) Destroy() error { return nil }
+
+type seriesCursor struct {
+ *seriesTable
+ value int64
+}
+
+func (vc *seriesCursor) Column(c *sqlite3.SQLiteContext, col int) error {
+ switch col {
+ case 0:
+ c.ResultInt64(vc.value)
+ case 1:
+ c.ResultInt64(vc.seriesTable.start)
+ case 2:
+ c.ResultInt64(vc.seriesTable.stop)
+ case 3:
+ c.ResultInt64(vc.seriesTable.step)
+ }
+ return nil
+}
+
+func (vc *seriesCursor) Filter(idxNum int, idxStr string, vals []interface{}) error {
+ switch {
+ case len(vals) < 1:
+ vc.seriesTable.start = 0
+ vc.seriesTable.stop = 1000
+ vc.value = vc.seriesTable.start
+ case len(vals) < 2:
+ vc.seriesTable.start = vals[0].(int64)
+ vc.seriesTable.stop = 1000
+ vc.value = vc.seriesTable.start
+ case len(vals) < 3:
+ vc.seriesTable.start = vals[0].(int64)
+ vc.seriesTable.stop = vals[1].(int64)
+ vc.value = vc.seriesTable.start
+ case len(vals) < 4:
+ vc.seriesTable.start = vals[0].(int64)
+ vc.seriesTable.stop = vals[1].(int64)
+ vc.seriesTable.step = vals[2].(int64)
+ }
+
+ return nil
+}
+
+func (vc *seriesCursor) Next() error {
+ vc.value += vc.step
+ return nil
+}
+
+func (vc *seriesCursor) EOF() bool {
+ return vc.value > vc.stop
+}
+
+func (vc *seriesCursor) Rowid() (int64, error) {
+ return int64(vc.value), nil
+}
+
+func (vc *seriesCursor) Close() error {
+ return nil
+}