Skip to content

how to build go-sqlite3 to include the json feature ? #710

Closed
@jiehuaou

Description

@jiehuaou

Here is my install procedure:

  1. go get github.com/mattn/go-sqlite3
  2. go build -tags json1 github.com/mattn/go-sqlite3
  3. go install github.com/mattn/go-sqlite3

after build and install , I run my code like this:

// open database
database, _ := sql.Open("sqlite3", "file:test.db?cache=shared&mode=memory")
statement, _ := database.Prepare("CREATE TABLE IF NOT EXISTS people (id INTEGER PRIMARY KEY, key TEXT, value TEXT, valueJson)")
statement.Exec()

``
// INSERT data
statement, _ = database.Prepare("INSERT INTO people (key, valueJson) VALUES (?, ?)")
statement.Exec("Nic", {"a":1, "b": "Raboy"})
statement.Exec("Hello", `{"a":2, "b": "World"}`)

sqlStr := `SELECT id, key, valueJson FROM people where json_extract(valueJson, "$.a")=2`

rows, err := database.Query(sqlStr)
if err != nil {
	fmt.Println(err)
}

`
then I got this error
no such function: json_extract
panic: runtime error: invalid memory address or nil pointer dereference

what did I miss ?

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