Documentation
¶
Index ¶
- Constants
- func Column(col string) columnExpression
- type Archive
- type ConcurrentMapShared
- type CreatedAt
- type Date
- func (Date) GormDBDataType(db *gorm.DB, field *schema.Field) string
- func (Date) GormDataType() string
- func (t Date) MarshalJSON() ([]byte, error)
- func (t *Date) Scan(src any) error
- func (t Date) String() string
- func (t *Date) UnmarshalJSON(data []byte) error
- func (t Date) Value() (driver.Value, error)
- type Dictionary
- func (dict *Dictionary[K, V]) Add(key K, value V)
- func (dict *Dictionary[K, V]) Delete(key K)
- func (dict *Dictionary[K, V]) FindByKey(key K) (int, *KeyValue[K, V])
- func (dict *Dictionary[K, V]) FindByValue(value V) (int, *KeyValue[K, V])
- func (dict *Dictionary[K, V]) FindByValueFunc(value V, equal func(a, b V) bool) (int, *KeyValue[K, V])
- func (*Dictionary[K, V]) GormDBDataType(db *gorm.DB, field *schema.Field) string
- func (*Dictionary[K, V]) GormDataType() string
- func (dict *Dictionary[K, V]) GormValue(ctx context.Context, db *gorm.DB) clause.Expr
- func (dict *Dictionary[K, V]) JSON() ([]byte, error)
- func (dict *Dictionary[K, V]) MarshalJSON() ([]byte, error)
- func (dict *Dictionary[K, V]) Replace(index int, key K, value V) bool
- func (dict *Dictionary[K, V]) Scan(val any) error
- func (dict *Dictionary[K, V]) String() string
- func (dict *Dictionary[K, V]) UnmarshalJSON(b []byte) error
- func (dict *Dictionary[K, V]) Value() (driver.Value, error)
- type Int64Array
- type IntArray
- type JSON
- func (JSON) GormDBDataType(db *gorm.DB, field *schema.Field) string
- func (JSON) GormDataType() string
- func (js JSON) GormValue(ctx context.Context, db *gorm.DB) clause.Expr
- func (j JSON) MarshalJSON() ([]byte, error)
- func (j *JSON) Scan(value any) error
- func (j JSON) String() string
- func (j *JSON) UnmarshalJSON(b []byte) error
- func (j JSON) Value() (driver.Value, error)
- type JSONArrayExpression
- type JSONMap
- func (JSONMap) GormDBDataType(db *gorm.DB, field *schema.Field) string
- func (m JSONMap) GormDataType() string
- func (jm JSONMap) GormValue(ctx context.Context, db *gorm.DB) clause.Expr
- func (m JSONMap) MarshalJSON() ([]byte, error)
- func (m *JSONMap) Scan(val any) error
- func (m *JSONMap) UnmarshalJSON(b []byte) error
- func (m JSONMap) Value() (driver.Value, error)
- type JSONOverlapsExpression
- type JSONQueryExpression
- func (jsonQuery *JSONQueryExpression) Build(builder clause.Builder)
- func (jsonQuery *JSONQueryExpression) Equals(value any, keys ...string) *JSONQueryExpression
- func (jsonQuery *JSONQueryExpression) Extract(path string) *JSONQueryExpression
- func (jsonQuery *JSONQueryExpression) HasKey(keys ...string) *JSONQueryExpression
- type JSONSetExpression
- type JSONSlice
- type JSONType
- func (j JSONType[T]) Data() T
- func (JSONType[T]) GormDBDataType(db *gorm.DB, field *schema.Field) string
- func (JSONType[T]) GormDataType() string
- func (js JSONType[T]) GormValue(ctx context.Context, db *gorm.DB) clause.Expr
- func (j JSONType[T]) MarshalJSON() ([]byte, error)
- func (j *JSONType[T]) Scan(value any) error
- func (j *JSONType[T]) UnmarshalJSON(b []byte) error
- func (j JSONType[T]) Value() (driver.Value, error)
- type KeyValue
- type Map
- func (m Map[K, V]) Exists(key K) bool
- func (m Map[K, V]) Get(key K) (V, bool)
- func (m Map[K, V]) GetShard(key K) *ConcurrentMapShared[K, V]
- func (m *Map[K, V]) GormDBDataType(db *gorm.DB, field *schema.Field) string
- func (m Map[K, V]) Iterate() ...
- func (m Map[K, V]) MSet(data map[K]V)
- func (m Map[K, V]) Range(f func(key K, value V))
- func (m Map[K, V]) Remove(key K)
- func (m Map[K, V]) RemoveCb(key K, cb RemoveCb[K, V]) bool
- func (m Map[K, V]) Set(key K, value V)
- func (m Map[K, V]) SetIfAbsent(key K, value V) bool
- func (m Map[K, V]) Upsert(key K, value V, cb UpsertCb[V]) (res V)
- type RemoveCb
- type SoftDelete
- type StringArray
- type Stringer
- type Time
- func (Time) GormDBDataType(db *gorm.DB, field *schema.Field) string
- func (Time) GormDataType() string
- func (t Time) MarshalJSON() ([]byte, error)
- func (t *Time) Scan(src any) error
- func (t Time) String() string
- func (t *Time) UnmarshalJSON(data []byte) error
- func (t Time) Value() (driver.Value, error)
- type URL
- type UUID
- func (u UUID) Equals(other UUID) bool
- func (UUID) GormDBDataType(db *gorm.DB, field *schema.Field) string
- func (UUID) GormDataType() string
- func (u UUID) IsEmpty() bool
- func (u *UUID) IsEmptyPtr() bool
- func (u UUID) IsNil() bool
- func (u *UUID) IsNilPtr() bool
- func (u UUID) Length() int
- func (u *UUID) Scan(value interface{}) error
- func (u UUID) String() string
- func (u UUID) Value() (driver.Value, error)
- type UpdatedAt
- type UpsertCb
Constants ¶
const SHARD_COUNT = 32
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Archive ¶
type Archive struct {
Archive bool `gorm:"column:archive" json:"archive"`
}
func (*Archive) SetArchive ¶
type ConcurrentMapShared ¶
type ConcurrentMapShared[K comparable, V any] struct { // contains filtered or unexported fields }
ConcurrentMapShared represents a single shard of the ConcurrentMap. It contains a map guarded by a RWMutex for safe concurrent access.
type CreatedAt ¶
type CreatedAt struct {
CreatedAt time.Time `gorm:"column:created_at;default:CURRENT_TIMESTAMP()" json:"created_at"`
}
CreatedAt represents the timestamp of when an entity or object was created. It uses GORM's autoCreateTime for automatic timestamp management.
type Date ¶
func (Date) GormDBDataType ¶
GormDBDataType returns gorm DB data type based on the current using database.
func (Date) GormDataType ¶
GormDataType returns gorm common data type. This type is used for the field's column type.
func (Date) MarshalJSON ¶
MarshalJSON implements json.Marshaler to convert Time to json serialization.
func (*Date) UnmarshalJSON ¶
UnmarshalJSON implements json.Unmarshaler to deserialize json data.
type Dictionary ¶
type Dictionary[K comparable, V any] struct { // contains filtered or unexported fields }
Dictionary represents an array of KeyValue pairs with thread-safety
func (*Dictionary[K, V]) Add ¶
func (dict *Dictionary[K, V]) Add(key K, value V)
Add adds a new key-value pair to the dictionary (Thread-Safe)
func (*Dictionary[K, V]) Delete ¶
func (dict *Dictionary[K, V]) Delete(key K)
Delete removes a key-value pair by key (Thread-Safe)
func (*Dictionary[K, V]) FindByKey ¶
func (dict *Dictionary[K, V]) FindByKey(key K) (int, *KeyValue[K, V])
FindByKey finds a key and returns its index and pointer to the KeyValue (Thread-Safe)
func (*Dictionary[K, V]) FindByValue ¶
func (dict *Dictionary[K, V]) FindByValue(value V) (int, *KeyValue[K, V])
FindByValue finds a value and returns its index and pointer to the KeyValue (Thread-Safe)
func (*Dictionary[K, V]) FindByValueFunc ¶
func (dict *Dictionary[K, V]) FindByValueFunc(value V, equal func(a, b V) bool) (int, *KeyValue[K, V])
FindByValueFunc finds a value and returns its index and pointer to the KeyValue (Thread-Safe)
func (*Dictionary[K, V]) GormDBDataType ¶
GormDBDataType specifies the database data type for Dictionary
func (*Dictionary[K, V]) GormDataType ¶
func (*Dictionary[K, V]) GormDataType() string
GormDataType specifies the GORM data type for Dictionary
func (*Dictionary[K, V]) JSON ¶
func (dict *Dictionary[K, V]) JSON() ([]byte, error)
JSON serializes the dictionary into JSON format (Thread-Safe)
func (*Dictionary[K, V]) MarshalJSON ¶
func (dict *Dictionary[K, V]) MarshalJSON() ([]byte, error)
MarshalJSON serializes the dictionary to JSON (Thread-Safe)
func (*Dictionary[K, V]) Replace ¶
func (dict *Dictionary[K, V]) Replace(index int, key K, value V) bool
Replace replaces a key-value pair at a specific index (Thread-Safe)
func (*Dictionary[K, V]) Scan ¶
func (dict *Dictionary[K, V]) Scan(val any) error
Scan scans value into Dictionary, implements sql.Scanner interface
func (*Dictionary[K, V]) String ¶
func (dict *Dictionary[K, V]) String() string
String displays all key-value pairs in the dictionary (for debugging)
func (*Dictionary[K, V]) UnmarshalJSON ¶
func (dict *Dictionary[K, V]) UnmarshalJSON(b []byte) error
UnmarshalJSON deserializes JSON into the dictionary (Thread-Safe)
type Int64Array ¶
type Int64Array []string
func (Int64Array) GormDBDataType ¶
func (Int64Array) GormDataType ¶
func (Int64Array) GormDataType() string
func (*Int64Array) Scan ¶
func (o *Int64Array) Scan(src any) error
type IntArray ¶
type IntArray []string
func (IntArray) GormDBDataType ¶
func (IntArray) GormDataType ¶
type JSON ¶
type JSON json.RawMessage
JSON defined JSON data type, need to implements driver.Valuer, sql.Scanner interface
func (JSON) GormDBDataType ¶
GormDBDataType gorm db data type
func (JSON) MarshalJSON ¶
MarshalJSON to output non base64 encoded []byte
func (*JSON) UnmarshalJSON ¶
UnmarshalJSON to deserialize []byte
type JSONArrayExpression ¶
type JSONArrayExpression struct {
// contains filtered or unexported fields
}
func JSONArrayQuery ¶
func JSONArrayQuery(column string) *JSONArrayExpression
func (*JSONArrayExpression) Build ¶
func (json *JSONArrayExpression) Build(builder clause.Builder)
Build implements clause.Expression
func (*JSONArrayExpression) Contains ¶
func (json *JSONArrayExpression) Contains(value any) *JSONArrayExpression
type JSONMap ¶
JSONMap defined JSON data type, need to implements driver.Valuer, sql.Scanner interface
func (JSONMap) GormDBDataType ¶
GormDBDataType gorm db data type
func (JSONMap) GormDataType ¶
GormDataType gorm common data type
func (JSONMap) MarshalJSON ¶
MarshalJSON to output non base64 encoded []byte
func (*JSONMap) UnmarshalJSON ¶
UnmarshalJSON to deserialize []byte
type JSONOverlapsExpression ¶
type JSONOverlapsExpression struct {
// contains filtered or unexported fields
}
JSONOverlapsExpression JSON_OVERLAPS expression, implements clause.Expression interface to use as querier
func JSONOverlaps ¶
func JSONOverlaps(column clause.Expression, value string) *JSONOverlapsExpression
JSONOverlaps query column as json
func (*JSONOverlapsExpression) Build ¶
func (json *JSONOverlapsExpression) Build(builder clause.Builder)
Build implements clause.Expression only mysql support JSON_OVERLAPS
type JSONQueryExpression ¶
type JSONQueryExpression struct {
// contains filtered or unexported fields
}
JSONQueryExpression json query expression, implements clause.Expression interface to use as querier
func (*JSONQueryExpression) Build ¶
func (jsonQuery *JSONQueryExpression) Build(builder clause.Builder)
Build implements clause.Expression
func (*JSONQueryExpression) Equals ¶
func (jsonQuery *JSONQueryExpression) Equals(value any, keys ...string) *JSONQueryExpression
Keys returns clause.Expression
func (*JSONQueryExpression) Extract ¶
func (jsonQuery *JSONQueryExpression) Extract(path string) *JSONQueryExpression
Extract extract json with path
func (*JSONQueryExpression) HasKey ¶
func (jsonQuery *JSONQueryExpression) HasKey(keys ...string) *JSONQueryExpression
HasKey returns clause.Expression
type JSONSetExpression ¶
type JSONSetExpression struct {
// contains filtered or unexported fields
}
JSONSetExpression json set expression, implements clause.Expression interface to use as updater
func (*JSONSetExpression) Build ¶
func (jsonSet *JSONSetExpression) Build(builder clause.Builder)
Build implements clause.Expression support mysql, sqlite and postgres
func (*JSONSetExpression) Set ¶
func (jsonSet *JSONSetExpression) Set(path string, value any) *JSONSetExpression
Set return clause.Expression.
{ "age": 20, "name": "json-1", "orgs": {"orga": "orgv"}, "tags": ["tag1", "tag2"] } // In MySQL/SQLite, path is `age`, `name`, `orgs.orga`, `tags[0]`, `tags[1]`. DB.UpdateColumn("attr", JSONSet("attr").Set("orgs.orga", 42)) // In PostgreSQL, path is `{age}`, `{name}`, `{orgs,orga}`, `{tags, 0}`, `{tags, 1}`. DB.UpdateColumn("attr", JSONSet("attr").Set("{orgs, orga}", "bar"))
type JSONSlice ¶
type JSONSlice[T any] []T
JSONSlice give a generic data type for json encoded slice data.
func NewJSONSlice ¶
func (JSONSlice[T]) GormDBDataType ¶
GormDBDataType gorm db data type
func (JSONSlice[T]) GormDataType ¶
GormDataType gorm common data type
type JSONType ¶
type JSONType[T any] struct { // contains filtered or unexported fields }
JSONType give a generic data type for json encoded data.
func NewJSONType ¶
func (JSONType[T]) GormDBDataType ¶
GormDBDataType gorm db data type
func (JSONType[T]) GormDataType ¶
GormDataType gorm common data type
func (JSONType[T]) MarshalJSON ¶
MarshalJSON to output non base64 encoded []byte
func (*JSONType[T]) UnmarshalJSON ¶
UnmarshalJSON to deserialize []byte
type KeyValue ¶
type KeyValue[K comparable, V any] struct { Key K `json:"key"` Value V `json:"value"` }
KeyValue represents a key-value pair with generic types
type Map ¶
type Map[K comparable, V any] struct { // contains filtered or unexported fields }
Map represents a thread-safe map using sharded storage. It divides the map into multiple shards to reduce lock contention and improve performance.
func NewMapWithCustomShardingFunction ¶
func NewMapWithCustomShardingFunction[K comparable, V any](sharding func(key K) uint32) Map[K, V]
NewMapWithCustomShardingFunction creates a new Map with a user-defined sharding function.
func NewStringerMap ¶
NewStringerMap creates a new Map with custom Stringer keys and a sharding function.
func (Map[K, V]) GetShard ¶
func (m Map[K, V]) GetShard(key K) *ConcurrentMapShared[K, V]
GetShard returns the shard corresponding to the given key.
func (*Map[K, V]) GormDBDataType ¶
GormDBDataType defines how GORM should handle the type in different databases.
func (Map[K, V]) Iterate ¶
func (m Map[K, V]) Iterate() <-chan struct { Key K Value V }
Iterate returns a channel to iterate over all key-value pairs in the map.
func (Map[K, V]) MSet ¶
func (m Map[K, V]) MSet(data map[K]V)
MSet sets multiple key-value pairs in the map concurrently.
func (Map[K, V]) Range ¶
func (m Map[K, V]) Range(f func(key K, value V))
Range iterates over all key-value pairs and applies the callback function to each pair.
func (Map[K, V]) Remove ¶
func (m Map[K, V]) Remove(key K)
Remove deletes a key-value pair from the map.
func (Map[K, V]) RemoveCb ¶
RemoveCb removes a key-value pair if the callback condition returns true.
func (Map[K, V]) Set ¶
func (m Map[K, V]) Set(key K, value V)
Set inserts or updates a value in the map under the specified key.
func (Map[K, V]) SetIfAbsent ¶
SetIfAbsent sets a value in the map only if the key does not already exist.
type SoftDelete ¶
type SoftDelete struct { Deleted bool `gorm:"column:deleted;default:0;index" json:"deleted"` DeletedAt *time.Time `gorm:"column:deleted_at;nullable" json:"deleted_at"` }
SoftDelete provides soft delete functionality in GORM. It includes a `Deleted` flag and a `DeletedAt` timestamp.
func (*SoftDelete) Delete ¶
func (o *SoftDelete) Delete()
Delete set the Deleted status and the DeletedAt timestamp.
func (*SoftDelete) IsDeleted ¶
func (o *SoftDelete) IsDeleted() bool
IsDeleted checks if the entity has been marked as deleted. Returns true if the `Deleted` field is set to true.
func (*SoftDelete) Restore ¶
func (o *SoftDelete) Restore()
Restore resets the Deleted status and clears the DeletedAt timestamp.
func (*SoftDelete) SetDeleted ¶
func (o *SoftDelete) SetDeleted(v bool)
SetDeleted updates the `Deleted` and `DeletedAt` fields of the SoftDelete object. If `v` is true, it sets `Deleted` to true and `DeletedAt` to the current time. If `v` is false, it resets `Deleted` to false and clears `DeletedAt`.
type StringArray ¶
type StringArray []string
func (StringArray) GormDBDataType ¶
func (StringArray) GormDataType ¶
func (StringArray) GormDataType() string
func (*StringArray) Scan ¶
func (o *StringArray) Scan(src any) error
type Stringer ¶
type Stringer interface { fmt.Stringer comparable }
Stringer is an interface that combines fmt.Stringer and comparable. It ensures that the type can be used both as a string and as a map key.
type Time ¶
Time is time data type.
func (Time) GormDBDataType ¶
GormDBDataType returns gorm DB data type based on the current using database.
func (Time) GormDataType ¶
GormDataType returns gorm common data type. This type is used for the field's column type.
func (Time) MarshalJSON ¶
MarshalJSON implements json.Marshaler to convert Time to json serialization.
func (*Time) UnmarshalJSON ¶
UnmarshalJSON implements json.Unmarshaler to deserialize json data.
type UUID ¶
func NewUUID ¶
func NewUUID() UUID
NewUUID generates a UUID version 4, panics on generation failure.
func NewUUIDv1 ¶
func NewUUIDv1() UUID
NewUUIDv1 generates a UUID version 1, panics on generation failure.
func NewUUIDv4 ¶
func NewUUIDv4() UUID
NewUUIDv4 generates a UUID version 4, panics on generation failure.
func (UUID) GormDBDataType ¶
GormDBDataType gorm db data type.
func (*UUID) IsEmptyPtr ¶
IsEmptyPtr returns true if caller UUID ptr is nil or it's value is empty.