extension.go 773 B

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