data

package module
v1.2.3 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2023 License: MPL-2.0 Imports: 12 Imported by: 0

README

Data 👋

Description

Data is a Go package that provides data manipulations.

Requirements

Go 1.19 or above.

Getting Started

Installation

Run the following command to install the package:

go get github.com/leliuga/data

License

This project is licensed under the Mozilla Public License Version 2.0 License - see the LICENSE file for details.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	KindNames = map[Kind]string{
		KindReference: "Reference",
		KindBoolean:   "Boolean",
		KindDateTime:  "Datetime",
		KindDate:      "Date",
		KindFloat32:   "Float32",
		KindFloat64:   "Float64",
		KindID:        "Id",
		KindInet:      "Inet",
		KindUInt8:     "Uint8",
		KindUInt16:    "Uint16",
		KindUInt32:    "Uint32",
		KindUInt64:    "Uint64",
		KindInt8:      "Int8",
		KindInt16:     "Int16",
		KindInt32:     "Int32",
		KindInt64:     "Int64",
		KindString:    "String",
		KindTime:      "Time",
	}

	// ErrKindInvalid is returned when the data kind is invalid.
	ErrKindInvalid = errors.New("invalid data kind")
)

Functions

func ConflictKeys added in v1.2.1

func ConflictKeys[T any](a, b Map[T]) (conflicts []string)

ConflictKeys returns a map of conflicting keys between the two maps.

func DiffKeys added in v1.2.1

func DiffKeys[T any](a, b Map[T]) (added, removed []string)

DiffKeys returns a map of added and removed keys between the two maps.

func Equal added in v1.2.1

func Equal(a, b any) bool

Equal returns whether the provided values are equal.

func Less added in v1.2.1

func Less(a, b any) bool

Less returns whether the first value is less than the second.

func More added in v1.2.1

func More(a, b any) bool

More returns whether the first value is more than the second.

func NotEqual added in v1.2.1

func NotEqual(a, b any) bool

NotEqual returns whether the provided values are not equal.

Types

type IModel added in v1.1.0

type IModel interface {
	// Validate makes `Model` validatable by implementing [validation.Validatable] interface.
	Validate() error
}

IModel defines a model interface.

type Kind

type Kind uint8

Kind defines a data kind.

const (
	KindInvalid   Kind = iota + 1 //
	KindReference                 // The `reference`scalar kind represents a reference to other structure Columns
	KindBoolean                   // The `boolean`  scalar kind represents                                                                        value `true` or `false`
	KindDateTime                  // The `datetime` scalar kind represents a date and time pairing in UTC                                         value `2023-01-25 10:10:10`
	KindDate                      // The `date`     scalar kind represents a date in UTC                                                          value `2023-01-25`
	KindFloat32                   // The `float32`  scalar kind represents an 32-bit signed double-precision floating-point                       value '1.2345'
	KindFloat64                   // The `float64`  scalar kind represents an 64-bit signed double-precision floating-point                       value '1.2345'
	KindID                        // The `id`       scalar kind represents a 128-bit hexadecimal                                                  value '7f9c24e8-3b12-4fef-91e0-56a2d5a246ec'
	KindInet                      // The `inet`     scalar kind represents an IPv4 or IPv6 address                                                value '192.168.0.1'
	KindUInt8                     // The `uint8`    scalar kind represents an unsigned  8-bit integers (0 to 255)                                 value '12345'
	KindUInt16                    // The `uint16`   scalar kind represents an unsigned 16-bit integers (0 to 65535)                               value '12345'
	KindUInt32                    // The `uint32`   scalar kind represents an unsigned 32-bit integers (0 to 4294967295)                          value '12345'
	KindUInt64                    // The `uint64`   scalar kind represents an unsigned 64-bit integers (0 to 18446744073709551615)                value '12345'
	KindInt8                      // The `int8`     scalar kind represents a signed  8-bit integers (-128 to 127)                                 value '-12'
	KindInt16                     // The `int16`    scalar kind represents a signed 16-bit integers (-32768 to 32767)                             value '-12'
	KindInt32                     // The `int32`    scalar kind represents a signed 32-bit integers (-2147483648 to 2147483647)                   value '-12'
	KindInt64                     // The `int64`    scalar kind represents a signed 64-bit integers (-9223372036854775808 to 9223372036854775807) value '-12'
	KindString                    // The `string`   scalar kind represents textual data a UTF‐8 character sequence                                value 'a1b2c3'
	KindTime                      // The `time`     scalar kind represents a time in UTC                                                          value `01:23:45.123456`
)

func DetectValueKind

func DetectValueKind(value any, convert bool) Kind

func MustParseKind

func MustParseKind(name string) Kind

MustParseKind parses data kind string or panics.

func ParseKind

func ParseKind(name string) Kind

ParseKind parses data kind string.

func (Kind) MarshalJSON

func (k Kind) MarshalJSON() ([]byte, error)

MarshalJSON data kind to json

func (Kind) String

func (k Kind) String() string

String data kind to string

func (*Kind) UnmarshalJSON

func (k *Kind) UnmarshalJSON(b []byte) error

UnmarshalJSON data kind from json

type Map added in v1.2.1

type Map[T any] map[string]T

Map defines a map of key:value. It implements Map.

func Merge added in v1.2.1

func Merge[T any](maps ...Map[T]) Map[T]

Merge merges the provided maps into a new map.

func NewMap added in v1.2.1

func NewMap[T any]() Map[T]

func ToMap added in v1.2.1

func ToMap[M ~map[K]T, K comparable, T any](m M) Map[T]

ToMap converts a map to a Map.

func (Map[T]) Clear added in v1.2.1

func (m Map[T]) Clear()

Clear clears the map.

func (Map[T]) Clone added in v1.2.1

func (m Map[T]) Clone() Map[T]

Clone returns a clone of the map.

func (Map[T]) Delete added in v1.2.1

func (m Map[T]) Delete(key string)

Delete deletes the value for the provided key.

func (Map[T]) Get added in v1.2.1

func (m Map[T]) Get(key string) T

Get returns the value for the provided key.

func (Map[T]) Has added in v1.2.1

func (m Map[T]) Has(key string) bool

Has returns whether the provided key exists in the map.

func (Map[T]) IsEmpty added in v1.2.1

func (m Map[T]) IsEmpty() bool

IsEmpty returns whether the map is empty.

func (Map[T]) Keys added in v1.2.1

func (m Map[T]) Keys() (keys []string)

Keys returns a slice of keys in the map.

func (Map[T]) Len added in v1.2.1

func (m Map[T]) Len() int

Len returns the length of the map.

func (Map[T]) Merge added in v1.2.1

func (m Map[T]) Merge(maps ...Map[T]) Map[T]

Merge merges the provided map into the current map.

func (Map[T]) Range added in v1.2.1

func (m Map[T]) Range(fn func(key string, value T) bool)

Range iterates over elements in the map.

func (Map[T]) Set added in v1.2.1

func (m Map[T]) Set(key string, value T)

Set sets the value for the provided key.

func (Map[T]) String added in v1.2.1

func (m Map[T]) String(sep, join string) string

String returns a string representation of the map.

func (Map[T]) Values added in v1.2.1

func (m Map[T]) Values() (values []T)

Values returns a slice of values in the map.

Directories

Path Synopsis
schema

Jump to

Keyboard shortcuts

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