JSON functions in SQLite

Viewed 389

I am trying to get the SQLite JSON functions to work with Go and the github.com/mattn/go-sqlite3 driver but not having much luck.

Using VSCode as my editor I did:

  1. go get github.com/mattn/go-sqlite3
  2. go build --tags "json1" github.com/mattn/go-sqlite3
  3. Wrote my test app which calls the following function
func IsJSONValid(payloadID int) bool {
    var isValid int
    sql := `select json_valid(json_payload) from exec_payload where payload_id = ?`

    err = database.QueryRow(sql, payloadID).Scan(&isValid)
    if err != nil {
        log.Println(err)
        log.Println("Fatal - unable to validate JSON payload")
        LogDb("IsJSONValid", "unable to validate JSON payload")
        return false
    }

    if isValid == 0 {
        return false
    }

    return true
}

Executing the code/func I get the following error:

no such function: json_valid

I know I can write a Struct and handle the logic to validate the json data stored in the sqlite table column - however it's pretty convenient to use / have the function already available in the DB - running the same query in the sqlite command line tool executes without any issues.

0 Answers
Related