Skip to content

How to load the json1 extension? #832

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

Open
sanket28 opened this issue Jul 10, 2020 · 1 comment
Open

How to load the json1 extension? #832

sanket28 opened this issue Jul 10, 2020 · 1 comment

Comments

@sanket28
Copy link

Hello,

I'm trying to load the json1 extension. I know you can do it by specifying the --tags option in your go build command. But just wanted to know if its possible to load it during runtime. I tried doing it but no luck. Here's the code snippet:

import (
    "database/sql"
    "github.com/mattn/go-sqlite3"
)

func connect(dbPath string) error {
    sql.Register("sqlite3_json1", &sqlite3.SQLiteDriver{
		ConnectHook: func(conn *sqlite3.SQLiteConn) error {
			if err := conn.LoadExtension("sqlite_json1", ""); err != nil {
				return err
			}
			return nil
		},
    })
    dbc, err := sql.Open("sqlite3", dbPath)
    if err != nil {
	return nil, err
    }
    return nil
}

Please advise. Thanks!

@cyrixSpec
Copy link

cyrixSpec commented Jan 21, 2021

Hi,

first compile the extension
gcc -g -fPIC -shared json1.c -o json1.so

now you can use the extension

` sql.Register("sqlite3_with_extensions",
&sqlite3.SQLiteDriver{
Extensions: []string{
"json1",
},
})

db, err := sql.Open("sqlite3_with_extensions", filename)`

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

No branches or pull requests

2 participants