go-sqlite icon indicating copy to clipboard operation
go-sqlite copied to clipboard

Do you have plan to support sqlite3?

Open jacobzeng opened this issue 2 years ago • 11 comments

Thank you first for the repo. Do you have plan to support sqlite3?

jacobzeng avatar Feb 17 '23 12:02 jacobzeng

it is indeed sqlite3. What do you mean?

glebarez avatar Feb 18 '23 06:02 glebarez

@jacobzeng you can use this repo just like you would use "github.com/mattn/go-sqlite3". I have had very good results using this repo.

misterunix avatar Feb 18 '23 07:02 misterunix

I can't open DB with sql.Open("sqlite3","data.db") ,maybe I did something wrong?

jacobzeng avatar Feb 18 '23 08:02 jacobzeng

@jacobzeng you can use this repo just like you would use "github.com/mattn/go-sqlite3". I have had very good results using this repo.

Thanks for your tip, but I think mattn/go-sqlite3 need CGO, right? I hate that ^^

jacobzeng avatar Feb 18 '23 08:02 jacobzeng

I can't open DB with sql.Open("sqlite3","data.db") ,maybe I did something wrong?

use

sql.Open("sqlite","data.db")

glebarez avatar Feb 18 '23 11:02 glebarez

Correct mattn needs cgo, thats why I use this repo.

misterunix avatar Feb 18 '23 20:02 misterunix

This issue could probably be closed, but I'm asking in here at the same time. Why does this module depend on the sqlite3 mattn module?

benstigsen avatar Jul 03 '23 22:07 benstigsen

This issue could probably be closed, but I'm asking in here at the same time. Why does this module depend on the sqlite3 mattn module?

This repo does not depend on sqlite3 mattn module (see go.mod). But underlying sqlite lib has it in its go.mod (but still does not use it in code, only for tests) see https://gitlab.com/cznic/sqlite/-/issues/69

glebarez avatar Jul 05 '23 09:07 glebarez

Ah okay.

benstigsen avatar Jul 06 '23 14:07 benstigsen

sql.Open("sqlite","data.db")

The problem with that suggestion is that there are loads of code out there (e.g. ent) that check against the well-known "sqlite3" string to choose SQL dialects.

I see at least a couple of alternatives to deal with this and keep backward-compatibility:

  • add a "compat" subpackage that just does sql.Register("sqlite3", newDriver()) (has the down-side of "acknowledging" the de-facto standard name of "sqlite3")
  • add a way to get the globally initialized Driver, so that the consumer can re-register it under a different name (more flexible but less idiomatic)
  • add something like RegisterAs(string) global function to re-register the Driver (also not idiomatic; probably confusing)

costela avatar Jul 11 '23 16:07 costela

sql.Open("sqlite","data.db")

The problem with that suggestion is that there are loads of code out there (e.g. ent) that check against the well-known "sqlite3" string to chose SQL dialects.

I see at least a couple of alternatives to deal with this and keep backward-compatibility:

  • add a "compat" subpackage that just does sql.Register("sqlite3", newDriver()) (has the down-side of "acknowledging" the de-facto standard name of "sqlite3")

  • add a way to get the globally initialized Driver, so that the consumer can re-register it under a different name (more flexible but less idiomatic)

  • add something like RegisterAs(string) global function to re-register the Driver (also not idiomatic; probably confusing)

I really like option 1 of your suggestion, since it will be a simple import of such compat package, without additional calls. Sounds like good drop-in fix.

glebarez avatar Jul 11 '23 18:07 glebarez