* feature extend readthrough for cache module (#5116) * feature 增加readthrough * feature: add write though for cache mode (#5117) * feature: add writethough for cache mode * feature add singleflight cache (#5119) * build(deps): bump go.opentelemetry.io/otel/trace from 1.8.0 to 1.11.2 Bumps [go.opentelemetry.io/otel/trace](https://github.com/open-telemetry/opentelemetry-go) from 1.8.0 to 1.11.2. - [Release notes](https://github.com/open-telemetry/opentelemetry-go/releases) - [Changelog](https://github.com/open-telemetry/opentelemetry-go/blob/main/CHANGELOG.md) - [Commits](https://github.com/open-telemetry/opentelemetry-go/compare/v1.8.0...v1.11.2) --- updated-dependencies: - dependency-name: go.opentelemetry.io/otel/trace dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> * fix 5129: must set formatter after init the logger * remove beego.vip * build(deps): bump actions/stale from 5 to 7 Bumps [actions/stale](https://github.com/actions/stale) from 5 to 7. - [Release notes](https://github.com/actions/stale/releases) - [Changelog](https://github.com/actions/stale/blob/main/CHANGELOG.md) - [Commits](https://github.com/actions/stale/compare/v5...v7) --- updated-dependencies: - dependency-name: actions/stale dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <support@github.com> * fix 5079: only log msg when the channel is not closed (#5132) * optimize test * upgrade otel dependencies to v1.11.2 * format code * Bloom filter cache (#5126) * feature: add bloom filter cache * feature upload remove all temp file * bugfix Controller SaveToFile remove all temp file * rft: motify BeeLogger signalChan (#5139) * add non-block write log in asynchronous mode (#5150) * add non-block write log in asynchronous mode --------- Co-authored-by: chenhaokun <chenhaokun@itiger.com> * fix the docsite URL (#5173) * Unified gopkg.in/yaml version to v2 (#5169) * Unified gopkg.in/yaml version to v2 and go mod tidy * update CHANGELOG * bugfix: protect field access with lock to avoid possible data race (#5211) * fix some comments (#5194) Signed-off-by: cui fliter <imcusg@gmail.com> * build(deps): bump github.com/prometheus/client_golang (#5213) Bumps [github.com/prometheus/client_golang](https://github.com/prometheus/client_golang) from 1.14.0 to 1.15.1. - [Release notes](https://github.com/prometheus/client_golang/releases) - [Changelog](https://github.com/prometheus/client_golang/blob/main/CHANGELOG.md) - [Commits](https://github.com/prometheus/client_golang/compare/v1.14.0...v1.15.1) --- updated-dependencies: - dependency-name: github.com/prometheus/client_golang dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * build(deps): bump go.etcd.io/etcd/client/v3 from 3.5.4 to 3.5.9 (#5209) Bumps [go.etcd.io/etcd/client/v3](https://github.com/etcd-io/etcd) from 3.5.4 to 3.5.9. - [Release notes](https://github.com/etcd-io/etcd/releases) - [Commits](https://github.com/etcd-io/etcd/compare/v3.5.4...v3.5.9) --- updated-dependencies: - dependency-name: go.etcd.io/etcd/client/v3 dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * cache: fix typo and optimize the naming * Release 2.1.0 change log * bugfix: beegoAppConfig String and Strings function has bug * httplib: fix unstable test, do not use httplib.org * chore: pkg imported more than once * chore: fmt modify * chore: Use github.com/go-kit/log * chore: unnecessary use of fmt.Sprintf * fix: golangci-lint error * orm: refactor ORM introducing internal/models pkg * remove adapter package * build(deps): bump github.com/bits-and-blooms/bloom/v3 Bumps [github.com/bits-and-blooms/bloom/v3](https://github.com/bits-and-blooms/bloom) from 3.3.1 to 3.5.0. - [Release notes](https://github.com/bits-and-blooms/bloom/releases) - [Commits](https://github.com/bits-and-blooms/bloom/compare/v3.3.1...v3.5.0) --- updated-dependencies: - dependency-name: github.com/bits-and-blooms/bloom/v3 dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> * feat: add write-delete cache mode * fix: unnecessary assignment to the blank identifier * fix: add change into .CHANGELOG file * build(deps): bump golang.org/x/sync from 0.1.0 to 0.3.0 Bumps [golang.org/x/sync](https://github.com/golang/sync) from 0.1.0 to 0.3.0. - [Commits](https://github.com/golang/sync/compare/v0.1.0...v0.3.0) --- updated-dependencies: - dependency-name: golang.org/x/sync dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> * build(deps): bump golang.org/x/crypto Bumps [golang.org/x/crypto](https://github.com/golang/crypto) from 0.0.0-20220315160706-3147a52a75dd to 0.10.0. - [Commits](https://github.com/golang/crypto/commits/v0.10.0) --- updated-dependencies: - dependency-name: golang.org/x/crypto dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> * remove golang--lint-ci * Beego web.Run() runs the server twice * fix 5255: Check the rows.Err() if rows.Next() is false * closes 5254: %COL% should be a common placeholder * build(deps): bump github.com/prometheus/client_golang Bumps [github.com/prometheus/client_golang](https://github.com/prometheus/client_golang) from 1.15.1 to 1.16.0. - [Release notes](https://github.com/prometheus/client_golang/releases) - [Changelog](https://github.com/prometheus/client_golang/blob/main/CHANGELOG.md) - [Commits](https://github.com/prometheus/client_golang/compare/v1.15.1...v1.16.0) --- updated-dependencies: - dependency-name: github.com/prometheus/client_golang dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> * fix: use of ioutil package (#5261) * fix ioutil.NopCloser * fix ioutil.ReadAll * fix ioutil.ReadFile * fix ioutil.WriteFile * run goimports -w -format-only ./ * update CHANGELOG.md * feature: add write-double-delete cache mode (#5263) * cache/redis: support skipEmptyPrefix option (#5264) * fix: refactor InsertValue method (#5267) * fix: refactor insertValue method and add the test * fix: exec goimports and add Licence file header * fix: modify construct method of dbBase * fix: add modify record into CHANGELOG * fix: modify InsertOrUpdate method (#5269) * fix: modify InsertOrUpdate method, Remove the isMulti variable and its associated code * fix: Delete unnecessary judgment branches * fix: add modify record into CHANGELOG * cache/redis: use redisConfig to receive incoming JSON (previously using a map) (#5268) * refactor cache/redis: Use redisConfig to receive incoming JSON (previously using a map). * refactor cache/redis: Use the string type to receive JSON parameters. --------- Co-authored-by: Tan <tanqianheng@gmail.com> * fix: refactor Delete method (#5271) * fix: refactor Delete method and add test * fix: add modify record into CHANGELOG * fix: refactor update sql (#5274) * fix: refactor UpdateSQL method and add test * fix: add modify record into CHANGELOG * fix: modify url in the CHANGELOG * fix: modify pr url in the CHANGELOG * Fix setPK function for table without primary key (#5276) --------- Signed-off-by: dependabot[bot] <support@github.com> Signed-off-by: cui fliter <imcusg@gmail.com> Co-authored-by: Stone-afk <73482944+Stone-afk@users.noreply.github.com> Co-authored-by: hookokoko <hooko@tju.edu.cn> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: hookokoko <648646891@qq.com> Co-authored-by: Stone-afk <1711865140@qq.com> Co-authored-by: chenhaokun <chenhaokun@itiger.com> Co-authored-by: Xuing <admin@xuing.cn> Co-authored-by: cui fliter <imcusg@gmail.com> Co-authored-by: guoguangwu <guoguangwu@magic-shield.com> Co-authored-by: uzziah <uzziahlin@gmail.com> Co-authored-by: Hanjiang Yu <delacroix.yu@gmail.com> Co-authored-by: Kota <mdryzk64smsh@gmail.com> Co-authored-by: Uzziah <120019273+uzziahlin@users.noreply.github.com> Co-authored-by: Handkerchiefs-t <59816423+Handkerchiefs-t@users.noreply.github.com> Co-authored-by: Tan <tanqianheng@gmail.com> Co-authored-by: mlgd <mlgd17@gmail.com>
786 lines
18 KiB
Go
786 lines
18 KiB
Go
// Copyright 2014 beego Author. All Rights Reserved.
|
||
//
|
||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||
// you may not use this file except in compliance with the License.
|
||
// You may obtain a copy of the License at
|
||
//
|
||
// http://www.apache.org/licenses/LICENSE-2.0
|
||
//
|
||
// Unless required by applicable law or agreed to in writing, software
|
||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||
// See the License for the specific language governing permissions and
|
||
// limitations under the License.
|
||
|
||
package models
|
||
|
||
import (
|
||
"fmt"
|
||
"strconv"
|
||
"time"
|
||
|
||
"github.com/beego/beego/v2/client/orm/internal/utils"
|
||
)
|
||
|
||
// Define the Type enum
|
||
const (
|
||
TypeBooleanField = 1 << iota
|
||
TypeVarCharField
|
||
TypeCharField
|
||
TypeTextField
|
||
TypeTimeField
|
||
TypeDateField
|
||
TypeDateTimeField
|
||
TypeBitField
|
||
TypeSmallIntegerField
|
||
TypeIntegerField
|
||
TypeBigIntegerField
|
||
TypePositiveBitField
|
||
TypePositiveSmallIntegerField
|
||
TypePositiveIntegerField
|
||
TypePositiveBigIntegerField
|
||
TypeFloatField
|
||
TypeDecimalField
|
||
TypeJSONField
|
||
TypeJsonbField
|
||
RelForeignKey
|
||
RelOneToOne
|
||
RelManyToMany
|
||
RelReverseOne
|
||
RelReverseMany
|
||
)
|
||
|
||
// Define some logic enum
|
||
const (
|
||
IsIntegerField = ^-TypePositiveBigIntegerField >> 6 << 7
|
||
IsPositiveIntegerField = ^-TypePositiveBigIntegerField >> 10 << 11
|
||
IsRelField = ^-RelReverseMany >> 18 << 19
|
||
IsFieldType = ^-RelReverseMany<<1 + 1
|
||
)
|
||
|
||
// BooleanField A true/false field.
|
||
type BooleanField bool
|
||
|
||
// Value return the BooleanField
|
||
func (e BooleanField) Value() bool {
|
||
return bool(e)
|
||
}
|
||
|
||
// Set will set the BooleanField
|
||
func (e *BooleanField) Set(d bool) {
|
||
*e = BooleanField(d)
|
||
}
|
||
|
||
// String format the Bool to string
|
||
func (e *BooleanField) String() string {
|
||
return strconv.FormatBool(e.Value())
|
||
}
|
||
|
||
// FieldType return BooleanField the type
|
||
func (e *BooleanField) FieldType() int {
|
||
return TypeBooleanField
|
||
}
|
||
|
||
// SetRaw set the interface to bool
|
||
func (e *BooleanField) SetRaw(value interface{}) error {
|
||
switch d := value.(type) {
|
||
case bool:
|
||
e.Set(d)
|
||
case string:
|
||
v, err := utils.StrTo(d).Bool()
|
||
if err == nil {
|
||
e.Set(v)
|
||
}
|
||
return err
|
||
default:
|
||
return fmt.Errorf("<BooleanField.SetRaw> unknown value `%s`", value)
|
||
}
|
||
return nil
|
||
}
|
||
|
||
// RawValue return the current value
|
||
func (e *BooleanField) RawValue() interface{} {
|
||
return e.Value()
|
||
}
|
||
|
||
// verify the BooleanField implement the Fielder interface
|
||
var _ Fielder = new(BooleanField)
|
||
|
||
// CharField A string field
|
||
// required values tag: size
|
||
// The size is enforced at the database level and in models’s validation.
|
||
// eg: `orm:"size(120)"`
|
||
type CharField string
|
||
|
||
// Value return the CharField's Value
|
||
func (e CharField) Value() string {
|
||
return string(e)
|
||
}
|
||
|
||
// Set CharField value
|
||
func (e *CharField) Set(d string) {
|
||
*e = CharField(d)
|
||
}
|
||
|
||
// String return the CharField
|
||
func (e *CharField) String() string {
|
||
return e.Value()
|
||
}
|
||
|
||
// FieldType return the enum type
|
||
func (e *CharField) FieldType() int {
|
||
return TypeVarCharField
|
||
}
|
||
|
||
// SetRaw set the interface to string
|
||
func (e *CharField) SetRaw(value interface{}) error {
|
||
switch d := value.(type) {
|
||
case string:
|
||
e.Set(d)
|
||
default:
|
||
return fmt.Errorf("<CharField.SetRaw> unknown value `%s`", value)
|
||
}
|
||
return nil
|
||
}
|
||
|
||
// RawValue return the CharField value
|
||
func (e *CharField) RawValue() interface{} {
|
||
return e.Value()
|
||
}
|
||
|
||
// verify CharField implement Fielder
|
||
var _ Fielder = new(CharField)
|
||
|
||
// TimeField A time, represented in go by a time.Time instance.
|
||
// only time values like 10:00:00
|
||
// Has a few extra, optional attr tag:
|
||
//
|
||
// auto_now:
|
||
// Automatically set the field to now every time the object is saved. Useful for “last-modified” timestamps.
|
||
// Note that the current date is always used; it’s not just a default value that you can override.
|
||
//
|
||
// auto_now_add:
|
||
// Automatically set the field to now when the object is first created. Useful for creation of timestamps.
|
||
// Note that the current date is always used; it’s not just a default value that you can override.
|
||
//
|
||
// eg: `orm:"auto_now"` or `orm:"auto_now_add"`
|
||
type TimeField time.Time
|
||
|
||
// Value return the time.Time
|
||
func (e TimeField) Value() time.Time {
|
||
return time.Time(e)
|
||
}
|
||
|
||
// Set set the TimeField's value
|
||
func (e *TimeField) Set(d time.Time) {
|
||
*e = TimeField(d)
|
||
}
|
||
|
||
// String convert time to string
|
||
func (e *TimeField) String() string {
|
||
return e.Value().String()
|
||
}
|
||
|
||
// FieldType return enum type Date
|
||
func (e *TimeField) FieldType() int {
|
||
return TypeDateField
|
||
}
|
||
|
||
// SetRaw convert the interface to time.Time. Allow string and time.Time
|
||
func (e *TimeField) SetRaw(value interface{}) error {
|
||
switch d := value.(type) {
|
||
case time.Time:
|
||
e.Set(d)
|
||
case string:
|
||
v, err := utils.TimeParse(d, utils.FormatTime)
|
||
if err == nil {
|
||
e.Set(v)
|
||
}
|
||
return err
|
||
default:
|
||
return fmt.Errorf("<TimeField.SetRaw> unknown value `%s`", value)
|
||
}
|
||
return nil
|
||
}
|
||
|
||
// RawValue return time value
|
||
func (e *TimeField) RawValue() interface{} {
|
||
return e.Value()
|
||
}
|
||
|
||
var _ Fielder = new(TimeField)
|
||
|
||
// DateField A date, represented in go by a time.Time instance.
|
||
// only date values like 2006-01-02
|
||
// Has a few extra, optional attr tag:
|
||
//
|
||
// auto_now:
|
||
// Automatically set the field to now every time the object is saved. Useful for “last-modified” timestamps.
|
||
// Note that the current date is always used; it’s not just a default value that you can override.
|
||
//
|
||
// auto_now_add:
|
||
// Automatically set the field to now when the object is first created. Useful for creation of timestamps.
|
||
// Note that the current date is always used; it’s not just a default value that you can override.
|
||
//
|
||
// eg: `orm:"auto_now"` or `orm:"auto_now_add"`
|
||
type DateField time.Time
|
||
|
||
// Value return the time.Time
|
||
func (e DateField) Value() time.Time {
|
||
return time.Time(e)
|
||
}
|
||
|
||
// Set set the DateField's value
|
||
func (e *DateField) Set(d time.Time) {
|
||
*e = DateField(d)
|
||
}
|
||
|
||
// String convert datetime to string
|
||
func (e *DateField) String() string {
|
||
return e.Value().String()
|
||
}
|
||
|
||
// FieldType return enum type Date
|
||
func (e *DateField) FieldType() int {
|
||
return TypeDateField
|
||
}
|
||
|
||
// SetRaw convert the interface to time.Time. Allow string and time.Time
|
||
func (e *DateField) SetRaw(value interface{}) error {
|
||
switch d := value.(type) {
|
||
case time.Time:
|
||
e.Set(d)
|
||
case string:
|
||
v, err := utils.TimeParse(d, utils.FormatDate)
|
||
if err == nil {
|
||
e.Set(v)
|
||
}
|
||
return err
|
||
default:
|
||
return fmt.Errorf("<DateField.SetRaw> unknown value `%s`", value)
|
||
}
|
||
return nil
|
||
}
|
||
|
||
// RawValue return Date value
|
||
func (e *DateField) RawValue() interface{} {
|
||
return e.Value()
|
||
}
|
||
|
||
// verify DateField implement fielder interface
|
||
var _ Fielder = new(DateField)
|
||
|
||
// DateTimeField A date, represented in go by a time.Time instance.
|
||
// datetime values like 2006-01-02 15:04:05
|
||
// Takes the same extra arguments as DateField.
|
||
type DateTimeField time.Time
|
||
|
||
// Value return the datetime value
|
||
func (e DateTimeField) Value() time.Time {
|
||
return time.Time(e)
|
||
}
|
||
|
||
// Set set the time.Time to datetime
|
||
func (e *DateTimeField) Set(d time.Time) {
|
||
*e = DateTimeField(d)
|
||
}
|
||
|
||
// String return the time's String
|
||
func (e *DateTimeField) String() string {
|
||
return e.Value().String()
|
||
}
|
||
|
||
// FieldType return the enum TypeDateTimeField
|
||
func (e *DateTimeField) FieldType() int {
|
||
return TypeDateTimeField
|
||
}
|
||
|
||
// SetRaw convert the string or time.Time to DateTimeField
|
||
func (e *DateTimeField) SetRaw(value interface{}) error {
|
||
switch d := value.(type) {
|
||
case time.Time:
|
||
e.Set(d)
|
||
case string:
|
||
v, err := utils.TimeParse(d, utils.FormatDateTime)
|
||
if err == nil {
|
||
e.Set(v)
|
||
}
|
||
return err
|
||
default:
|
||
return fmt.Errorf("<DateTimeField.SetRaw> unknown value `%s`", value)
|
||
}
|
||
return nil
|
||
}
|
||
|
||
// RawValue return the datetime value
|
||
func (e *DateTimeField) RawValue() interface{} {
|
||
return e.Value()
|
||
}
|
||
|
||
// verify datetime implement fielder
|
||
var _ Fielder = new(DateTimeField)
|
||
|
||
// FloatField A floating-point number represented in go by a float32 value.
|
||
type FloatField float64
|
||
|
||
// Value return the FloatField value
|
||
func (e FloatField) Value() float64 {
|
||
return float64(e)
|
||
}
|
||
|
||
// Set the Float64
|
||
func (e *FloatField) Set(d float64) {
|
||
*e = FloatField(d)
|
||
}
|
||
|
||
// String return the string
|
||
func (e *FloatField) String() string {
|
||
return utils.ToStr(e.Value(), -1, 32)
|
||
}
|
||
|
||
// FieldType return the enum type
|
||
func (e *FloatField) FieldType() int {
|
||
return TypeFloatField
|
||
}
|
||
|
||
// SetRaw converter interface Float64 float32 or string to FloatField
|
||
func (e *FloatField) SetRaw(value interface{}) error {
|
||
switch d := value.(type) {
|
||
case float32:
|
||
e.Set(float64(d))
|
||
case float64:
|
||
e.Set(d)
|
||
case string:
|
||
v, err := utils.StrTo(d).Float64()
|
||
if err == nil {
|
||
e.Set(v)
|
||
}
|
||
return err
|
||
default:
|
||
return fmt.Errorf("<FloatField.SetRaw> unknown value `%s`", value)
|
||
}
|
||
return nil
|
||
}
|
||
|
||
// RawValue return the FloatField value
|
||
func (e *FloatField) RawValue() interface{} {
|
||
return e.Value()
|
||
}
|
||
|
||
// verify FloatField implement Fielder
|
||
var _ Fielder = new(FloatField)
|
||
|
||
// SmallIntegerField -32768 to 32767
|
||
type SmallIntegerField int16
|
||
|
||
// Value return int16 value
|
||
func (e SmallIntegerField) Value() int16 {
|
||
return int16(e)
|
||
}
|
||
|
||
// Set the SmallIntegerField value
|
||
func (e *SmallIntegerField) Set(d int16) {
|
||
*e = SmallIntegerField(d)
|
||
}
|
||
|
||
// String convert smallint to string
|
||
func (e *SmallIntegerField) String() string {
|
||
return utils.ToStr(e.Value())
|
||
}
|
||
|
||
// FieldType return enum type SmallIntegerField
|
||
func (e *SmallIntegerField) FieldType() int {
|
||
return TypeSmallIntegerField
|
||
}
|
||
|
||
// SetRaw convert interface int16/string to int16
|
||
func (e *SmallIntegerField) SetRaw(value interface{}) error {
|
||
switch d := value.(type) {
|
||
case int16:
|
||
e.Set(d)
|
||
case string:
|
||
v, err := utils.StrTo(d).Int16()
|
||
if err == nil {
|
||
e.Set(v)
|
||
}
|
||
return err
|
||
default:
|
||
return fmt.Errorf("<SmallIntegerField.SetRaw> unknown value `%s`", value)
|
||
}
|
||
return nil
|
||
}
|
||
|
||
// RawValue return smallint value
|
||
func (e *SmallIntegerField) RawValue() interface{} {
|
||
return e.Value()
|
||
}
|
||
|
||
// verify SmallIntegerField implement Fielder
|
||
var _ Fielder = new(SmallIntegerField)
|
||
|
||
// IntegerField -2147483648 to 2147483647
|
||
type IntegerField int32
|
||
|
||
// Value return the int32
|
||
func (e IntegerField) Value() int32 {
|
||
return int32(e)
|
||
}
|
||
|
||
// Set IntegerField value
|
||
func (e *IntegerField) Set(d int32) {
|
||
*e = IntegerField(d)
|
||
}
|
||
|
||
// String convert Int32 to string
|
||
func (e *IntegerField) String() string {
|
||
return utils.ToStr(e.Value())
|
||
}
|
||
|
||
// FieldType return the enum type
|
||
func (e *IntegerField) FieldType() int {
|
||
return TypeIntegerField
|
||
}
|
||
|
||
// SetRaw convert interface int32/string to int32
|
||
func (e *IntegerField) SetRaw(value interface{}) error {
|
||
switch d := value.(type) {
|
||
case int32:
|
||
e.Set(d)
|
||
case string:
|
||
v, err := utils.StrTo(d).Int32()
|
||
if err == nil {
|
||
e.Set(v)
|
||
}
|
||
return err
|
||
default:
|
||
return fmt.Errorf("<IntegerField.SetRaw> unknown value `%s`", value)
|
||
}
|
||
return nil
|
||
}
|
||
|
||
// RawValue return IntegerField value
|
||
func (e *IntegerField) RawValue() interface{} {
|
||
return e.Value()
|
||
}
|
||
|
||
// verify IntegerField implement Fielder
|
||
var _ Fielder = new(IntegerField)
|
||
|
||
// BigIntegerField -9223372036854775808 to 9223372036854775807.
|
||
type BigIntegerField int64
|
||
|
||
// Value return int64
|
||
func (e BigIntegerField) Value() int64 {
|
||
return int64(e)
|
||
}
|
||
|
||
// Set the BigIntegerField value
|
||
func (e *BigIntegerField) Set(d int64) {
|
||
*e = BigIntegerField(d)
|
||
}
|
||
|
||
// String convert BigIntegerField to string
|
||
func (e *BigIntegerField) String() string {
|
||
return utils.ToStr(e.Value())
|
||
}
|
||
|
||
// FieldType return enum type
|
||
func (e *BigIntegerField) FieldType() int {
|
||
return TypeBigIntegerField
|
||
}
|
||
|
||
// SetRaw convert interface int64/string to int64
|
||
func (e *BigIntegerField) SetRaw(value interface{}) error {
|
||
switch d := value.(type) {
|
||
case int64:
|
||
e.Set(d)
|
||
case string:
|
||
v, err := utils.StrTo(d).Int64()
|
||
if err == nil {
|
||
e.Set(v)
|
||
}
|
||
return err
|
||
default:
|
||
return fmt.Errorf("<BigIntegerField.SetRaw> unknown value `%s`", value)
|
||
}
|
||
return nil
|
||
}
|
||
|
||
// RawValue return BigIntegerField value
|
||
func (e *BigIntegerField) RawValue() interface{} {
|
||
return e.Value()
|
||
}
|
||
|
||
// verify BigIntegerField implement Fielder
|
||
var _ Fielder = new(BigIntegerField)
|
||
|
||
// PositiveSmallIntegerField 0 to 65535
|
||
type PositiveSmallIntegerField uint16
|
||
|
||
// Value return uint16
|
||
func (e PositiveSmallIntegerField) Value() uint16 {
|
||
return uint16(e)
|
||
}
|
||
|
||
// Set PositiveSmallIntegerField value
|
||
func (e *PositiveSmallIntegerField) Set(d uint16) {
|
||
*e = PositiveSmallIntegerField(d)
|
||
}
|
||
|
||
// String convert uint16 to string
|
||
func (e *PositiveSmallIntegerField) String() string {
|
||
return utils.ToStr(e.Value())
|
||
}
|
||
|
||
// FieldType return enum type
|
||
func (e *PositiveSmallIntegerField) FieldType() int {
|
||
return TypePositiveSmallIntegerField
|
||
}
|
||
|
||
// SetRaw convert Interface uint16/string to uint16
|
||
func (e *PositiveSmallIntegerField) SetRaw(value interface{}) error {
|
||
switch d := value.(type) {
|
||
case uint16:
|
||
e.Set(d)
|
||
case string:
|
||
v, err := utils.StrTo(d).Uint16()
|
||
if err == nil {
|
||
e.Set(v)
|
||
}
|
||
return err
|
||
default:
|
||
return fmt.Errorf("<PositiveSmallIntegerField.SetRaw> unknown value `%s`", value)
|
||
}
|
||
return nil
|
||
}
|
||
|
||
// RawValue returns PositiveSmallIntegerField value
|
||
func (e *PositiveSmallIntegerField) RawValue() interface{} {
|
||
return e.Value()
|
||
}
|
||
|
||
// verify PositiveSmallIntegerField implement Fielder
|
||
var _ Fielder = new(PositiveSmallIntegerField)
|
||
|
||
// PositiveIntegerField 0 to 4294967295
|
||
type PositiveIntegerField uint32
|
||
|
||
// Value return PositiveIntegerField value. Uint32
|
||
func (e PositiveIntegerField) Value() uint32 {
|
||
return uint32(e)
|
||
}
|
||
|
||
// Set the PositiveIntegerField value
|
||
func (e *PositiveIntegerField) Set(d uint32) {
|
||
*e = PositiveIntegerField(d)
|
||
}
|
||
|
||
// String convert PositiveIntegerField to string
|
||
func (e *PositiveIntegerField) String() string {
|
||
return utils.ToStr(e.Value())
|
||
}
|
||
|
||
// FieldType return enum type
|
||
func (e *PositiveIntegerField) FieldType() int {
|
||
return TypePositiveIntegerField
|
||
}
|
||
|
||
// SetRaw convert interface uint32/string to Uint32
|
||
func (e *PositiveIntegerField) SetRaw(value interface{}) error {
|
||
switch d := value.(type) {
|
||
case uint32:
|
||
e.Set(d)
|
||
case string:
|
||
v, err := utils.StrTo(d).Uint32()
|
||
if err == nil {
|
||
e.Set(v)
|
||
}
|
||
return err
|
||
default:
|
||
return fmt.Errorf("<PositiveIntegerField.SetRaw> unknown value `%s`", value)
|
||
}
|
||
return nil
|
||
}
|
||
|
||
// RawValue return the PositiveIntegerField Value
|
||
func (e *PositiveIntegerField) RawValue() interface{} {
|
||
return e.Value()
|
||
}
|
||
|
||
// verify PositiveIntegerField implement Fielder
|
||
var _ Fielder = new(PositiveIntegerField)
|
||
|
||
// PositiveBigIntegerField 0 to 18446744073709551615
|
||
type PositiveBigIntegerField uint64
|
||
|
||
// Value return uint64
|
||
func (e PositiveBigIntegerField) Value() uint64 {
|
||
return uint64(e)
|
||
}
|
||
|
||
// Set PositiveBigIntegerField value
|
||
func (e *PositiveBigIntegerField) Set(d uint64) {
|
||
*e = PositiveBigIntegerField(d)
|
||
}
|
||
|
||
// String convert PositiveBigIntegerField to string
|
||
func (e *PositiveBigIntegerField) String() string {
|
||
return utils.ToStr(e.Value())
|
||
}
|
||
|
||
// FieldType return enum type
|
||
func (e *PositiveBigIntegerField) FieldType() int {
|
||
return TypePositiveIntegerField
|
||
}
|
||
|
||
// SetRaw convert interface uint64/string to Uint64
|
||
func (e *PositiveBigIntegerField) SetRaw(value interface{}) error {
|
||
switch d := value.(type) {
|
||
case uint64:
|
||
e.Set(d)
|
||
case string:
|
||
v, err := utils.StrTo(d).Uint64()
|
||
if err == nil {
|
||
e.Set(v)
|
||
}
|
||
return err
|
||
default:
|
||
return fmt.Errorf("<PositiveBigIntegerField.SetRaw> unknown value `%s`", value)
|
||
}
|
||
return nil
|
||
}
|
||
|
||
// RawValue return PositiveBigIntegerField value
|
||
func (e *PositiveBigIntegerField) RawValue() interface{} {
|
||
return e.Value()
|
||
}
|
||
|
||
// verify PositiveBigIntegerField implement Fielder
|
||
var _ Fielder = new(PositiveBigIntegerField)
|
||
|
||
// TextField A large text field.
|
||
type TextField string
|
||
|
||
// Value return TextField value
|
||
func (e TextField) Value() string {
|
||
return string(e)
|
||
}
|
||
|
||
// Set the TextField value
|
||
func (e *TextField) Set(d string) {
|
||
*e = TextField(d)
|
||
}
|
||
|
||
// String convert TextField to string
|
||
func (e *TextField) String() string {
|
||
return e.Value()
|
||
}
|
||
|
||
// FieldType return enum type
|
||
func (e *TextField) FieldType() int {
|
||
return TypeTextField
|
||
}
|
||
|
||
// SetRaw convert interface string to string
|
||
func (e *TextField) SetRaw(value interface{}) error {
|
||
switch d := value.(type) {
|
||
case string:
|
||
e.Set(d)
|
||
default:
|
||
return fmt.Errorf("<TextField.SetRaw> unknown value `%s`", value)
|
||
}
|
||
return nil
|
||
}
|
||
|
||
// RawValue return TextField value
|
||
func (e *TextField) RawValue() interface{} {
|
||
return e.Value()
|
||
}
|
||
|
||
// verify TextField implement Fielder
|
||
var _ Fielder = new(TextField)
|
||
|
||
// JSONField postgres json field.
|
||
type JSONField string
|
||
|
||
// Value return JSONField value
|
||
func (j JSONField) Value() string {
|
||
return string(j)
|
||
}
|
||
|
||
// Set the JSONField value
|
||
func (j *JSONField) Set(d string) {
|
||
*j = JSONField(d)
|
||
}
|
||
|
||
// String convert JSONField to string
|
||
func (j *JSONField) String() string {
|
||
return j.Value()
|
||
}
|
||
|
||
// FieldType return enum type
|
||
func (j *JSONField) FieldType() int {
|
||
return TypeJSONField
|
||
}
|
||
|
||
// SetRaw convert interface string to string
|
||
func (j *JSONField) SetRaw(value interface{}) error {
|
||
switch d := value.(type) {
|
||
case string:
|
||
j.Set(d)
|
||
default:
|
||
return fmt.Errorf("<JSONField.SetRaw> unknown value `%s`", value)
|
||
}
|
||
return nil
|
||
}
|
||
|
||
// RawValue return JSONField value
|
||
func (j *JSONField) RawValue() interface{} {
|
||
return j.Value()
|
||
}
|
||
|
||
// verify JSONField implement Fielder
|
||
var _ Fielder = new(JSONField)
|
||
|
||
// JsonbField postgres json field.
|
||
type JsonbField string
|
||
|
||
// Value return JsonbField value
|
||
func (j JsonbField) Value() string {
|
||
return string(j)
|
||
}
|
||
|
||
// Set the JsonbField value
|
||
func (j *JsonbField) Set(d string) {
|
||
*j = JsonbField(d)
|
||
}
|
||
|
||
// String convert JsonbField to string
|
||
func (j *JsonbField) String() string {
|
||
return j.Value()
|
||
}
|
||
|
||
// FieldType return enum type
|
||
func (j *JsonbField) FieldType() int {
|
||
return TypeJsonbField
|
||
}
|
||
|
||
// SetRaw convert interface string to string
|
||
func (j *JsonbField) SetRaw(value interface{}) error {
|
||
switch d := value.(type) {
|
||
case string:
|
||
j.Set(d)
|
||
default:
|
||
return fmt.Errorf("<JsonbField.SetRaw> unknown value `%s`", value)
|
||
}
|
||
return nil
|
||
}
|
||
|
||
// RawValue return JsonbField value
|
||
func (j *JsonbField) RawValue() interface{} {
|
||
return j.Value()
|
||
}
|
||
|
||
// verify JsonbField implement Fielder
|
||
var _ Fielder = new(JsonbField)
|