Documentation
¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Attach ¶
Attach attaches an additional SQLite database file (dbfile) to the default database connection under the schema alias dbname using the SQLite ATTACH DATABASE statement.
func InitDefault ¶
InitDefault opens SQLite and stores it as the dbsqlx default database.
Example ¶
ExampleInitDefault shows the default-instance pattern: call InitDefault once at application startup, then retrieve the shared *sqlx.DB via dbsqlx.Default().
package main
import (
"fmt"
"github.com/phcp-tech/common-library-golang/dbsqlx"
"github.com/phcp-tech/common-library-golang/dbsqlx/sqlite"
)
func main() {
err := sqlite.InitDefault(&sqlite.Config{Path: ":memory:"})
fmt.Println(err == nil)
fmt.Println(dbsqlx.Default() != nil)
}
Output: true true
func NewSQLite ¶
NewSQLite opens a SQLite-backed *sqlx.DB and applies the standard PRAGMA settings (WAL, foreign keys, busy timeout, cache size). The parent directory of a file-based path is created automatically if absent.
Example ¶
ExampleNewSQLite shows how to open an in-memory SQLite database. In-memory databases are useful for tests and ephemeral data — all data is lost when the connection is closed.
package main
import (
"fmt"
"github.com/phcp-tech/common-library-golang/dbsqlx/sqlite"
)
func main() {
db, err := sqlite.NewSQLite(&sqlite.Config{Path: ":memory:"})
fmt.Println(err == nil)
fmt.Println(db != nil)
}
Output: true true
Types ¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package component provides sqlx SQLite lifecycle integration for bootstrap.
|
Package component provides sqlx SQLite lifecycle integration for bootstrap. |
|
Package vfs opens a SQLite database embedded inside a Go binary using modernc.org/sqlite/vfs and Go's embed.FS.
|
Package vfs opens a SQLite database embedded inside a Go binary using modernc.org/sqlite/vfs and Go's embed.FS. |