Automatically load extensions. (#115)

This commit is contained in:
Nuno Cruces
2024-07-08 12:06:57 +01:00
committed by GitHub
parent fff8b1c74f
commit b5f746aadf
36 changed files with 261 additions and 245 deletions

View File

@@ -20,8 +20,8 @@ import (
// Register registers the bloom_filter virtual table:
//
// CREATE VIRTUAL TABLE foo USING bloom_filter(nElements, falseProb, kHashes)
func Register(db *sqlite3.Conn) {
sqlite3.CreateModule(db, "bloom_filter", create, connect)
func Register(db *sqlite3.Conn) error {
return sqlite3.CreateModule(db, "bloom_filter", create, connect)
}
type bloom struct {

View File

@@ -12,6 +12,10 @@ import (
_ "github.com/ncruces/go-sqlite3/internal/testcfg"
)
func init() {
sqlite3.AutoExtension(bloom.Register)
}
func TestRegister(t *testing.T) {
t.Parallel()
@@ -21,8 +25,6 @@ func TestRegister(t *testing.T) {
}
defer db.Close()
bloom.Register(db)
err = db.Exec(`
CREATE VIRTUAL TABLE sports_cars USING bloom_filter(20);
INSERT INTO sports_cars VALUES ('ferrari'), ('lamborghini'), ('alfa romeo')
@@ -90,8 +92,6 @@ func Test_compatible(t *testing.T) {
}
defer db.Close()
bloom.Register(db)
query, _, err := db.Prepare(`SELECT COUNT(*) FROM plants(?)`)
if err != nil {
t.Fatal(err)