surrealtypes

package
v0.0.0-...-0281c1b Latest Latest
Warning

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

Go to latest
Published: Mar 18, 2025 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Footgun: Those aren't paranthesis, brackets, or anything alike.
	// ... they're _unicode_. o.o
	SRIDOpen  rune = '⟨'
	SRIDClose rune = '⟩'
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Any

type Any = any

TODO: Properly work this out From and with: https://surrealdb.com/docs/surrealql/datamodel ## Simple ### basic

type ArrayOf

type ArrayOf[T any] struct {
	Values []T
}

ArrayOf is a generic type that implements JSON and SQL interfaces.

func NewArray

func NewArray[T any](obj []T) ArrayOf[T]

func (ArrayOf[T]) MarshalJSON

func (a ArrayOf[T]) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler

func (*ArrayOf[T]) Scan

func (a *ArrayOf[T]) Scan(value interface{}) error

Scan implements sql.Scanner, parsing JSON arrays from []byte.

func (*ArrayOf[T]) UnmarshalJSON

func (a *ArrayOf[T]) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unmarshaler

func (ArrayOf[T]) Value

func (a ArrayOf[T]) Value() (driver.Value, error)

Value implements driver.Valuer, returning a JSON-encoded value.

type AutoID

type AutoID struct {
	Table string
	Thing AutoIDFunc
}

TODO: this currently does not retrive the ID.

func (*AutoID) MarshalJSON

func (id *AutoID) MarshalJSON() ([]byte, error)

func (*AutoID) Scan

func (id *AutoID) Scan(src any) error

func (AutoID) SurrealString

func (id AutoID) SurrealString() string

func (*AutoID) UnmarshalJSON

func (id *AutoID) UnmarshalJSON(b []byte) error

func (*AutoID) Value

func (id *AutoID) Value() (driver.Value, error)

type AutoIDFunc

type AutoIDFunc string
const (
	AutoIDRand AutoIDFunc = "rand()"
	AutoIDUUID AutoIDFunc = "uuid()"
	AutoIDULID AutoIDFunc = "ulid()"
)

type BasicTypes

type BasicTypes interface {
	Bool | Bytes | String
}

## Type Constraints

type Bool

type Bool = bool

type Bytes

type Bytes = []byte

type ComplexTypes

type ComplexTypes interface {
	Object | Set | Geometry
}

type DateTime

type DateTime struct {
	time.Time
}

func (*DateTime) MarshalSurreal

func (t *DateTime) MarshalSurreal() ([]byte, error)

func (*DateTime) Scan

func (t *DateTime) Scan(src any) error

func (*DateTime) Value

func (t *DateTime) Value() (driver.Value, error)

type Decimal

type Decimal struct {
	*big.Float
}

func (Decimal) MarshalJSON

func (bf Decimal) MarshalJSON() ([]byte, error)

func (*Decimal) Scan

func (d *Decimal) Scan(src any) error

func (*Decimal) UnmarshalJSON

func (bf *Decimal) UnmarshalJSON(data []byte) error

func (*Decimal) Value

func (d *Decimal) Value() (driver.Value, error)

type Duration

type Duration struct {
	time.Duration
}

func (*Duration) MarshalJSON

func (d *Duration) MarshalJSON() ([]byte, error)

func (*Duration) Scan

func (d *Duration) Scan(src any) error

func (*Duration) UnmarshalJSON

func (d *Duration) UnmarshalJSON(b []byte) error

func (*Duration) Value

func (d *Duration) Value() (driver.Value, error)

type Float

type Float = float64

type FloatID

type FloatID struct {
	Table string
	Thing float64
}

func (*FloatID) MarshalJSON

func (id *FloatID) MarshalJSON() ([]byte, error)

func (*FloatID) Scan

func (id *FloatID) Scan(src any) error

func (FloatID) SurrealString

func (id FloatID) SurrealString() string

func (*FloatID) UnmarshalJSON

func (id *FloatID) UnmarshalJSON(b []byte) error

func (*FloatID) Value

func (id *FloatID) Value() (driver.Value, error)

type Geometry

type Geometry = geojson.Geometry

### Objects type Object = gjson.Result

type IDThings

type IDThings interface {
	int64 | float64 | []rune | gjson.Result | ulid.ULID | uuid.UUID | time.Time | AutoIDFunc
}

type Int

type Int = int

### numbers

type IntID

type IntID struct {
	Table string
	Thing int64
}

func (*IntID) MarshalJSON

func (id *IntID) MarshalJSON() ([]byte, error)

func (*IntID) Scan

func (id *IntID) Scan(src any) error

func (IntID) SurrealString

func (id IntID) SurrealString() string

func (*IntID) UnmarshalJSON

func (id *IntID) UnmarshalJSON(b []byte) error

func (*IntID) Value

func (id *IntID) Value() (driver.Value, error)

type Literal

type Literal = []rune // TODO: Go has no type unions...so what do?

type NumberTypes

type NumberTypes interface {
	Int | Float | Decimal
}
type EmptyTypes interface {
	Null | None
}

type Object

type Object map[string]interface{}

func (*Object) MarshalJSON

func (o *Object) MarshalJSON() ([]byte, error)

func (*Object) Scan

func (o *Object) Scan(value interface{}) error

func (*Object) UnmarshalJSON

func (o *Object) UnmarshalJSON(b []byte) error

