Documentation
¶
Overview ¶
Package component provides sqlx SQLite lifecycle integration for bootstrap.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Component ¶
func Component() bootstrap.IComponent
Component wraps loadFromEnv as a bootstrap.IComponent. Init calls loadFromEnv; Close closes the default sqlx SQLite connection.
The SQLite path is read from env key db.sqlite.path during Init(). Typical values:
- "file:app.db?cache=shared" for file-based databases
- "file::memory:?cache=shared" for in-memory databases (tests)
Example ¶
ExampleComponent shows how Component() is used in a bootstrap registration chain. It reads the SQLite path from env key db.sqlite.path during Init():
"file:app.db?cache=shared" — file-based database "file::memory:?cache=shared" — in-memory (tests, ephemeral data)
SQLite is an embedded database — Init() never fails due to network issues. Schema setup (CREATE TABLE, migrations) should be registered as a PreReady step immediately after, using dbsqlx.Default() to reach the connection:
bootstrap.New().
Add(envComp.Component(...)).
Add(logComp.Component()).
Add(dbComp.Component()).
PreReady(func() error {
_, err := dbsqlx.Default().Exec(schemaSQL)
return err
}).
Run()
package main
import (
"fmt"
dbComp "github.com/phcp-tech/common-library-golang/dbsqlx/sqlite/component"
)
func main() {
c := dbComp.Component()
fmt.Println(c != nil)
}
Output: true
Types ¶
This section is empty.