Versions in this module Expand all Collapse all v0 v0.0.2 Aug 11, 2025 Changes in this version + func EagerLoadMany[T any, R any](ctx context.Context, kn *KintsNorm, parents []*T, getParentID func(*T) any, ...) error + func LazyLoadMany[R any](ctx context.Context, kn *KintsNorm, parentID any, childForeignKey string) ([]*R, error) + func QuoteIdentifier(identifier string) string + type AfterCreate interface + AfterCreate func(ctx context.Context) error + type AfterDelete interface + AfterDelete func(ctx context.Context, id any) error + type AfterPurgeTrashed interface + AfterPurgeTrashed func(ctx context.Context, affected int64) error + type AfterRestore interface + AfterRestore func(ctx context.Context, id any) error + type AfterSoftDelete interface + AfterSoftDelete func(ctx context.Context, id any) error + type AfterUpdate interface + AfterUpdate func(ctx context.Context) error + type AfterUpsert interface + AfterUpsert func(ctx context.Context) error + type BeforeCreate interface + BeforeCreate func(ctx context.Context) error + type BeforeDelete interface + BeforeDelete func(ctx context.Context, id any) error + type BeforePurgeTrashed interface + BeforePurgeTrashed func(ctx context.Context) error + type BeforeRestore interface + BeforeRestore func(ctx context.Context, id any) error + type BeforeSoftDelete interface + BeforeSoftDelete func(ctx context.Context, id any) error + type BeforeUpdate interface + BeforeUpdate func(ctx context.Context) error + type BeforeUpsert interface + BeforeUpsert func(ctx context.Context) error + type Cache interface + Get func(ctx context.Context, key string) ([]byte, bool, error) + Invalidate func(ctx context.Context, keys ...string) error + Set func(ctx context.Context, key string, value []byte, ttl time.Duration) error + type Condition struct + Args []any + Expr string + func And(conds ...Condition) Condition + func Between(col string, start any, end any) Condition + func DateRange(col string, from, to time.Time) Condition + func Eq(col string, v any) Condition + func Ge(col string, v any) Condition + func Gt(col string, v any) Condition + func In(col string, vals []any) Condition + func Le(col string, v any) Condition + func Lt(col string, v any) Condition + func Ne(col string, v any) Condition + func OnDate(col string, day time.Time) Condition + func Or(conds ...Condition) Condition + func RawCond(expr string, args ...any) Condition + type Config struct + ApplicationName string + CircuitBreakerEnabled bool + CircuitFailureThreshold int + CircuitHalfOpenMaxCalls int + CircuitOpenTimeout time.Duration + ConnectTimeout time.Duration + Database string + HealthCheckPeriod time.Duration + Host string + MaxConnIdleTime time.Duration + MaxConnLifetime time.Duration + MaxConnections int32 + MinConnections int32 + Password string + Port int + ReadOnlyConnString string + RetryAttempts int + RetryBackoff time.Duration + SSLMode string + StatementCacheCapacity int + Username string + func (c *Config) ConnString() string + type ErrorCode int + const ErrCodeConnection + const ErrCodeConstraint + const ErrCodeDuplicate + const ErrCodeInvalidCast + const ErrCodeInvalidColumn + const ErrCodeInvalidFunction + const ErrCodeMigration + const ErrCodeNotFound + const ErrCodeStringTooLong + const ErrCodeTransaction + const ErrCodeValidation + type ExpvarMetrics struct + func (ExpvarMetrics) CircuitStateChanged(state string) + func (ExpvarMetrics) ConnectionCount(active, idle int32) + func (ExpvarMetrics) ErrorCount(errorType string) + func (ExpvarMetrics) QueryDuration(duration time.Duration, _ string) + type Field struct + Key string + Value any + type KintsNorm struct + func New(config *Config, opts ...Option) (*KintsNorm, error) + func NewWithConnString(connString string, opts ...Option) (*KintsNorm, error) + func (kn *KintsNorm) AutoMigrate(models ...any) error + func (kn *KintsNorm) AutoMigrateWithOptions(ctx context.Context, opts migration.ApplyOptions, models ...any) error + func (kn *KintsNorm) Close() error + func (kn *KintsNorm) Health(ctx context.Context) error + func (kn *KintsNorm) MigrateDownDir(ctx context.Context, dir string, steps int) error + func (kn *KintsNorm) MigrateUpDir(ctx context.Context, dir string) error + func (kn *KintsNorm) Model(model any) *QueryBuilder + func (kn *KintsNorm) Pool() *pgxpool.Pool + func (kn *KintsNorm) Query() *QueryBuilder + func (kn *KintsNorm) QueryRead() *QueryBuilder + func (kn *KintsNorm) ReadPool() *pgxpool.Pool + func (kn *KintsNorm) SetManualMigrationOptions(opts migration.ManualOptions) + func (kn *KintsNorm) Tx() TxManager + type LogMode int + const LogDebug + const LogError + const LogInfo + const LogSilent + const LogWarn + type Logger interface + Debug func(msg string, fields ...Field) + Error func(msg string, fields ...Field) + Info func(msg string, fields ...Field) + Warn func(msg string, fields ...Field) + type Metrics interface + CircuitStateChanged func(state string) + ConnectionCount func(active, idle int32) + ErrorCount func(errorType string) + QueryDuration func(duration time.Duration, query string) + type NoopCache struct + func (NoopCache) Get(ctx context.Context, key string) ([]byte, bool, error) + func (NoopCache) Invalidate(ctx context.Context, keys ...string) error + func (NoopCache) Set(ctx context.Context, key string, value []byte, ttl time.Duration) error + type NoopLogger struct + func (NoopLogger) Debug(msg string, fields ...Field) + func (NoopLogger) Error(msg string, fields ...Field) + func (NoopLogger) Info(msg string, fields ...Field) + func (NoopLogger) Warn(msg string, fields ...Field) + type NoopMetrics struct + func (NoopMetrics) CircuitStateChanged(state string) + func (NoopMetrics) ConnectionCount(active, idle int32) + func (NoopMetrics) ErrorCount(errorType string) + func (NoopMetrics) QueryDuration(duration time.Duration, query string) + type ORMError struct + Args []any + Code ErrorCode + Internal error + Message string + Query string + func (e *ORMError) Error() string + type Option func(*options) + func WithCache(c Cache) Option + func WithLogContextFields(fn func(ctx context.Context) []Field) Option + func WithLogMode(mode LogMode) Option + func WithLogParameterMasking(mask bool) Option + func WithLogger(l Logger) Option + func WithMetrics(m Metrics) Option + func WithSlowQueryThreshold(threshold time.Duration) Option + type Page struct + Items []*T + Limit int + Offset int + Total int64 + type PageRequest struct + Limit int + Offset int + OrderBy string + type QueryBuilder struct + func (qb *QueryBuilder) After(column string, value any) *QueryBuilder + func (qb *QueryBuilder) Before(column string, value any) *QueryBuilder + func (qb *QueryBuilder) CrossJoin(table string) *QueryBuilder + func (qb *QueryBuilder) Debug() *QueryBuilder + func (qb *QueryBuilder) Delete(ctx context.Context) (int64, error) + func (qb *QueryBuilder) DoUpdateSet(setExpr string, args ...any) *QueryBuilder + func (qb *QueryBuilder) Exec(ctx context.Context) error + func (qb *QueryBuilder) ExecInsert(ctx context.Context, dest any) (int64, error) + func (qb *QueryBuilder) ExecUpdate(ctx context.Context, dest any) (int64, error) + func (qb *QueryBuilder) Find(ctx context.Context, dest any) error + func (qb *QueryBuilder) First(ctx context.Context, dest any) error + func (qb *QueryBuilder) FullJoin(table, on string) *QueryBuilder + func (qb *QueryBuilder) HardDelete() *QueryBuilder + func (qb *QueryBuilder) InnerJoin(table, on string) *QueryBuilder + func (qb *QueryBuilder) Insert(columns ...string) *QueryBuilder + func (qb *QueryBuilder) InsertStruct(ctx context.Context, entity any) (int64, error) + func (qb *QueryBuilder) Join(table, on string) *QueryBuilder + func (qb *QueryBuilder) Last(ctx context.Context, dest any) error + func (qb *QueryBuilder) LeftJoin(table, on string) *QueryBuilder + func (qb *QueryBuilder) Limit(n int) *QueryBuilder + func (qb *QueryBuilder) Model(model any) *QueryBuilder + func (qb *QueryBuilder) Offset(n int) *QueryBuilder + func (qb *QueryBuilder) OnConflict(cols ...string) *QueryBuilder + func (qb *QueryBuilder) OnlyTrashed() *QueryBuilder + func (qb *QueryBuilder) OrderBy(ob string) *QueryBuilder + func (qb *QueryBuilder) Raw(sql string, args ...any) *QueryBuilder + func (qb *QueryBuilder) RawNamed(sql string, namedArgs map[string]any) *QueryBuilder + func (qb *QueryBuilder) Returning(cols ...string) *QueryBuilder + func (qb *QueryBuilder) RightJoin(table, on string) *QueryBuilder + func (qb *QueryBuilder) Select(columns ...string) *QueryBuilder + func (qb *QueryBuilder) SelectQ(columns ...string) *QueryBuilder + func (qb *QueryBuilder) SelectQI(columns ...string) *QueryBuilder + func (qb *QueryBuilder) Set(setExpr string, args ...any) *QueryBuilder + func (qb *QueryBuilder) Table(name string) *QueryBuilder + func (qb *QueryBuilder) TableQ(name string) *QueryBuilder + func (qb *QueryBuilder) Unscoped() *QueryBuilder + func (qb *QueryBuilder) UpdateStructByPK(ctx context.Context, entity any, pkColumn string) (int64, error) + func (qb *QueryBuilder) UsePrimary() *QueryBuilder + func (qb *QueryBuilder) UseReadPool() *QueryBuilder + func (qb *QueryBuilder) Values(values ...any) *QueryBuilder + func (qb *QueryBuilder) ValuesRows(rows [][]any) *QueryBuilder + func (qb *QueryBuilder) Where(condition string, args ...any) *QueryBuilder + func (qb *QueryBuilder) WhereCond(c Condition) *QueryBuilder + func (qb *QueryBuilder) WhereNamed(condition string, namedArgs map[string]any) *QueryBuilder + func (qb *QueryBuilder) WithCacheKey(key string, ttl time.Duration) *QueryBuilder + func (qb *QueryBuilder) WithInvalidateKeys(keys ...string) *QueryBuilder + func (qb *QueryBuilder) WithTrashed() *QueryBuilder + type Repository interface + Count func(ctx context.Context, conditions ...Condition) (int64, error) + Create func(ctx context.Context, entity *T) error + CreateBatch func(ctx context.Context, entities []*T) error + CreateCopyFrom func(ctx context.Context, entities []*T, columns ...string) (int64, error) + Delete func(ctx context.Context, id any) error + Exists func(ctx context.Context, conditions ...Condition) (bool, error) + Find func(ctx context.Context, conditions ...Condition) ([]*T, error) + FindOne func(ctx context.Context, conditions ...Condition) (*T, error) + FindPage func(ctx context.Context, page PageRequest, conditions ...Condition) (Page[T], error) + GetByID func(ctx context.Context, id any) (*T, error) + OnlyTrashed func() Repository[T] + PurgeTrashed func(ctx context.Context) (int64, error) + Restore func(ctx context.Context, id any) error + SoftDelete func(ctx context.Context, id any) error + SoftDeleteAll func(ctx context.Context) (int64, error) + Update func(ctx context.Context, entity *T) error + UpdatePartial func(ctx context.Context, id any, fields map[string]any) error + Upsert func(ctx context.Context, entity *T, conflictCols []string, updateCols []string) error + WithTrashed func() Repository[T] + func NewRepositoryWithExecutor[T any](kn *KintsNorm, exec dbExecuter) Repository[T] + func NewRepository[T any](kn *KintsNorm) Repository[T] + type StdLogger struct + func (StdLogger) Debug(msg string, fields ...Field) + func (StdLogger) Error(msg string, fields ...Field) + func (StdLogger) Info(msg string, fields ...Field) + func (StdLogger) Warn(msg string, fields ...Field) + type Transaction interface + Commit func(ctx context.Context) error + Exec func() dbExecuter + Query func() *QueryBuilder + Repository func() Repository[map[string]any] + Rollback func(ctx context.Context) error + type TxManager interface + BeginTx func(ctx context.Context, opts *TxOptions) (Transaction, error) + WithTransaction func(ctx context.Context, fn func(tx Transaction) error) error + type TxOptions struct v0.0.1 Aug 10, 2025