Documentation
¶
Overview ¶
Package database provides database initialization, migration, and management utilities for the l-ui panel using GORM with SQLite or PostgreSQL.
Index ¶
- Constants
- func Checkpoint() error
- func CloseDB() error
- func Dialect() string
- func GetDB() *gorm.DB
- func GreatestExpr(a, b string) string
- func InitDB(dbPath string) error
- func IsNotFound(err error) bool
- func IsPostgres() bool
- func IsSQLiteDB(file io.ReaderAt) (bool, error)
- func JSONClientsFromInbound() string
- func JSONFieldText(expr, key string) string
- func MigrateData(srcPath, dstDSN string) error
- func ValidateSQLiteDB(dbPath string) error
Constants ¶
const ( DialectSQLite = "sqlite" DialectPostgres = "postgres" )
Variables ¶
This section is empty.
Functions ¶
func Checkpoint ¶
func Checkpoint() error
Checkpoint performs a WAL checkpoint on the SQLite database to ensure data consistency. No-op on PostgreSQL (WAL there is managed by the server).
func Dialect ¶
func Dialect() string
Dialect returns the active GORM dialect name, or "" if the DB is not open.
func GreatestExpr ¶
func InitDB ¶
InitDB sets up the database connection, migrates models, and runs seeders. When LUI_DB_TYPE=postgres, dbPath is ignored and LUI_DB_DSN is used instead.
func IsNotFound ¶
func IsPostgres ¶
func IsPostgres() bool
IsPostgres reports whether the active connection is a PostgreSQL backend.
func IsSQLiteDB ¶
IsSQLiteDB checks if the given file is a valid SQLite database by reading its signature.
func JSONClientsFromInbound ¶
func JSONClientsFromInbound() string
JSONClientsFromInbound returns the FROM clause that yields one row per element of inbounds.settings -> clients, with a column named `client.value` whose text fields can be read with JSONFieldText("client.value", "<key>").
func JSONFieldText ¶
func MigrateData ¶
MigrateData copies every row from the configured SQLite file at srcPath into a fresh PostgreSQL database described by dstDSN. The destination tables are (re)created with AutoMigrate before the copy. Source data is left untouched.
func ValidateSQLiteDB ¶
ValidateSQLiteDB opens the provided sqlite DB path with a throw-away connection and runs a PRAGMA integrity_check to ensure the file is structurally sound. It does not mutate global state or run migrations.
Types ¶
This section is empty.