func (*Object) Value

func (o *Object) Value() (driver.Value, error)

type ObjectID

type ObjectID struct {
	Table string
	Thing gjson.Result
}

func (*ObjectID) MarshalJSON

func (id *ObjectID) MarshalJSON() ([]byte, error)

func (*ObjectID) Scan

func (id *ObjectID) Scan(src any) error

func (ObjectID) SurrealString

func (id ObjectID) SurrealString() string

SurrealString implements SurrealDBRecordID.

func (*ObjectID) UnmarshalJSON

func (id *ObjectID) UnmarshalJSON(b []byte) error

func (*ObjectID) Value

func (id *ObjectID) Value() (driver.Value, error)

type Range

type Range = any // TODO: this needs a custom type

type RawID

type RawID struct {
	Table string
	Thing []rune
}

func (*RawID) MarshalJSON

func (id *RawID) MarshalJSON() ([]byte, error)

func (*RawID) Scan

func (id *RawID) Scan(src any) error

func (RawID) SurrealString

func (id RawID) SurrealString() string

SurrealString implements SurrealDBRecordID.

func (*RawID) UnmarshalJSON

func (id *RawID) UnmarshalJSON(b []byte) error

func (*RawID) Value

func (id *RawID) Value() (driver.Value, error)

type Record

type Record[T any] struct {
	// contains filtered or unexported fields
}

func NewRecord

func NewRecord[T any](obj T) Record[T]

func (*Record[T]) Get

func (r *Record[T]) Get() (*T, bool)

func (*Record[T]) GetID

func (r *Record[T]) GetID() (SurrealDBRecordID, bool)

func (*Record[T]) HasData

func (r *Record[T]) HasData() bool

func (*Record[T]) HasID

func (r *Record[T]) HasID() bool

func (*Record[T]) MarshalJSON

func (r *Record[T]) MarshalJSON() ([]byte, error)

func (*Record[T]) Scan

func (r *Record[T]) Scan(src any) error

func (*Record[T]) UnmarshalJSON

func (r *Record[T]) UnmarshalJSON(b []byte) error

func (*Record[T]) Value

func (r *Record[T]) Value() (driver.Value, error)

type Records

type Records[T any] struct {
	// contains filtered or unexported fields
}

func NewRecords

func NewRecords[T any](obj []T) Records[T]

func (*Records[T]) Get

func (r *Records[T]) Get() ([]*Record[T], bool)

func (*Records[T]) Len

func (r *Records[T]) Len() int

func (*Records[T]) MarshalJSON

func (r *Records[T]) MarshalJSON() ([]byte, error)

func (*Records[T]) Scan

func (r *Records[T]) Scan(src any) error

func (*Records[T]) UnmarshalJSON

func (r *Records[T]) UnmarshalJSON(b []byte) error

func (*Records[T]) Value

func (r *Records[T]) Value() (driver.Value, error)

type Set

type Set = []interface{} // TODO: User specified, thus technically generic

type Record = Object // TODO: Actually, this isn't true. in json its string, in db its object!

type String

type String = string

type StringArray

type StringArray = []string

type StringID

type StringID struct {
	Table string
	Thing string
}

func (*StringID) MarshalJSON

func (id *StringID) MarshalJSON() ([]byte, error)

func (*StringID) Scan

func (id *StringID) Scan(src any) error

func (StringID) SurrealString

func (id StringID) SurrealString() string

SurrealString implements SurrealDBRecordID.

func (*StringID) UnmarshalJSON

func (id *StringID) UnmarshalJSON(b []byte) error

func (*StringID) Value

func (id *StringID) Value() (driver.Value, error)

type SurrealDBRecordID

type SurrealDBRecordID interface {
	SurrealString() string
}

func ParseID

func ParseID(in string) (SurrealDBRecordID, error)

type SurrealMarshalable

type SurrealMarshalable interface {
	MarshalSurreal() ([]byte, error)
}

type TimeTypes

type TimeTypes interface {
	DateTime | Duration
}

type Types

type Types interface {
	BasicTypes | NumberTypes | TimeTypes | ComplexTypes
}

type ULIDID

type ULIDID struct {
	Table string
	Thing ulid.ULID
}

func (*ULIDID) MarshalJSON

func (id *ULIDID) MarshalJSON() ([]byte, error)

func (*ULIDID) Scan

func (id *ULIDID) Scan(src any) error

func (ULIDID) SurrealString

func (id ULIDID) SurrealString() string

func (*ULIDID) UnmarshalJSON

func (id *ULIDID) UnmarshalJSON(b []byte) error

func (*ULIDID) Value

func (id *ULIDID) Value() (driver.Value, error)

type UUIDID

type UUIDID struct {
	Table string
	Thing uuid.UUID
}

func (*UUIDID) MarshalJSON

func (id *UUIDID) MarshalJSON() ([]byte, error)

func (*UUIDID) Scan

func (id *UUIDID) Scan(src any) error

func (UUIDID) SurrealString

func (id UUIDID) SurrealString() string

func (*UUIDID) UnmarshalJSON

func (id *UUIDID) UnmarshalJSON(b []byte) error

func (*UUIDID) Value

func (id *UUIDID) Value() (driver.Value, error)

Notes

Bugs

  • %T may result in pretty.formatter from github.com/kr/pretty ... fml.

Jump to

Keyboard shortcuts

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