stardb/errors.go

65 lines
2.8 KiB
Go
Raw Permalink Normal View History

package stardb
import (
"errors"
"fmt"
)
var (
// Lifecycle errors.
ErrDBNotInitialized = errors.New("database is not initialized; call Open or SetDB first")
ErrTxNotInitialized = errors.New("transaction is not initialized")
ErrStmtNotInitialized = errors.New("statement is not initialized")
ErrStmtDBNotInitialized = errors.New("statement database context is not initialized")
// SQL input errors.
ErrQueryEmpty = errors.New("query string cannot be empty")
ErrScanStopped = errors.New("scan stopped by callback")
ErrScanFuncNil = errors.New("scan callback cannot be nil")
ErrScanORMFuncNil = errors.New("scan orm callback cannot be nil")
// Mapping and schema errors.
ErrColumnNotFound = errors.New("column not found")
ErrFieldNotFound = errors.New("field not found")
ErrRowIndexOutOfRange = errors.New("row index out of range")
// Target validation errors.
ErrTargetNil = errors.New("target cannot be nil")
ErrTargetsNil = errors.New("targets cannot be nil")
ErrTargetNotPointer = errors.New("target must be a pointer")
ErrTargetPointerNil = errors.New("target pointer cannot be nil")
ErrTargetsPointerNil = errors.New("targets pointer is nil")
ErrTargetNotStruct = errors.New("target is not a struct")
ErrTargetNotWritable = errors.New("target is not writable")
ErrPointerTargetNil = errors.New("pointer target is nil")
// SQL builder errors.
ErrTableNameEmpty = errors.New("table name cannot be empty")
ErrPrimaryKeyRequired = errors.New("at least one primary key is required")
ErrPrimaryKeyEmpty = errors.New("primary key cannot be empty")
ErrNoInsertColumns = errors.New("no columns to insert")
ErrNoInsertValues = errors.New("no values to insert")
ErrBatchInsertMaxParamsTooLow = errors.New("batch insert max params is lower than column count")
ErrNoUpdateFields = errors.New("no fields to update after excluding primary keys")
ErrBatchRowValueCountMismatch = errors.New("row values count does not match columns")
ErrStructsNil = errors.New("structs cannot be nil")
ErrStructsPointerNil = errors.New("structs pointer is nil")
ErrStructsNotSlice = errors.New("structs must be a slice or array")
ErrNoStructsToInsert = errors.New("no structs to insert")
// Transaction helper errors.
ErrTxFuncNil = errors.New("transaction callback cannot be nil")
)
func wrapColumnNotFound(column string) error {
return fmt.Errorf("%w: %s", ErrColumnNotFound, column)
}
func wrapFieldNotFound(field string) error {
return fmt.Errorf("%w: %s", ErrFieldNotFound, field)
}
func wrapBatchRowValueCountMismatch(rowIndex, got, expected int) error {
return fmt.Errorf("%w: row %d has %d values, expected %d", ErrBatchRowValueCountMismatch, rowIndex, got, expected)
}