data

package
v1.64.0 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2025 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PostgresScheme = "postgres"
	MysqlScheme    = "mysql://"
	MemScheme      = "mem://"
	RedisScheme    = "redis://"
	NatsScheme     = "nats://"
)

Constants for database drivers.

Variables

This section is empty.

Functions

func ErrorIsNoRows

func ErrorIsNoRows(err error) bool

ErrorIsNoRows validate if supplied error is because of record missing in DB.

func StableSearch

func StableSearch[T any](
	ctx context.Context, workMan workerpool.Manager,
	query *SearchQuery, searchFunc func(ctx context.Context, query *SearchQuery) ([]T, error),
) (workerpool.JobResultPipe[[]T], error)

Types

type BaseModel

type BaseModel struct {
	ID          string `gorm:"type:varchar(50);primary_key"`
	CreatedAt   time.Time
	ModifiedAt  time.Time
	Version     uint           `gorm:"DEFAULT 0"`
	TenantID    string         `gorm:"type:varchar(50);index:,composite:base_tenancy"`
	PartitionID string         `gorm:"type:varchar(50);index:,composite:base_tenancy"`
	AccessID    string         `gorm:"type:varchar(50);index:,composite:base_tenancy"`
	DeletedAt   gorm.DeletedAt `sql:"index"`
}

BaseModel base table struct to be extended by other models.

func (*BaseModel) BeforeCreate

func (model *BaseModel) BeforeCreate(db *gorm.DB) error

func (*BaseModel) BeforeSave

func (model *BaseModel) BeforeSave(db *gorm.DB) error

BeforeSave Ensures we update a migrations time stamps.

func (*BaseModel) BeforeUpdate

func (model *BaseModel) BeforeUpdate(_ *gorm.DB) error

BeforeUpdate Updates time stamp every time we update status of a migration.

func (*BaseModel) CopyPartitionInfo

func (model *BaseModel) CopyPartitionInfo(parent *BaseModel)

func (*BaseModel) GenID

func (model *BaseModel) GenID(ctx context.Context)

GenID creates a new id for model if its not existent.

func (*BaseModel) GetID

func (model *BaseModel) GetID() string

func (*BaseModel) GetVersion

func (model *BaseModel) GetVersion() uint

func (*BaseModel) ValidXID

func (model *BaseModel) ValidXID(id string) bool

ValidXID Validates that the supplied string is an xid.

type BaseModelI

type BaseModelI interface {
	GetID() string
	GetVersion() uint
}

type DSN added in v1.63.3

type DSN string

A DSN for conveniently handling a URI connection string.

func (DSN) ChangePort added in v1.63.3

func (d DSN) ChangePort(newPort string) (DSN, error)

func (DSN) DelPath added in v1.63.3

func (d DSN) DelPath() DSN

func (DSN) ExtendPath added in v1.63.3

func (d DSN) ExtendPath(epath ...string) DSN

func (DSN) ExtendQuery added in v1.63.3

func (d DSN) ExtendQuery(key, value string) DSN

func (DSN) GetQuery added in v1.63.3

func (d DSN) GetQuery(key string) string

func (DSN) IsCache added in v1.63.3

func (d DSN) IsCache() bool

func (DSN) IsDB added in v1.63.3

func (d DSN) IsDB() bool

func (DSN) IsMem added in v1.63.3

func (d DSN) IsMem() bool

func (DSN) IsMySQL added in v1.63.3

func (d DSN) IsMySQL() bool

func (DSN) IsNats added in v1.63.3

func (d DSN) IsNats() bool

func (DSN) IsPostgres added in v1.63.3

func (d DSN) IsPostgres() bool

func (DSN) IsQueue added in v1.63.3

func (d DSN) IsQueue() bool

func (DSN) IsRedis added in v1.63.3

func (d DSN) IsRedis() bool

func (DSN) PrefixPath added in v1.63.3

func (d DSN) PrefixPath(prefix string) DSN

func (DSN) RemoveQuery added in v1.63.3

func (d DSN) RemoveQuery(key ...string) DSN

func (DSN) String added in v1.63.3

func (d DSN) String() string

func (DSN) SuffixPath added in v1.63.3

func (d DSN) SuffixPath(suffix string) DSN

func (DSN) ToArray added in v1.63.3

func (d DSN) ToArray() []DSN

func (DSN) ToURI added in v1.63.3

func (d DSN) ToURI() (*url.URL, error)

func (DSN) WithPassword added in v1.63.3

func (d DSN) WithPassword(password string) (DSN, error)

func (DSN) WithPath added in v1.63.3

