Go-sqlite3: json_extract support?

Created on 8 Apr 2017  Â·  12Comments  Â·  Source: mattn/go-sqlite3

running go 1.8 on OS X:

  r, err := store.Db.Exec("select * from kv where json_extract(v, '$.title')")
  CheckFatal(err)
goroutine 1 [running]:
runtime/debug.Stack(0xc420128b20, 0x0, 0x0)
    /usr/local/Cellar/go/1.8/libexec/src/runtime/debug/stack.go:24 +0x79
runtime/debug.PrintStack()
    /usr/local/Cellar/go/1.8/libexec/src/runtime/debug/stack.go:16 +0x22
tpods.CheckFatal(0x473ca40, 0xc420128b20, 0x31, 0x0)
    /Users/hgrosman/v/tesla_go/src/tpods/utils.go:100 +0x4c
main.main()
    /Users/hgrosman/v/tesla_go/src/tpods/ack_files.go:371 +0x238
2017/04/07 16:15:01 error:  no such function: json_extract

also: i am using "database/sql".
is there a way to interact with the sqlite APIs directly
(for example calling the backup APIs to load and unload DB in and from :memory:)

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

...
    log.Println("create store: ", store.Filename)
    store.Db, err = sql.Open("sqlite3", store.Filename)
    if err != nil {
        return nil, err
    }

    _, err = store.Db.Exec("PRAGMA busy_timeout = 50000;")
    if err != nil {
        return nil, err
    }

    _, err = store.Db.Exec("PRAGMA journal_mode = OFF;")
    if err != nil {
        return nil, err
    }
...

Most helpful comment

@jonybrn Try -tags not -tag.

All 12 comments

build with -tag json.

go build -tag json github.com/mattn/go-sqlite3

?

doesn't work for me

sorry, json1 not json.

that worked! thank you so much!

  1. why is it not on by default?

  2. can you please help with the second question (how to get to the sqlite api directly - for example loading and unloading :memory: DB from and to files)

  1. because I want to provide smallest and customizable features for all users.
  2. please see _example/*.

can indeed see the example i was looking for here now:
https://github.com/mattn/go-sqlite3/blob/master/_example/hook/hook.go

Thank you Very Much!

thank you for this! very cool.

image

@jonybrn Try -tags not -tag.

Thanks @rittneje this is the right command:
go build -tags json1 github.com/mattn/go-sqlite3

Was this page helpful?
0 / 5 - 0 ratings

Related issues

hackertron picture hackertron  Â·  10Comments

vzool picture vzool  Â·  4Comments

anacrolix picture anacrolix  Â·  6Comments

jacentsao picture jacentsao  Â·  6Comments

tiaguinho picture tiaguinho  Â·  3Comments