Last active
October 3, 2024 19:34
-
-
Save mbivert/8110564ef8f9abcdf26af8d53f52808a to your computer and use it in GitHub Desktop.
github.com/ncruces/go-sqlite3 : sql: unknown driver "sqlite3" (forgotten import?) / sqlite3: no SQLite binary embed/set/loaded
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"database/sql" | |
"log" | |
// We all know about this one: | |
_ "github.com/ncruces/go-sqlite3" | |
// solves: unknown driver "sqlite3" (forgotten import?) | |
_ "github.com/ncruces/go-sqlite3/driver" | |
// solves: sqlite3: no SQLite binary embed/set/loaded | |
_ "github.com/ncruces/go-sqlite3/embed" | |
) | |
func main() { | |
db, err := sql.Open("sqlite3", ":memory:") | |
if err != nil { | |
log.Fatal("open ", err) | |
} | |
if _, err := db.Exec(`CREATE TABLE IF NOT EXISTS foo (x TEXT)`); err != nil { | |
log.Fatal("create table ", err) | |
} | |
if _, err := db.Exec(`INSERT INTO foo VALUES('foo')`); err != nil { | |
log.Fatal("insert ", err) | |
} | |
x := "" | |
if err := db.QueryRow(`SELECT x FROM foo`).Scan(&x); err != nil { | |
log.Fatal("select ", err) | |
} | |
println(db, x) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment