mattn / go-sqlite3

sqlite3 driver for go using database/sql
http://mattn.github.io/go-sqlite3
MIT License
7.83k stars 1.09k forks source link

Problems building with --tags json1 #544

Closed thisisaaronland closed 6 years ago

thisisaaronland commented 6 years ago

Hi,

I am trying to add json1 support to this package which uses go-sqlite3 under the hood:

https://github.com/whosonfirst/go-whosonfirst-sqlite

I have updated the build process to install go-sqlite3with the --tags json1 flag per the docs:

@GOPATH=$(GOPATH) go get "github.com/mattn/go-sqlite3"
@GOPATH=$(GOPATH) go install --tags json1 "github.com/mattn/go-sqlite3"

And everything builds/compiles properly but I am still getting "no such function: json_extract". I think I am doing everything correctly but maybe I'm missing something? Thoughts?

package main

import (
        "flag"
        "github.com/whosonfirst/go-whosonfirst-sqlite/database"
    "log"
)

func main (){

        dsn := flag.String("dsn", ":memory:", "")
        driver := flag.String("driver", "sqlite3", "")

        flag.Parse()

    db, err := database.NewDBWithDriver(*driver, *dsn)

        if err != nil {
           log.Fatal(err)
        }

        defer db.Close()

        conn, err := db.Conn()

        if err != nil {
           log.Fatal(err)
        }

    sql := "SELECT id, properties, geom FROM geojson WHERE json_extract(properties, '$.placetype') = 'venue'"
        _, err = conn.Query(sql)

        if err != nil {
           log.Fatal(err)
        }

        log.Println("OK")
}
FiloSottile commented 6 years ago

You need to build your actual binary with --tags json1, the tags apply to all dependencies every time.

thisisaaronland commented 6 years ago

Ah, okay. That would be the part that I was missing :D

I re-built my tests with and without the --tags flag and everything works (or doesn't work) as expected.

Thanks!