Skip to content

How to register custom functions? Can't import modernc lib #133

Description

@clarkmcc

I'm trying to figure out how to add custom functions. When I register the custom functions directly to the modernc lib, then I get the following error because both the glebarez lib and the modernc call sql.Register using the same driver name.

 Register called twice for driver sqlite
import (
	"database/sql/driver"
	"fmt"
	"github.com/glebarez/sqlite"
	"github.com/tidwall/gjson"
	"gorm.io/gorm"
	"gorm.io/gorm/logger"
	sqlitecore "modernc.org/sqlite"
)

func init() {
        sqlitecore.RegisterFunction("FOOBAR", &sqlitecore.FunctionImpl{
		NArgs:         2,
		Deterministic: true,
		Scalar: ...,
	})
}

func open(dsn string) (*gorm.DB, error) {
	return gorm.Open(sqlite.Open(dsn), &gorm.Config{
		Logger: logger.Discard,
	})
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions