models

package
v0.0.0-...-78dbd8a Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func PtrToStr

func PtrToStr[T any](v *T) string

PtrToStr lets us print pointers for debug purposes

func SliceToStr

func SliceToStr[T any](v []T) string

SliceToStr lets us print slices for debug purposes, and know if they are nil or not

Types

type AccountCompatible

type AccountCompatible struct {
	ID         uint64           `json:"id" db:"id" ksql:"id"`
	Name       string           `json:"name" db:"name" ksql:"name"`
	Email      string           `json:"email" db:"email" ksql:"email"`
	Active     bool             `json:"active" db:"active" ksql:"active"`
	FavColor   *string          `json:"fav_color" db:"fav_color" ksql:"fav_color"`       // Can be null // Could also use sql.NullString or Nullable instead of *string
	FavNumbers Array[int]       `json:"fav_numbers" db:"fav_numbers" ksql:"fav_numbers"` // Can be null
	Properties *json.RawMessage `json:"properties" db:"properties" ksql:"properties"`    // Can be null // Could also use []byte instead of *json.RawMessage
	CreatedAt  time.Time        `json:"created_at" db:"created_at" ksql:"created_at"`
}

AccountCompatible is not as nice as AccountIdeal, because it has to use a specialized version of FavNumbers because the helper library can't directly scan a postgres array to a golang []int. This is usually because the helper library is forced to use the stdlib version of pgx.

func (AccountCompatible) String

func (a AccountCompatible) String() string

type AccountIdeal

type AccountIdeal struct {
	ID         uint64           `json:"id" db:"id" ksql:"id"`
	Name       string           `json:"name" db:"name" ksql:"name"`
	Email      string           `json:"email" db:"email" ksql:"email"`
	Active     bool             `json:"active" db:"active" ksql:"active"`
	FavColor   *string          `json:"fav_color" db:"fav_color" ksql:"fav_color"`       // Can be null // Could also use sql.NullString or Nullable instead of *string
	FavNumbers []int            `json:"fav_numbers" db:"fav_numbers" ksql:"fav_numbers"` // Can be null
	Properties *json.RawMessage `json:"properties" db:"properties" ksql:"properties"`    // Can be null // Could also use []byte instead of *json.RawMessage
	CreatedAt  time.Time        `json:"created_at" db:"created_at" ksql:"created_at"`
}

AccountIdeal is the ideal model for an "accounts" row we would like to use, with hope that our driver and helper library can directly use this.

func (AccountIdeal) String

func (a AccountIdeal) String() string

type Array

type Array[T any] []T

Array is a wrapper that allows scanning a postgres Array into a golang slice

func (Array[T]) Get

func (a Array[T]) Get() []T

func (*Array[T]) Scan

func (a *Array[T]) Scan(src any) error

func (Array[T]) Value

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

type Filters

type Filters struct {
	Names     []string
	Active    *bool
	FavColors []string
}

Filters exists to test out dynamic querying

type Nullable

type Nullable[T any] struct {
	sql.Null[T]
}

Nullable wraps sql.Null to provide a String method

func (Nullable[T]) String

func (n Nullable[T]) String() string

Jump to

Keyboard shortcuts

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