Documentation
¶
Overview ¶
Package liborm provides ORM-based query execution using Gorm.
Index ¶
- Constants
- func GetQuery[R any](query string, core OrmInterface, args ...any) ([]R, error)
- func Query[R any](command libQuery.CommandInterface, core OrmInterface, args ...any) ([]R, error)
- func QueryToStruct[Target any](db *gorm.DB, querySQL string, args ...any) ([]Target, error)
- func SetVariable(_ context.Context, tx *gorm.DB, command, key, value string) error
- type ContextKey
- type OrmInterface
- type OrmModel
Constants ¶
const ( // App is the context key for the application/program identifier in audit trail variables. App = "request.APP" // User is the context key for the user identifier in audit trail variables. User = "request.USER" // Module is the context key for the module name in audit trail variables. Module = "request.MODULE" // Method is the context key for the method name in audit trail variables. Method = "request.METHOD" // SetCommandError is the error description format for SetTrxVariable failures. SetCommandError = "error in Dml->SetTrxVariable(%s,%s,%s)" // ErrorExecuteDML is the error code for DML execution failures. ErrorExecuteDML = "ERROR_EXECUTE_DML" // OracleSetVariableCommand is the SQL command for setting audit trail variables in Oracle. OracleSetVariableCommand = `--sql BEGIN AUDIT_TRAIL.SET_MODIF_ARGS(:1, :2); END;` // PostgresSetVariableCommand is the SQL command for setting audit trail variables in PostgreSQL. PostgresSetVariableCommand = "SELECT set_config($1,$2,true);" // MySQLSetVariableCommand is the SQL command format for setting audit trail variables in MySQL. MySQLSetVariableCommand = "SET @%s = '%s';" // SQLiteSetVariableCommand is the SQL command format for setting audit trail variables in SQLite. SQLiteSetVariableCommand = "PRAGMA %s = '%s';" )
Variables ¶
This section is empty.
Functions ¶
func GetQuery ¶
func GetQuery[R any](query string, core OrmInterface, args ...any) ([]R, error)
GetQuery executes a raw SQL query and returns the result rows, returning NoDataFound error if empty.
func Query ¶
func Query[R any](command libQuery.CommandInterface, core OrmInterface, args ...any) ([]R, error)
Query executes a command interface query and returns result rows, handling single vs all result modes.
func QueryToStruct ¶
QueryToStruct executes a raw SQL query and scans the result rows into a slice of Target.
Types ¶
type ContextKey ¶
type ContextKey string
ContextKey is the type used for context keys in ORM transaction variables.
type OrmInterface ¶
OrmInterface defines the interface for ORM-based database access with mode and DB handle.
type OrmModel ¶
type OrmModel struct {
DB *gorm.DB
ProgramName string
ModuleName string
SetVariable string
Mode libQuery.DBMode
}
OrmModel holds the Gorm DB connection, program/module names, and DML configuration.
func Init ¶
func Init( DB *gorm.DB, ProgramName string, ModuleName string, mode libQuery.DBMode) (*OrmModel, error)
Init creates and returns an OrmModel configured for the given database mode.
func (OrmModel) Dml ¶
func (m OrmModel) Dml(ctx context.Context, moduleName, methodName, command string, args ...any) (int64, error)
Dml executes a DML command within a transaction with audit trail variables set, returning rows affected.