georgysavva / scany

Library for scanning data from a database into Go structs and more
MIT License
1.24k stars 67 forks source link

Project depending on incorrect version of sqlite3 driver #66

Closed suessflorian closed 2 years ago

suessflorian commented 2 years ago

Awesome project!

Unfortunately I'm getting restricted with what sqlite features I can use when introducing scany into my project.

migration.sql

CREATE TABLE processes(
  id INTEGER PRIMARY KEY AUTOINCREMENT,
  status TEXT CHECK( status IN ('RUNNING','FINISHED','FAILED') )
)

main.go

package main

import (
    "context"
    "database/sql"
    _ "embed"
    "fmt"
    "os"

    "github.com/georgysavva/scany/sqlscan"
    _ "github.com/mattn/go-sqlite3"
    log "github.com/sirupsen/logrus"
)

//go:embed migration.sql
var migration string

type Process struct {
    Pid    int
    Status string
}

func main() {
    os.Create("./test.db")
    conn, err := sql.Open("sqlite3", "./test.db")

    if err != nil {
        log.WithError(err).Fatal("failed to establish connection")
    }

    if _, err := conn.Exec(migration); err != nil {
        log.WithError(err).Fatal("failed to run migration")
    }

    var process Process
    if err := sqlscan.Get(context.TODO(), conn, &process, "INSERT INTO processes(status) VALUES($1) RETURNING *", "RUNNING"); err != nil {
        log.WithError(err).Fatal("failed to scan")
    }

  fmt.Println(process)
}

go mod file here would look like

module example

go 1.16

require (
    github.com/georgysavva/scany v0.2.9
    github.com/mattn/go-sqlite3 v2.0.1+incompatible
    github.com/sirupsen/logrus v1.8.1
)

Running this I get a scany: query one result row: near \"RETURNING\": syntax error error, that is complaining about the RETURNING syntax in sqlite.

I try to fix this by upgrading go-sqlite3 driver to v1.14, which in turn supports sqlite v3.35.0 via go get...

And it just seems to remove scanny altogether :/

 temp/will-remove % go get github.com/mattn/go-sqlite3@v1.14.8
go get: removed github.com/georgysavva/scany v0.2.9
go get: downgraded github.com/jinzhu/gorm v1.9.12 => v1.9.11
go get: downgraded github.com/mattn/go-sqlite3 v2.0.1+incompatible => v1.14.8

I'm sure it's because of the sentence right below https://github.com/mattn/go-sqlite3, but wanting to track this down so I can use scany over sqlite3 with the RETURNING syntax.

georgysavva commented 2 years ago

Hey. I just upgraded the dependencies to support github.com/mattn/go-sqlite3@v1.14.8 here: https://github.com/georgysavva/scany/pull/67 Could you please install the latest scany version from master and try your thing again? To install latest scany from master: go get github.com/georgysavva/scany@HEAD

suessflorian commented 2 years ago

That fixed it, thanks @georgysavva 👍