types

package
v2.0.0-...-10e4721 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2024 License: MIT, MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Column

func Column(col string) columnExpression

Types

type Date

type Date struct {
	time.Time
}

func NewDate

func NewDate(year, month, day int) Date

NewDate is a constructor for Date and returns new Date.

func (Date) GormDBDataType

func (Date) GormDBDataType(db *gorm.DB, field *schema.Field) string

GormDBDataType returns gorm DB data type based on the current using database.

func (Date) GormDataType

func (Date) GormDataType() string

GormDataType returns gorm common data type. This type is used for the field's column type.

func (Date) MarshalJSON

func (t Date) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler to convert Time to json serialization.

func (*Date) Scan

func (t *Date) Scan(src any) error

Scan implements sql.Scanner interface and scans value into Time,

func (Date) String

func (t Date) String() string

String implements fmt.Stringer interface.

func (*Date) UnmarshalJSON

func (t *Date) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unmarshaler to deserialize json data.

func (Date) Value

func (t Date) Value() (driver.Value, error)

Value implements driver.Valuer interface and returns string format of Time.

type Int64Array

type Int64Array []string

func (Int64Array) GormDBDataType

func (Int64Array) GormDBDataType(db *gorm.DB, field *schema.Field) string

func (Int64Array) GormDataType

func (Int64Array) GormDataType() string

func (*Int64Array) Scan

func (o *Int64Array) Scan(src any) error

func (Int64Array) Value

func (o Int64Array) Value() (driver.Value, error)

type IntArray

type IntArray []string

func (IntArray) GormDBDataType

func (IntArray) GormDBDataType(db *gorm.DB, field *schema.Field) string

func (IntArray) GormDataType

func (IntArray) GormDataType() string

func (*IntArray) Scan

func (o *IntArray) Scan(src any) error

func (IntArray) Value

func (o IntArray) Value() (driver.Value, error)

type JSON

type JSON json.RawMessage

JSON defined JSON data type, need to implements driver.Valuer, sql.Scanner interface

func (JSON) GormDBDataType

func (JSON) GormDBDataType(db *gorm.DB, field *schema.Field) string

GormDBDataType gorm db data type

func (JSON) GormDataType

func (JSON) GormDataType() string

GormDataType gorm common data type

func (JSON) GormValue

func (js JSON) GormValue(ctx context.Context, db *gorm.DB) clause.Expr

func (JSON) MarshalJSON

func (j JSON) MarshalJSON() ([]byte, error)

MarshalJSON to output non base64 encoded []byte

func (*JSON) Scan

func (j *JSON) Scan(value any) error

Scan scan value into Jsonb, implements sql.Scanner interface

func (JSON) String

func (j JSON) String() string

func (*JSON) UnmarshalJSON

func (j *JSON) UnmarshalJSON(b []byte) error

UnmarshalJSON to deserialize []byte

func (JSON) Value

func (j JSON) Value() (driver.Value, error)

Value return json value, implement driver.Valuer interface

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

type JSONMap map[string]any

JSONMap defined JSON data type, need to implements driver.Valuer, sql.Scanner interface

func (JSONMap) GormDBDataType

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

GormDBDataType gorm db data type

func (JSONMap) GormDataType

func (m JSONMap) GormDataType() string

GormDataType gorm common data type

func (JSONMap) GormValue

func (jm JSONMap) GormValue(ctx context.Context, db *gorm.DB) clause.Expr

func (JSONMap) MarshalJSON

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

MarshalJSON to output non base64 encoded []byte

func (*JSONMap) Scan

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

Scan scan value into Jsonb, implements sql.Scanner interface

func (*JSONMap) UnmarshalJSON

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

UnmarshalJSON to deserialize []byte

func (JSONMap) Value

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

Value return json value, implement driver.Valuer interface

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 JSONQuery

func JSONQuery(column string) *JSONQueryExpression

JSONQuery query column as json

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 JSONSet

func JSONSet(column string) *JSONSetExpression

JSONSet update fields of json column

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 NewJSONSlice[T any](s []T) JSONSlice[T]

func (JSONSlice[T]) GormDBDataType

func (JSONSlice[T]) GormDBDataType(db *gorm.DB, field *schema.Field) string

GormDBDataType gorm db data type

func (JSONSlice[T]) GormDataType

func (JSONSlice[T]) GormDataType() string

GormDataType gorm common data type

func (JSONSlice[T]) GormValue

func (j JSONSlice[T]) GormValue(ctx context.Context, db *gorm.DB) clause.Expr

func (*JSONSlice[T]) Scan

func (j *JSONSlice[T]) Scan(value any) error

Scan scan value into JSONType[T], implements sql.Scanner interface

func (JSONSlice[T]) Value

func (j JSONSlice[T]) Value() (driver.Value, error)

Value return json value, implement driver.Valuer interface

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 NewJSONType[T any](data T) JSONType[T]

func (JSONType[T]) Data

func (j JSONType[T]) Data() T

Data return data with generic Type T

func (JSONType[T]) GormDBDataType

func (JSONType[T]) GormDBDataType(db *gorm.DB, field *schema.Field) string

GormDBDataType gorm db data type

func (JSONType[T]) GormDataType

func (JSONType[T]) GormDataType() string

GormDataType gorm common data type

func (JSONType[T]) GormValue

func (js JSONType[T]) GormValue(ctx context.Context, db *gorm.DB) clause.Expr

func (JSONType[T]) MarshalJSON

func (j JSONType[T]) MarshalJSON() ([]byte, error)

MarshalJSON to output non base64 encoded []byte

func (*JSONType[T]) Scan

func (j *JSONType[T]) Scan(value any) error

Scan scan value into JSONType[T], implements sql.Scanner interface

func (*JSONType[T]) UnmarshalJSON

func (j *JSONType[T]) UnmarshalJSON(b []byte) error

UnmarshalJSON to deserialize []byte

func (JSONType[T]) Value

func (j JSONType[T]) Value() (driver.Value, error)

Value return json value, implement driver.Valuer interface

type StringArray

type StringArray []string

func (StringArray) GormDBDataType

func (StringArray) GormDBDataType(db *gorm.DB, field *schema.Field) string

func (StringArray) GormDataType

func (StringArray) GormDataType() string

func (*StringArray) Scan

func (o *StringArray) Scan(src any) error

func (StringArray) Value

func (o StringArray) Value() (driver.Value, error)

type Time

type Time time.Duration

Time is time data type.

func NewTime

func NewTime(hour, min, sec, nsec int) Time

NewTime is a constructor for Time and returns new Time.

func (Time) GormDBDataType

func (Time) GormDBDataType(db *gorm.DB, field *schema.Field) string

GormDBDataType returns gorm DB data type based on the current using database.

func (Time) GormDataType

func (Time) GormDataType() string

GormDataType returns gorm common data type. This type is used for the field's column type.

func (Time) MarshalJSON

func (t Time) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler to convert Time to json serialization.

func (*Time) Scan

func (t *Time) Scan(src any) error

Scan implements sql.Scanner interface and scans value into Time,

func (Time) String

func (t Time) String() string

String implements fmt.Stringer interface.

func (*Time) UnmarshalJSON

func (t *Time) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unmarshaler to deserialize json data.

func (Time) Value

func (t Time) Value() (driver.Value, error)

Value implements driver.Valuer interface and returns string format of Time.

type URL

type URL url.URL

func (URL) GormDBDataType

func (URL) GormDBDataType(db *gorm.DB, field *schema.Field) string

func (URL) GormDataType

func (URL) GormDataType() string

func (URL) MarshalJSON

func (u URL) MarshalJSON() ([]byte, error)

func (*URL) Scan

func (u *URL) Scan(value any) error

func (*URL) String

func (u *URL) String() string

func (*URL) UnmarshalJSON

func (u *URL) UnmarshalJSON(data []byte) error

func (URL) Value

func (u URL) Value() (driver.Value, error)

Jump to

Keyboard shortcuts

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