Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
clarkmcc opened this issue Apr 26, 2024 · 2 comments · May be fixed by #134
Open

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

clarkmcc opened this issue Apr 26, 2024 · 2 comments · May be fixed by #134

Comments

@clarkmcc
Copy link

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,
	})
}
@clarkmcc clarkmcc linked a pull request Apr 26, 2024 that will close this issue
@WinXaito
Copy link

WinXaito commented May 3, 2024

I'm facing the same problem, I want to use the backup methods from modernc.org/sqlite, but I got the same error message.

@clarkmcc
Copy link
Author

clarkmcc commented May 3, 2024

This PR solved my issue. If you add a replace directive to your go.mod file with my repo, it should work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants