You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There is a very handy extension for generating UUIDs in sqlite: https://sqlite.org/src/file/ext/misc/uuid.c
It would be nice to include it into go-sqlite3 as a loadable extension.
It's actually very small and shouldn't add too much overhead, so it could also be loaded per default.
I did not really understand how the upgrade tool pulls in extensions, or how I would add the extension there.
As an alternative, one can create a new instance of the driver with a go implementation. I successfully made that work, but it was basically impossible to use with other libraries like ORMs due to the self-initialization nature of the go SQL drivers.
The text was updated successfully, but these errors were encountered:
For those wanting uuid functionality in the meantime, you can register it with the driver something like this (this specific one is in conjunction with sqlc):
import (
"database/sql""log""os""github.com/google/uuid""github.com/mattn/go-sqlite3"
)
typeDatabasestruct {
Conn*sql.DBQueries*Queries
}
// opens the `DB_STRING` sqlite database.func (db*Database) Connect() {
// register the sqlite driver with a uuid functionsql.Register("sqlite3_uuid", &sqlite3.SQLiteDriver{
ConnectHook: func(sc*sqlite3.SQLiteConn) error {
returnsc.RegisterFunc("uuid", func() string {
returnuuid.New().String()
}, true)
},
})
// open the sqlite connectionconn, err:=sql.Open("sqlite3_uuid", os.Getenv("DB_STRING"))
iferr!=nil {
log.Fatalf("failed to open sqlite database: %v", err)
}
db.Conn=conndb.Queries=New(db.Conn)
}
There is a very handy extension for generating UUIDs in sqlite: https://sqlite.org/src/file/ext/misc/uuid.c
It would be nice to include it into go-sqlite3 as a loadable extension.
It's actually very small and shouldn't add too much overhead, so it could also be loaded per default.
I did not really understand how the upgrade tool pulls in extensions, or how I would add the extension there.
As an alternative, one can create a new instance of the driver with a go implementation. I successfully made that work, but it was basically impossible to use with other libraries like ORMs due to the self-initialization nature of the go SQL drivers.
The text was updated successfully, but these errors were encountered: