nullable

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2020 License: MIT Imports: 12 Imported by: 1

README

Nullable SQL Data Types for Golang (GO)

Open Issues Open Pull Request Unit Test Result Unit Test Coverage

Helps you convert every SQL nullable data types into Golang's supported types. So you don't have to create your own scanner and valuer only for.. let's say... BIGINT UNSIGNED NULL

Nullable handles all SQL<->Go data type conversion burden just for you :)

Features

  • 100% GORM support
  • Can be marshalled into JSON
  • Can be unmarshal from JSON
  • Convenient Set/Get operation
  • Support MySQL, MariaDB, SQLite, and PostgreSQL
  • Zero configuration, just use it as normal data type.
  • Heavily tested! So you don't have to worry of many bugs :D

Supported Data Types

  • bool
  • byte
  • string
  • time.Time (capable of handling DATETIME, TIME, DATE, and TIMESTAMP)
  • []byte
  • float32
  • float64
  • int
  • int8
  • int16
  • int32
  • int64
  • uint
  • uint8
  • uint16
  • uint32
  • uint64

WARNING: PostgreSQL won't support any form of unsigned integers. However, you still able to use any uint variants with a drawback: they will be stored in form of raw binary instead of normal integer. Thus, PostgreSQL-side uint comparation is impossible, you have to compare them in your Go application. MySQL, MariaDB, and SQLite won't affected by this issue, don't worry.

How to Use?

Very easy! first of all, let's install like normal Go packages

go get github.com/Thor-x86/nullable

Create a new variable

Remember, all you need to have is a basic variable and a nullable variable created with nullable.New...(&yourBasicVar). Example:

import (
    "fmt"
    "gorm.io/gorm"
    "github.com/Thor-x86/nullable"
)

func main() {
    // Create new
    myBasicString := "Hello blяoW!"
    myNullableString := nullable.NewString(&myBasicString)

    // Create new but already nil
    myAlreadyNullString := nullable.NewString(nil)

    // Get and print to command console
    fmt.Println(myNullableString.Get()) // Output: Hello blяoW!
    fmt.Println(myAlreadyNullString.Get()) // Output: nil
}

Change existing variable

You'll use .Set(&anotherBasicVar) to change existing variable. Example:

import (
    "fmt"
    "gorm.io/gorm"
    "github.com/Thor-x86/nullable"
)

func main() {
    // Create new
    myBasicString := "Hello blяoW!"
    myNullableString := nullable.NewString(&myBasicString)
    fmt.Println(myNullableString.Get()) // Output: Hello blяoW!

    // Change existing variable
    anotherString := "Hello World!"
    myNullableString.Set(&anotherString)
    fmt.Println(myNullableString.Get()) // Output: Hello World!

    // Change with nil
    myNullableString.Set(nil)
    fmt.Println(myNullableString.Get()) // Output: nil
}

Also another example for uint64:

import (
    "fmt"
    "gorm.io/gorm"
    "github.com/Thor-x86/nullable"
)

func main() {
    // Create new
    var theNumber uint64 = 70
    nullableNumber := nullable.NewUint64(&theNumber)
    fmt.Println(nullableNumber.Get()) // Output: 70

    // Change to another number
    var anotherNumber uint64 = 3306
    nullableNumber.Set(&anotherNumber)
    fmt.Println(nullableNumber.Get()) // Output: 3306

    // Change to nil
    nullableNumber.Set(nil)
    fmt.Println(nullableNumber.Get()) // Output: nil
}

Change without creating a new basic variable

If you thinking it's not really convenient to create a basic variable first, then you can use .Scan(...) instead of .Set(&yourBasicVar). Example:

import (
    "fmt"
    "gorm.io/gorm"
    "github.com/Thor-x86/nullable"
)

func main() {
    // Create new
    nullableString := nullable.NewString(nil)

    // Directly write string
    nullableString.Scan("Hello blяoW!")
    fmt.Println(nullableString.Get()) // Output: Hello blяoW!

    // Change existing string
    nullableString.Scan("Hello World!")
    fmt.Println(nullableString.Get()) // Output: Hello World!

    // Scan also works with nil
    nullableString.Scan(nil)
    fmt.Println(nullableString.Get()) // Output: nil
}

WARNING: Mostly .Scan(...) won't cause compile-time error when you did something wrong, please be careful.

For Contributors

Feel free to clone, fork, pull request, and open a new issue on this repository. However, you must test your work before asking for pull request. Here's how to execute the test:

  1. For Windows users, install WSL first. MacOS and Linux users can skip to the next step.
  2. Open your bash terminal. Then install Docker and Docker Compose.
  3. Make sure your bash terminal is currently pointing nullable project directory.
  4. Run this to start the databases: docker-compose up
  5. Wait for a minute, just to make sure all databases are ready.
  6. Run this to start the testing process: ./test_all.sh
  7. If everything OK, you're good to pull request. Otherwise, check what's the root of problem.

Frequently Asked Question (FAQ)

Q: If everything set with pointer, will it causes memory leak or something? A: No, it won't store the pointer but the real value itself. Much like sql.NullString but every nil checking already done at nullable package.

Q: Why Scan is unsafe? A: The Scan method actually meant to be implemented for Golang's SQL package to read query response from SQL server. However, you're allowed to use that as you like within risk of runtime error if you did something wrong.

Q: Will you add Microsoft SQL (MsSQL) Server support? A: MsSQL throws me a lot of error while developing this project. I don't have much that time to tame MsSQL. Anyway, feel free to pull request. I already added the test configuration at test_all.sh, main_test.go, and .github/workflows/tests.yml. Just uncomment them and run the test as usual.

Q: How about key-value server support like Redis, Cassandra, and Memcached? A: First of all, another ORM need to be implemented like redis-orm. The challenge is we need to make sure it won't conflict with GORM. Pull request always welcome :)

Q: Is this support NoSQL like MongoDB? A: If it JSON-marshallable, then the answer is yes. Nullable can be unmarshalled from JSON.

Q: I found security issue, can I open issue for this? A: Please don't. You risking another users' security. Email me instead at athaariqa@gmail.com

Q: This FAQ section didn't answer my problem. A: Feel free to find issue regarding the problem. If you found nothing, you are allowed to open a new issue.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bool

type Bool struct {
	// contains filtered or unexported fields
}

Bool SQL type that can retrieve NULL value

func NewBool

func NewBool(value *bool) Bool

NewBool creates a new nullable boolean

func (Bool) Get

func (n Bool) Get() *bool

Get either nil or boolean

func (Bool) GormDBDataType

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

GormDBDataType gorm db data type

func (Bool) GormDataType

func (Bool) GormDataType() string

GormDataType gorm common data type

func (Bool) MarshalJSON

func (n Bool) MarshalJSON() ([]byte, error)

MarshalJSON converts current value to JSON

func (*Bool) Scan

func (n *Bool) Scan(value interface{}) error

Scan implements scanner interface

func (*Bool) Set

func (n *Bool) Set(value *bool)

Set either nil or boolean

func (*Bool) UnmarshalJSON

func (n *Bool) UnmarshalJSON(data []byte) error

UnmarshalJSON writes JSON to this type

func (Bool) Value

func (n Bool) Value() (driver.Value, error)

Value implements the driver Valuer interface.

type Byte

type Byte struct {
	// contains filtered or unexported fields
}

Byte SQL type that can retrieve NULL value

func NewByte

func NewByte(value *byte) Byte

NewByte creates a new nullable single byte

func (Byte) Get

func (n Byte) Get() *byte

Get either nil or single byte

func (Byte) GormDBDataType

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

GormDBDataType gorm db data type

func (Byte) GormDataType

func (Byte) GormDataType() string

GormDataType gorm common data type

func (Byte) MarshalJSON

func (n Byte) MarshalJSON() ([]byte, error)

MarshalJSON converts current value to JSON

func (*Byte) Scan

func (n *Byte) Scan(value interface{}) error

Scan implements scanner interface

func (*Byte) Set

func (n *Byte) Set(value *byte)

Set either nil or single byte

func (*Byte) UnmarshalJSON

func (n *Byte) UnmarshalJSON(data []byte) error

UnmarshalJSON writes JSON to this type

func (Byte) Value

func (n Byte) Value() (driver.Value, error)

Value implements the driver Valuer interface.

type Bytes

type Bytes struct {
	// contains filtered or unexported fields
}

Bytes SQL type that can retrieve NULL value

func NewBytes

func NewBytes(value *[]byte) Bytes

NewBytes creates a new nullable array of bytes

func (Bytes) Get

func (n Bytes) Get() *[]byte

Get either nil or array of bytes

func (Bytes) GormDBDataType

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

GormDBDataType gorm db data type

func (Bytes) GormDataType

func (Bytes) GormDataType() string

GormDataType gorm common data type

func (Bytes) MarshalJSON

func (n Bytes) MarshalJSON() ([]byte, error)

MarshalJSON converts current value to JSON

func (*Bytes) Scan

func (n *Bytes) Scan(value interface{}) error

Scan implements scanner interface

func (*Bytes) Set

func (n *Bytes) Set(value *[]byte)

Set either nil or array of bytes

func (*Bytes) UnmarshalJSON

func (n *Bytes) UnmarshalJSON(data []byte) error

UnmarshalJSON writes JSON to this type

func (Bytes) Value

func (n Bytes) Value() (driver.Value, error)

Value implements the driver Valuer interface.

type Float32

type Float32 struct {
	// contains filtered or unexported fields
}

Float32 SQL type that can retrieve NULL value

func NewFloat32

func NewFloat32(value *float32) Float32

NewFloat32 creates a new nullable float

func (Float32) Get

func (n Float32) Get() *float32

Get either nil or float

func (Float32) GormDBDataType

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

GormDBDataType gorm db data type

func (Float32) GormDataType

func (Float32) GormDataType() string

GormDataType gorm common data type

func (Float32) MarshalJSON

func (n Float32) MarshalJSON() ([]byte, error)

MarshalJSON converts current value to JSON

func (*Float32) Scan

func (n *Float32) Scan(value interface{}) error

Scan implements scanner interface

func (*Float32) Set

func (n *Float32) Set(value *float32)

Set either nil or float

func (*Float32) UnmarshalJSON

func (n *Float32) UnmarshalJSON(data []byte) error

UnmarshalJSON writes JSON to this type

func (Float32) Value

func (n Float32) Value() (driver.Value, error)

Value implements the driver Valuer interface.

type Float64

type Float64 struct {
	// contains filtered or unexported fields
}

Float64 SQL type that can retrieve NULL value

func NewFloat64

func NewFloat64(value *float64) Float64

NewFloat64 creates a new nullable double precision float

func (Float64) Get

func (n Float64) Get() *float64

Get either nil or double precision float

func (Float64) GormDBDataType

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

GormDBDataType gorm db data type

func (Float64) GormDataType

func (Float64) GormDataType() string

GormDataType gorm common data type

func (Float64) MarshalJSON

func (n Float64) MarshalJSON() ([]byte, error)

MarshalJSON converts current value to JSON

func (*Float64) Scan

func (n *Float64) Scan(value interface{}) error

Scan implements scanner interface

func (*Float64) Set

func (n *Float64) Set(value *float64)

Set either nil or double precision float

func (*Float64) UnmarshalJSON

func (n *Float64) UnmarshalJSON(data []byte) error

UnmarshalJSON writes JSON to this type

func (Float64) Value

func (n Float64) Value() (driver.Value, error)

Value implements the driver Valuer interface.

type Int

type Int struct {
	// contains filtered or unexported fields
}

Int SQL type that can retrieve NULL value

func NewInt

func NewInt(value *int) Int

NewInt creates a new nullable integer

func (Int) Get

func (n Int) Get() *int

Get either nil or integer

func (Int) GormDBDataType

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

GormDBDataType gorm db data type

func (Int) GormDataType

func (Int) GormDataType() string

GormDataType gorm common data type

func (Int) MarshalJSON

func (n Int) MarshalJSON() ([]byte, error)

MarshalJSON converts current value to JSON

func (*Int) Scan

func (n *Int) Scan(value interface{}) error

Scan implements scanner interface

func (*Int) Set

func (n *Int) Set(value *int)

Set either nil or integer

func (*Int) UnmarshalJSON

func (n *Int) UnmarshalJSON(data []byte) error

UnmarshalJSON writes JSON to this type

func (Int) Value

func (n Int) Value() (driver.Value, error)

Value implements the driver Valuer interface.

type Int16

type Int16 struct {
	// contains filtered or unexported fields
}

Int16 SQL type that can retrieve NULL value

func NewInt16

func NewInt16(value *int16) Int16

NewInt16 creates a new nullable 16-bit integer

func (Int16) Get

func (n Int16) Get() *int16

Get either nil or 16-bit integer

func (Int16) GormDBDataType

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

GormDBDataType gorm db data type

func (Int16) GormDataType

func (Int16) GormDataType() string

GormDataType gorm common data type

func (Int16) MarshalJSON

func (n Int16) MarshalJSON() ([]byte, error)

MarshalJSON converts current value to JSON

func (*Int16) Scan

func (n *Int16) Scan(value interface{}) error

Scan implements scanner interface

func (*Int16) Set

func (n *Int16) Set(value *int16)

Set either nil or 16-bit integer

func (*Int16) UnmarshalJSON

func (n *Int16) UnmarshalJSON(data []byte) error

UnmarshalJSON writes JSON to this type

func (Int16) Value

func (n Int16) Value() (driver.Value, error)

Value implements the driver Valuer interface.

type Int32

type Int32 struct {
	// contains filtered or unexported fields
}

Int32 SQL type that can retrieve NULL value

func NewInt32

func NewInt32(value *int32) Int32

NewInt32 creates a new nullable 32-bit integer

func (Int32) Get

func (n Int32) Get() *int32

Get either nil or 32-bit integer

func (Int32) GormDBDataType

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

GormDBDataType gorm db data type

func (Int32) GormDataType

func (Int32) GormDataType() string

GormDataType gorm common data type

func (Int32) MarshalJSON

func (n Int32) MarshalJSON() ([]byte, error)

MarshalJSON converts current value to JSON

func (*Int32) Scan

func (n *Int32) Scan(value interface{}) error

Scan implements scanner interface

func (*Int32) Set

func (n *Int32) Set(value *int32)

Set either nil or 32-bit integer

func (*Int32) UnmarshalJSON

func (n *Int32) UnmarshalJSON(data []byte) error

UnmarshalJSON writes JSON to this type

func (Int32) Value

func (n Int32) Value() (driver.Value, error)

Value implements the driver Valuer interface.

type Int64

type Int64 struct {
	// contains filtered or unexported fields
}

Int64 SQL type that can retrieve NULL value

func NewInt64

func NewInt64(value *int64) Int64

NewInt64 creates a new nullable 64-bit integer

func (Int64) Get

func (n Int64) Get() *int64

Get either nil or 64-bit integer

func (Int64) GormDBDataType

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

GormDBDataType gorm db data type

func (Int64) GormDataType

func (Int64) GormDataType() string

GormDataType gorm common data type

func (Int64) MarshalJSON

func (n Int64) MarshalJSON() ([]byte, error)

MarshalJSON converts current value to JSON

func (*Int64) Scan

func (n *Int64) Scan(value interface{}) error

Scan implements scanner interface

func (*Int64) Set

func (n *Int64) Set(value *int64)

Set either nil or 64-bit integer

func (*Int64) UnmarshalJSON

func (n *Int64) UnmarshalJSON(data []byte) error

UnmarshalJSON writes JSON to this type

func (Int64) Value

func (n Int64) Value() (driver.Value, error)

Value implements the driver Valuer interface.

type Int8

type Int8 struct {
	// contains filtered or unexported fields
}

Int8 SQL type that can retrieve NULL value

func NewInt8

func NewInt8(value *int8) Int8

NewInt8 creates a new nullable 8-bit integer

func (Int8) Get

func (n Int8) Get() *int8

Get either nil or 8-bit integer

func (Int8) GormDBDataType

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

GormDBDataType gorm db data type

func (Int8) GormDataType

func (Int8) GormDataType() string

GormDataType gorm common data type

func (Int8) MarshalJSON

func (n Int8) MarshalJSON() ([]byte, error)

MarshalJSON converts current value to JSON

func (*Int8) Scan

func (n *Int8) Scan(value interface{}) error

Scan implements scanner interface

func (*Int8) Set

func (n *Int8) Set(value *int8)

Set either nil or 8-bit integer

func (*Int8) UnmarshalJSON

func (n *Int8) UnmarshalJSON(data []byte) error

UnmarshalJSON writes JSON to this type

func (Int8) Value

func (n Int8) Value() (driver.Value, error)

Value implements the driver Valuer interface.

type String

type String struct {
	// contains filtered or unexported fields
}

String SQL type that can retrieve NULL value

func NewString

func NewString(value *string) String

NewString creates a new nullable string

func (String) Get

func (n String) Get() *string

Get either nil or string

func (String) GormDBDataType

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

GormDBDataType gorm db data type

func (String) GormDataType

func (String) GormDataType() string

GormDataType gorm common data type

func (String) MarshalJSON

func (n String) MarshalJSON() ([]byte, error)

MarshalJSON converts current value to JSON

func (*String) Scan

func (n *String) Scan(value interface{}) error

Scan implements scanner interface

func (*String) Set

func (n *String) Set(value *string)

Set either nil or string

func (*String) UnmarshalJSON

func (n *String) UnmarshalJSON(data []byte) error

UnmarshalJSON writes JSON to this type

func (String) Value

func (n String) Value() (driver.Value, error)

Value implements the driver Valuer interface.

type Time

type Time struct {
	// contains filtered or unexported fields
}

Time SQL type that can retrieve NULL value

func NewTime

func NewTime(value *time.Time) Time

NewTime creates a new nullable 64-bit integer

func (Time) Get

func (n Time) Get() *time.Time

Get either nil or 64-bit integer

func (Time) GormDBDataType

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

GormDBDataType gorm db data type

func (Time) GormDataType

func (Time) GormDataType() string

GormDataType gorm common data type

func (Time) MarshalJSON

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

MarshalJSON converts current value to JSON

func (*Time) Scan

func (n *Time) Scan(value interface{}) error

Scan implements scanner interface

func (*Time) Set

func (n *Time) Set(value *time.Time)

Set either nil or 64-bit integer

func (*Time) UnmarshalJSON

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

UnmarshalJSON writes JSON to this type

func (Time) Value

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

Value implements the driver Valuer interface.

type Uint

type Uint struct {
	// contains filtered or unexported fields
}

Uint SQL type that can retrieve NULL value

func NewUint

func NewUint(value *uint) Uint

NewUint creates a new nullable unsigned integer

func (Uint) Get

func (n Uint) Get() *uint

Get either nil or unsigned integer

func (Uint) GormDBDataType

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

GormDBDataType gorm db data type

func (Uint) GormDataType

func (Uint) GormDataType() string

GormDataType gorm common data type

func (Uint) GormValue

func (n Uint) GormValue(ctx context.Context, db *gorm.DB) clause.Expr

GormValue implements the driver Valuer interface via GORM.

func (Uint) MarshalJSON

func (n Uint) MarshalJSON() ([]byte, error)

MarshalJSON converts current value to JSON

func (*Uint) Scan

func (n *Uint) Scan(value interface{}) error

Scan implements scanner interface

func (*Uint) Set

func (n *Uint) Set(value *uint)

Set either nil or unsigned integer

func (*Uint) UnmarshalJSON

func (n *Uint) UnmarshalJSON(data []byte) error

UnmarshalJSON writes JSON to this type

func (Uint) Value

func (n Uint) Value() (driver.Value, error)

Value implements the driver Valuer interface.

type Uint16

type Uint16 struct {
	// contains filtered or unexported fields
}

Uint16 SQL type that can retrieve NULL value

func NewUint16

func NewUint16(value *uint16) Uint16

NewUint16 creates a new nullable 16-bit unsigned integer

func (Uint16) Get

func (n Uint16) Get() *uint16

Get either nil or 16-bit unsigned integer

func (Uint16) GormDBDataType

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

GormDBDataType gorm db data type

func (Uint16) GormDataType

func (Uint16) GormDataType() string

GormDataType gorm common data type

func (Uint16) GormValue

func (n Uint16) GormValue(ctx context.Context, db *gorm.DB) clause.Expr

GormValue implements the driver Valuer interface via GORM.

func (Uint16) MarshalJSON

func (n Uint16) MarshalJSON() ([]byte, error)

MarshalJSON converts current value to JSON

func (*Uint16) Scan

func (n *Uint16) Scan(value interface{}) error

Scan implements scanner interface

func (*Uint16) Set

func (n *Uint16) Set(value *uint16)

Set either nil or 16-bit unsigned integer

func (*Uint16) UnmarshalJSON

func (n *Uint16) UnmarshalJSON(data []byte) error

UnmarshalJSON writes JSON to this type

func (Uint16) Value

func (n Uint16) Value() (driver.Value, error)

Value implements the driver Valuer interface.

type Uint32

type Uint32 struct {
	// contains filtered or unexported fields
}

Uint32 SQL type that can retrieve NULL value

func NewUint32

func NewUint32(value *uint32) Uint32

NewUint32 creates a new nullable 32-bit unsigned integer

func (Uint32) Get

func (n Uint32) Get() *uint32

Get either nil or 32-bit unsigned integer

func (Uint32) GormDBDataType

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

GormDBDataType gorm db data type

func (Uint32) GormDataType

func (Uint32) GormDataType() string

GormDataType gorm common data type

func (Uint32) GormValue

func (n Uint32) GormValue(ctx context.Context, db *gorm.DB) clause.Expr

GormValue implements the driver Valuer interface via GORM.

func (Uint32) MarshalJSON

func (n Uint32) MarshalJSON() ([]byte, error)

MarshalJSON converts current value to JSON

func (*Uint32) Scan

func (n *Uint32) Scan(value interface{}) error

Scan implements scanner interface

func (*Uint32) Set

func (n *Uint32) Set(value *uint32)

Set either nil or 32-bit unsigned integer

func (*Uint32) UnmarshalJSON

func (n *Uint32) UnmarshalJSON(data []byte) error

UnmarshalJSON writes JSON to this type

func (Uint32) Value

func (n Uint32) Value() (driver.Value, error)

Value implements the driver Valuer interface.

type Uint64

type Uint64 struct {
	// contains filtered or unexported fields
}

Uint64 SQL type that can retrieve NULL value

func NewUint64

func NewUint64(value *uint64) Uint64

NewUint64 creates a new nullable 64-bit integer

func (Uint64) Get

func (n Uint64) Get() *uint64

Get either nil or 64-bit integer

func (Uint64) GormDBDataType

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

GormDBDataType gorm db data type

func (Uint64) GormDataType

func (Uint64) GormDataType() string

GormDataType gorm common data type

func (Uint64) GormValue

func (n Uint64) GormValue(ctx context.Context, db *gorm.DB) clause.Expr

GormValue implements the driver Valuer interface via GORM.

func (Uint64) MarshalJSON

func (n Uint64) MarshalJSON() ([]byte, error)

MarshalJSON converts current value to JSON

func (*Uint64) Scan

func (n *Uint64) Scan(value interface{}) error

Scan implements scanner interface

func (*Uint64) Set

func (n *Uint64) Set(value *uint64)

Set either nil or 64-bit integer

func (*Uint64) UnmarshalJSON

func (n *Uint64) UnmarshalJSON(data []byte) error

UnmarshalJSON writes JSON to this type

func (Uint64) Value

func (n Uint64) Value() (driver.Value, error)

Value implements the driver Valuer interface.

type Uint8

type Uint8 struct {
	// contains filtered or unexported fields
}

Uint8 SQL type that can retrieve NULL value

func NewUint8

func NewUint8(value *uint8) Uint8

NewUint8 creates a new nullable 8-bit unsigned integer

func (Uint8) Get

func (n Uint8) Get() *uint8

Get either nil or 8-bit unsigned integer

func (Uint8) GormDBDataType

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

GormDBDataType gorm db data type

func (Uint8) GormDataType

func (Uint8) GormDataType() string

GormDataType gorm common data type

func (Uint8) GormValue

func (n Uint8) GormValue(ctx context.Context, db *gorm.DB) clause.Expr

GormValue implements the driver Valuer interface via GORM.

func (Uint8) MarshalJSON

func (n Uint8) MarshalJSON() ([]byte, error)

MarshalJSON converts current value to JSON

func (*Uint8) Scan

func (n *Uint8) Scan(value interface{}) error

Scan implements scanner interface

func (*Uint8) Set

func (n *Uint8) Set(value *uint8)

Set either nil or 8-bit unsigned integer

func (*Uint8) UnmarshalJSON

func (n *Uint8) UnmarshalJSON(data []byte) error

UnmarshalJSON writes JSON to this type

func (Uint8) Value

func (n Uint8) Value() (driver.Value, error)

Value implements the driver Valuer interface.

Jump to

Keyboard shortcuts

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