aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMacaully James Muir <hello@macaullyjames.com>2020-11-16 15:40:44 +0100
committerGitHub <noreply@github.com>2020-11-16 23:40:44 +0900
commit784c625194de154b7be313cd0ce95d5b2b0a0574 (patch)
tree3e820ff4559d8819060f579fe2dd0e91f6e7f191
parentFix #860 extenstion entry bug (#861) (diff)
downloadgolite-784c625194de154b7be313cd0ce95d5b2b0a0574.tar.gz
golite-784c625194de154b7be313cd0ce95d5b2b0a0574.tar.xz
Expand documentation for extension functions (#880)
This relates to #870; it's not immediately clear that you need to pass a different driver name to sql.Open from the documentation.
-rw-r--r--doc.go19
1 files changed, 16 insertions, 3 deletions
diff --git a/doc.go b/doc.go
index c721f77..b15f782 100644
--- a/doc.go
+++ b/doc.go
@@ -93,19 +93,32 @@ you need to set ConnectHook and get the SQLiteConn.
Go SQlite3 Extensions
-If you want to register Go functions as SQLite extension functions,
-call RegisterFunction from ConnectHook.
+If you want to register Go functions as SQLite extension functions
+you can make a custom driver by calling RegisterFunction from
+ConnectHook.
regex = func(re, s string) (bool, error) {
return regexp.MatchString(re, s)
}
- sql.Register("sqlite3_with_go_func",
+ sql.Register("sqlite3_extended",
&sqlite3.SQLiteDriver{
ConnectHook: func(conn *sqlite3.SQLiteConn) error {
return conn.RegisterFunc("regexp", regex, true)
},
})
+You can then use the custom driver by passing its name to sql.Open.
+
+ var i int
+ conn, err := sql.Open("sqlite3_extended", "./foo.db")
+ if err != nil {
+ panic(err)
+ }
+ err = db.QueryRow(`SELECT regexp("foo.*", "seafood")`).Scan(&i)
+ if err != nil {
+ panic(err)
+ }
+
See the documentation of RegisterFunc for more details.
*/