Skip to content

How to load the json1 extension? #832

@sanket28

Description

@sanket28

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!

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