xdb

package
v0.14.0 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2023 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MaxLenForName     = 64
	MaxLenForEmail    = 160
	MaxLenForShortURL = 256
)

Max values, common for strings

Variables

This section is empty.

Functions

func DbNameFromConnection

func DbNameFromConnection(conn string) string

DbNameFromConnection return DB name from connection

func IDString

func IDString(id uint64) string

IDString returns string id

func NullTime

func NullTime(val *time.Time) sql.NullTime

NullTime from *time.Time

func ParseUint

func ParseUint(id string) (uint64, error)

ParseUint returns id from the string

func String

func String(val *string) string

String returns string

func TimePtr

func TimePtr(val Time) *time.Time

TimePtr returns nil if time is zero, or pointer with a value

func Validate

func Validate(m interface{}) error

Validate returns error if the model is not valid

Types

type ID

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

ID defines a type to convert between internal uint64 and external string representations of ID

func MustID

func MustID(val string) ID

MustID returns ID or panics if the value is invalid

func NewID

func NewID(id uint64) ID

NewID returns ID

func ParseID

func ParseID(val string) ID

ParseID returns ID or empty if val is not valid ID

func (ID) Invalid

func (v ID) Invalid() bool

Invalid returns if ID is invalid

func (ID) IsZero

func (v ID) IsZero() bool

IsZero returns if ID is 0

func (ID) MarshalJSON

func (v ID) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler interface

func (*ID) Reset

func (v *ID) Reset()

Reset the value

func (*ID) Scan

func (v *ID) Scan(value any) error

Scan implements the Scanner interface.

func (*ID) Set

func (v *ID) Set(val string) error

Set the value

func (ID) String

func (v ID) String() string

func (ID) UInt64

func (v ID) UInt64() uint64

UInt64 returns uint64 value

func (*ID) UnmarshalJSON

func (v *ID) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface. The time is expected to be a quoted string in RFC 3339 format.

func (ID) Valid

func (v ID) Valid() bool

Valid returns if ID is valid

func (ID) Value

func (v ID) Value() (driver.Value, error)

Value implements the driver Valuer interface.

type IDArray

type IDArray []ID

IDArray defines a list of IDArray

func (*IDArray) Scan

func (n *IDArray) Scan(value any) error

Scan implements the Scanner interface for IDs

func (IDArray) Strings

func (n IDArray) Strings() []string

Strings returns string representation of IDs

func (IDArray) Value

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

Value implements the driver Valuer interface for IDs

type Metadata

type Metadata map[string]string

Metadata de/encodes the string map to/from a SQL string.

func (*Metadata) Scan

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

Scan implements the Scanner interface.

func (Metadata) Value

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

Value implements the driver Valuer interface.

type NULLString

type NULLString string

NULLString de/encodes the string a SQL string.

func (*NULLString) Scan

func (ns *NULLString) Scan(value interface{}) error

Scan implements the Scanner interface.

func (NULLString) Value

func (ns NULLString) Value() (driver.Value, error)

Value implements the driver Valuer interface.

type SQL

type SQL interface {
	// QueryContext executes a query that returns rows, typically a SELECT.
	// The args are for any placeholder parameters in the query.
	QueryContext(ctx context.Context, query string, args ...any) (*sql.Rows, error)
	// QueryRowContext executes a query that is expected to return at most one row.
	// QueryRowContext always returns a non-nil value. Errors are deferred until
	// Row's Scan method is called.
	// If the query selects no rows, the *Row's Scan will return ErrNoRows.
	// Otherwise, the *Row's Scan scans the first selected row and discards
	// the rest.
	QueryRowContext(ctx context.Context, query string, args ...any) *sql.Row
	// ExecContext executes a query without returning any rows.
	// The args are for any placeholder parameters in the query.
	ExecContext(ctx context.Context, query string, args ...any) (sql.Result, error)
}

SQL provides interface for Db operations

type Scanner

type Scanner interface {
	Scan(dest ...any) error
}

Scanner is DB scan interface

type Strings

type Strings []string

Strings de/encodes the string slice to/from a SQL string.

func (*Strings) Scan

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

Scan implements the Scanner interface.

func (Strings) Value

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

Value implements the driver Valuer interface.

type Time

type Time time.Time

Time implements sql.Time functionality and always returns UTC

func FromNow

func FromNow(after time.Duration) Time

FromNow returns Time in UTC after now, with Second presicions

func FromUnixMilli

func FromUnixMilli(tm int64) Time

FromUnixMilli returns Time from Unix milliseconds elapsed since January 1, 1970 UTC.

func Now

func Now() Time

Now returns Time in UTC

func ParseTime

func ParseTime(val string) Time

ParseTime returns Time from RFC3339 format

func UTC

func UTC(t time.Time) Time

UTC returns Time in UTC,

func (Time) Add

func (ns Time) Add(after time.Duration) Time

Add returns Time in UTC after this thime, with Second presicions

func (Time) IsNil

func (ns Time) IsNil() bool

IsNil reports whether t represents the zero time instant, January 1, year 1, 00:00:00 UTC.

func (Time) IsZero

func (ns Time) IsZero() bool

IsZero reports whether t represents the zero time instant, January 1, year 1, 00:00:00 UTC.

func (Time) MarshalJSON

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

MarshalJSON implements the json.Marshaler interface. The time is a quoted string in RFC 3339 format, with sub-second precision added if present.

func (Time) Ptr

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

Ptr returns pointer to Time, or nil if the time is zero

func (*Time) Scan

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

Scan implements the Scanner interface.

func (Time) String

func (ns Time) String() string

String returns string in RFC3339 format, if it's Zero time, an empty string is returned

func (Time) UTC

func (ns Time) UTC() time.Time

UTC returns t with the location set to UTC.

func (Time) UnixMilli

func (ns Time) UnixMilli() int64

UnixMilli returns t as a Unix time, the number of milliseconds elapsed since January 1, 1970 UTC.

func (*Time) UnmarshalJSON

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

UnmarshalJSON implements the json.Unmarshaler interface. The time is expected to be a quoted string in RFC 3339 format.

func (Time) Value

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

Value implements the driver Valuer interface.

type Validator

type Validator interface {
	// Validate returns error if the model is not valid
	Validate() error
}

Validator provides schema validation interface

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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