database

package
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 6, 2026 License: GPL-3.0 Imports: 25 Imported by: 0

Documentation

Overview

Package database provides database initialization, migration, and management utilities for the l-ui panel using GORM with SQLite or PostgreSQL.

Index

Constants

View Source
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 CloseDB

func CloseDB() error

CloseDB closes the database connection if it exists.

func Dialect

func Dialect() string

Dialect returns the active GORM dialect name, or "" if the DB is not open.

func GetDB

func GetDB() *gorm.DB

GetDB returns the global GORM database instance.

func GreatestExpr

func GreatestExpr(a, b string) string

func InitDB

func InitDB(dbPath string) error

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 IsNotFound(err error) bool

func IsPostgres

func IsPostgres() bool

IsPostgres reports whether the active connection is a PostgreSQL backend.

func IsSQLiteDB

func IsSQLiteDB(file io.ReaderAt) (bool, error)

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 JSONFieldText(expr, key string) string

func MigrateData

func MigrateData(srcPath, dstDSN string) error

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

func ValidateSQLiteDB(dbPath string) error

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.

Directories

Path Synopsis
Package model defines the database models and data structures used by the l-ui panel.
Package model defines the database models and data structures used by the l-ui panel.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL