nullable

package module
v1.0.6 Latest Latest
Warning

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

Go to latest
Published: May 31, 2024 License: MIT Imports: 20 Imported by: 0

README

Go Reference Go

Nullable

Nullable Data Type for json and database

Install

go get go.portalnesia.com/nullable

Example

package main

import (
	"encoding/json"
	"fmt"
	"go.portalnesia.com/nullable"
)

type JsonType struct {
	String nullable.String `json:"string"`
}

func main() {
	dataJson := []byte(`{"string":null}`)

    var data JsonType
    if err := json.Unmarshal(dataJson,&data); err != nil {
        panic(err)
    }
	
    fmt.Println(data.String)
}

Go References

pkg.go.dev/go.portalnesia.com/nullable

Documentation

Overview

Copyright © Portalnesia <[email protected]>

Copyright © Portalnesia <[email protected]>

Copyright © Portalnesia <[email protected]>

Copyright © Portalnesia <[email protected]>

Copyright © Portalnesia <[email protected]>

Copyright © Portalnesia <[email protected]>

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bool

type Bool struct {
	Present bool // Present is true if key is present in json
	Valid   bool // Valid is true if value is not null and valid bool
	Data    bool
}

Bool represents a bool that may be null or not present in json at all.

func NewBool

func NewBool(data bool, presentValid ...bool) Bool

func NewBoolPtr

func NewBoolPtr(data bool, presentValid ...bool) *Bool

func (Bool) FiberConverter

func (Bool) FiberConverter(value string) reflect.Value

func (Bool) MarshalBSON added in v1.0.5

func (i Bool) MarshalBSON() ([]byte, error)

MarshalBSON implements bson.Marshaler interface.

func (Bool) MarshalJSON

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

MarshalJSON implements json.Marshaler interface.

func (Bool) Null

func (d Bool) Null() null.Bool

func (Bool) Ptr

func (d Bool) Ptr() *bool

func (*Bool) Scan

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

sql.Value interface

func (*Bool) UnmarshalBSON added in v1.0.5

func (b *Bool) UnmarshalBSON(data []byte) error

UnmarshalBSON implements bson.Marshaler interface.

func (*Bool) UnmarshalJSON

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

UnmarshalJSON implements json.Marshaler interface.

func (Bool) Value

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

sql.Value interface

type Float

type Float struct {
	Present bool // Present is true if key is present in json
	Valid   bool // Valid is true if value is not null and valid float
	Data    float64
}

Float represents a float that may be null or not present in json at all.

func NewFloat

func NewFloat(data float64, presentValid ...bool) Float

func NewFloatPtr

func NewFloatPtr(data float64, presentValid ...bool) *Float

func (Float) FiberConverter

func (Float) FiberConverter(value string) reflect.Value

func (Float) MarshalBSON added in v1.0.5

func (i Float) MarshalBSON() ([]byte, error)

MarshalBSON implements bson.Marshaler interface.

func (Float) MarshalJSON

func (i Float) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler interface.

func (Float) Null

func (d Float) Null() null.Float

func (Float) Ptr

func (d Float) Ptr() *float64

func (*Float) Scan

func (d *Float) Scan(value interface{}) error

sql.Value interface

func (*Float) UnmarshalBSON added in v1.0.5

func (f *Float) UnmarshalBSON(data []byte) error

UnmarshalBSON implements bson.Marshaler interface.

func (*Float) UnmarshalJSON

func (f *Float) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Marshaler interface.

func (Float) Value

func (d Float) Value() (driver.Value, error)

sql.Value interface

type GeomMultiPolygon

type GeomMultiPolygon struct {
	geojson.MultiPolygon
}

func (*GeomMultiPolygon) Scan

func (g *GeomMultiPolygon) Scan(input interface{}) error

func (*GeomMultiPolygon) UnmarshalBSON added in v1.0.5

func (g *GeomMultiPolygon) UnmarshalBSON(data []byte) error

type GeomPoint

type GeomPoint struct {
	geojson.Point
}

func (*GeomPoint) Scan

func (g *GeomPoint) Scan(input interface{}) error

func (*GeomPoint) UnmarshalBSON added in v1.0.5

func (g *GeomPoint) UnmarshalBSON(data []byte) error

type GeomPolygon

type GeomPolygon struct {
	geojson.Polygon
}

func (*GeomPolygon) Scan

func (g *GeomPolygon) Scan(input interface{}) error

func (*GeomPolygon) UnmarshalBSON added in v1.0.5

func (g *GeomPolygon) UnmarshalBSON(data []byte) error

type Int

type Int struct {
	Present bool // Present is true if key is present in json
	Valid   bool // Valid is true if value is not null and valid int64
	Data    int64
}

func NewInt

func NewInt(data int64, presentValid ...bool) Int

func NewIntPtr

func NewIntPtr(data int64, presentValid ...bool) *Int

func (Int) FiberConverter

func (Int) FiberConverter(value string) reflect.Value

func (Int) MarshalBSON added in v1.0.5

func (i Int) MarshalBSON() ([]byte, error)

MarshalBSON implements bson.Marshaler interface.

func (Int) MarshalJSON

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

MarshalJSON implements json.Marshaler interface. Bug: Marshal undefined value

func (Int) Null

func (d Int) Null() null.Int

func (Int) Ptr

func (d Int) Ptr() *int64

func (*Int) Scan

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

sql.Value interface

func (*Int) UnmarshalBSON added in v1.0.5

func (i *Int) UnmarshalBSON(data []byte) error

UnmarshalBSON implements bson.Marshaler interface.

func (*Int) UnmarshalJSON

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

UnmarshalJSON implements json.Marshaler interface.

func (Int) Value

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

sql.Value interface

type String

type String struct {
	Present bool // Present is true if key is present in json
	Valid   bool // Valid is true if value is not null and valid string
	Data    string
}

String represents a string that may be null or not present in json at all.

func NewString

func NewString(data string, presentValid ...bool) String

func NewStringPtr

func NewStringPtr(data string, presentValid ...bool) *String

func (String) FiberConverter

func (String) FiberConverter(value string) reflect.Value

func (String) MarshalBSON added in v1.0.5

func (i String) MarshalBSON() ([]byte, error)

MarshalBSON implements bson.Marshaler interface.

func (String) MarshalJSON

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

MarshalJSON implements json.Marshaler interface.

func (String) Null

func (d String) Null() null.String

func (String) Ptr

func (d String) Ptr() *string

func (*String) Scan

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

sql.Value interface

func (*String) UnmarshalBSON added in v1.0.5

func (s *String) UnmarshalBSON(data []byte) error

UnmarshalBSON implements bson.Marshaler interface.

func (*String) UnmarshalJSON

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

UnmarshalJSON implements json.Marshaler interface.

func (String) Value

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

sql.Value interface

type StringArray

type StringArray struct {
	Present bool // Present is true if key is present in json
	Valid   bool // Valid is true if value is not null and valid string
	Data    pg.StringArray
}

func NewStringArray

func NewStringArray(data pg.StringArray, presentValid ...bool) StringArray

func NewStringArrayPtr

func NewStringArrayPtr(data pg.StringArray, presentValid ...bool) *StringArray

func (StringArray) FiberConverter added in v1.0.3

func (StringArray) FiberConverter(value string) reflect.Value

func (StringArray) GormDBDataType

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

GormDBDataType gorm db data type

func (StringArray) GormDataType

func (StringArray) GormDataType() string

GormDataType gorm common data type

func (StringArray) MarshalBSON added in v1.0.5

func (d StringArray) MarshalBSON() ([]byte, error)

MarshalBSON implements bson.Marshaler interface.

func (StringArray) MarshalJSON

func (d StringArray) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler interface.

func (StringArray) Ptr

func (d StringArray) Ptr() *pg.StringArray

func (*StringArray) Scan

func (d *StringArray) Scan(value interface{}) error

func (*StringArray) UnmarshalBSON added in v1.0.5

func (d *StringArray) UnmarshalBSON(data []byte) error

UnmarshalBSON implements bson.Marshaler interface.

func (*StringArray) UnmarshalJSON

func (d *StringArray) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Marshaler interface.

func (StringArray) Value

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

Value sql.Value interface

type Time

type Time struct {
	Present bool // Present is true if key is present in json
	Valid   bool // Valid is true if value is not null and valid string
	Data    time.Time
	// contains filtered or unexported fields
}

func NewTime

func NewTime(data time.Time, presentValid ...bool) Time

func NewTimePtr

func NewTimePtr(data time.Time, presentValid ...bool) *Time

func (Time) Carbon added in v1.0.5

func (d Time) Carbon() carbon.Carbon

func (Time) FiberConverter

func (Time) FiberConverter(value string) reflect.Value

func (Time) MarshalBSON added in v1.0.5

func (d Time) MarshalBSON() ([]byte, error)

MarshalBSON implements bson.Marshaler interface.

func (Time) MarshalJSON

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

MarshalJSON implements json.Marshaler interface.

func (Time) Null

func (d Time) Null() null.Time

func (Time) Ptr

func (d Time) Ptr() *time.Time

func (*Time) Scan

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

sql.Value interface

func (*Time) UnmarshalBSON added in v1.0.5

func (d *Time) UnmarshalBSON(data []byte) error

UnmarshalBSON implements bson.Marshaler interface.

func (*Time) UnmarshalJSON

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

UnmarshalJSON implements json.Marshaler interface.

func (Time) Value

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

sql.Value interface

type Type

type Type[D any] struct {
	Present bool // Present is true if key is present in json
	Valid   bool // Valid is true if value is not null and valid string
	Data    D
}

func NewType

func NewType[T any](data T, presentValid ...bool) Type[T]

func NewTypePtr

func NewTypePtr[T any](data T, presentValid ...bool) *Type[T]

func (Type[D]) Datatypes

func (d Type[D]) Datatypes() *datatypes.JSONType[D]

func (Type[D]) FiberConverter added in v1.0.3

func (Type[D]) FiberConverter(value string) reflect.Value

func (Type[D]) GormDBDataType

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

GormDBDataType gorm db data type

func (Type[D]) GormDataType

func (Type[D]) GormDataType() string

GormDataType gorm common data type

func (Type[D]) MarshalBSON added in v1.0.5

func (i Type[D]) MarshalBSON() ([]byte, error)

MarshalBSON implements bson.Marshaler interface.

func (Type[D]) MarshalJSON

func (i Type[D]) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler interface. Bug: Marshal undefined value

func (Type[D]) Ptr

func (d Type[D]) Ptr() *D

func (*Type[D]) Scan

func (d *Type[D]) Scan(value interface{}) error

func (*Type[D]) UnmarshalBSON added in v1.0.5

func (i *Type[D]) UnmarshalBSON(data []byte) error

UnmarshalBSON implements bson.Marshaler interface.

func (*Type[D]) UnmarshalJSON

func (i *Type[D]) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Marshaler interface.

func (Type[D]) Value

func (d Type[D]) Value() (driver.Value, error)

Value sql.Value interface

Jump to

Keyboard shortcuts

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