func (d DSN) WithPath(path string) (DSN, error)

func (DSN) WithPathSuffix added in v1.63.3

func (d DSN) WithPathSuffix(suffix string) (DSN, error)

func (DSN) WithQuery added in v1.63.3

func (d DSN) WithQuery(query string) (DSN, error)

func (DSN) WithUser added in v1.63.3

func (d DSN) WithUser(user string) (DSN, error)

func (DSN) WithUserAndPassword added in v1.63.3

func (d DSN) WithUserAndPassword(userName, password string) (DSN, error)

type JSONMap added in v1.63.2

type JSONMap map[string]any

JSONMap is a GORM-compatible map[string]any that stores JSONB/JSON in a DB.

func (*JSONMap) Copy added in v1.63.2

func (m *JSONMap) Copy() JSONMap

Copy returns a deep copy of the JSONMap. Nested maps and slices are recursively copied so that the returned JSONMap can be modified without affecting the original.

func (*JSONMap) FromProtoStruct added in v1.63.2

func (m *JSONMap) FromProtoStruct(s *structpb.Struct) JSONMap

FromProtoStruct populates the JSONMap with data from a protocol buffer Struct. If the receiver is nil, a new JSONMap will be created and returned. If the input struct is nil, the receiver is returned unchanged. Returns the receiver (or a new JSONMap if receiver was nil) for method chaining.

func (*JSONMap) GetFloat added in v1.63.2

func (m *JSONMap) GetFloat(key string) float64

GetFloat retrieves a string value from the JSONMap by key. It returns the string and a boolean indicating if the value was found and is a string.

func (*JSONMap) GetString added in v1.63.2

func (m *JSONMap) GetString(key string) string

GetString retrieves a string value from the JSONMap by key. It returns the string and a boolean indicating if the value was found and is a string.

func (*JSONMap) GormDBDataType added in v1.63.2

func (m *JSONMap) GormDBDataType(db *gorm.DB, _ *schema.Field) string

GormDBDataType returns the dialect-specific database column type.

func (*JSONMap) GormDataType added in v1.63.2

func (m *JSONMap) GormDataType() string

GormDataType returns the common GORM data type.

func (*JSONMap) GormValue added in v1.63.2

func (m *JSONMap) GormValue(_ context.Context, db *gorm.DB) clause.Expr

GormValue optimizes how values are rendered in SQL for specific dialects.

func (*JSONMap) MarshalJSON added in v1.63.2

func (m *JSONMap) MarshalJSON() ([]byte, error)

MarshalJSON customizes the JSON encoding.

func (*JSONMap) Scan added in v1.63.2

func (m *JSONMap) Scan(value any) error

Scan implements the sql.Scanner interface for database deserialization.

func (*JSONMap) ToProtoStruct added in v1.63.2

func (m *JSONMap) ToProtoStruct() *structpb.Struct

ToProtoStruct converts a JSONMap into a structpb.Struct safely and efficiently.

func (*JSONMap) UnmarshalJSON added in v1.63.2

func (m *JSONMap) UnmarshalJSON(data []byte) error

UnmarshalJSON deserializes JSON into the map.

func (*JSONMap) Update added in v1.63.2

func (m *JSONMap) Update(update JSONMap) JSONMap

Update merges all key-value pairs from update into the receiver. If the receiver is nil, a new JSONMap is created. Keys in update overwrite existing keys in the receiver.

func (*JSONMap) Value added in v1.63.2

func (m *JSONMap) Value() (driver.Value, error)

Value implements the driver.Valuer interface for database serialization.

type Paginator

type Paginator struct {
	Offset int
	Limit  int

	BatchSize int
}

func (*Paginator) CanLoad

func (p *Paginator) CanLoad() bool

func (*Paginator) SetBatchSize

func (p *Paginator) SetBatchSize(batchSize int)

func (*Paginator) Stop

func (p *Paginator) Stop(loadedCount int) bool

type SearchQuery

type SearchQuery struct {
	ProfileID   string
	Query       string
	QueryFields map[string]string // We query with the value of query but use value as operator: {'id': ' = ?', 'name': ' LIKE ?', 'props': ' @@ plainto_tsquery(?)'}
	Fields      map[string]any

	Pagination *Paginator
}

func NewSearchQuery

func NewSearchQuery(query string,
	fields map[string]any,
	resultPage, resultCount int,
) *SearchQuery

type UnitMeasure added in v1.63.3

type UnitMeasure int64

func (*UnitMeasure) UnmarshalText added in v1.63.3

func (d *UnitMeasure) UnmarshalText(text []byte) error

Jump to

Keyboard shortcuts

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