forked from mirrors/homebox
feat: goreleaser + remove cgo dependency (#363)
* wip: goreleaser * update image path * spelling * set working dir * change main.go * remove unused field * drop cgo requirement * remove unused workflow step * generate code * drop cgo from docker file * update publish workflow * annotate as unfinished
This commit is contained in:
parent
2d768e2b9c
commit
ed1230e17d
48 changed files with 532 additions and 1054 deletions
40
backend/pkgs/cgofreesqlite/sqlite.go
Normal file
40
backend/pkgs/cgofreesqlite/sqlite.go
Normal file
|
@ -0,0 +1,40 @@
|
|||
// sqlite package provides a CGO free implementation of the sqlite3 driver. This wraps the
|
||||
// modernc.org/sqlite driver and adds the PRAGMA foreign_keys = ON; statement to the connection
|
||||
// initialization as well as registering the driver with the sql package as "sqlite3" for compatibility
|
||||
// with entgo.io
|
||||
//
|
||||
// NOTE: This does come with around a 30% performance hit compared to the CGO version of the driver.
|
||||
// however it greatly simplifies the build process and allows for cross compilation.
|
||||
package cgofreesqlite
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"database/sql/driver"
|
||||
|
||||
"modernc.org/sqlite"
|
||||
)
|
||||
|
||||
type CGOFreeSqliteDriver struct {
|
||||
*sqlite.Driver
|
||||
}
|
||||
|
||||
type sqlite3DriverConn interface {
|
||||
Exec(string, []driver.Value) (driver.Result, error)
|
||||
}
|
||||
|
||||
func (d CGOFreeSqliteDriver) Open(name string) (conn driver.Conn, err error) {
|
||||
conn, err = d.Driver.Open(name)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
_, err = conn.(sqlite3DriverConn).Exec("PRAGMA foreign_keys = ON;", nil)
|
||||
if err != nil {
|
||||
_ = conn.Close()
|
||||
return nil, err
|
||||
}
|
||||
return conn, err
|
||||
}
|
||||
|
||||
func init() {
|
||||
sql.Register("sqlite3", CGOFreeSqliteDriver{Driver: &sqlite.Driver{}})
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue