fields

package module
v0.0.0-...-f8add74 Latest Latest
Warning

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

Go to latest
Published: Jul 5, 2016 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var UUIDv4 = postgres.UUID().NotNull()

Functions

func NormalizeEmail

func NormalizeEmail(email string) (string, error)

NormalizeEmail will check that the email has at least one @ - it will then lowercase both the local name and domain

Types

type Email

type Email string

Email is an email type

func NewEmail

func NewEmail(email string) Email

NewEmail creates a new Email

func (*Email) Normalize

func (email *Email) Normalize() error

Normalize will perform an in-place normalization of the email, only returning an email if normalization fails

func (*Email) Scan

func (email *Email) Scan(value interface{}) error

Scan converts an SQL value into an Email

func (*Email) UnmarshalJSON

func (email *Email) UnmarshalJSON(text []byte) error

UnmarshalJSON for emails trims spaces

func (Email) Value

func (email Email) Value() (driver.Value, error)

Value returns the email as a string

type ImmutableFK

type ImmutableFK struct {
	ID    uint64
	Name  string
	Table *sol.TableElem
}

ImmutableFK is a foreign key. It embeds an ID and adds a column name (such as remote_id) and foreign key table (such as Remotes)

func (ImmutableFK) Exists

func (fk ImmutableFK) Exists(conn sol.Conn) bool

Exists returns true if the foreign key table has an entry with the given ID

func (ImmutableFK) MarshalJSON

func (fk ImmutableFK) MarshalJSON() ([]byte, error)

MarshalJSON returns the inner ID

func (ImmutableFK) Modify

func (fk ImmutableFK) Modify(table sol.Tabular) error

Modify implements the sol.Modifier interface

func (*ImmutableFK) Scan

func (fk *ImmutableFK) Scan(value interface{}) error

Scan implements the database/sql.Scanner interface

func (*ImmutableFK) SetTable

func (fk *ImmutableFK) SetTable(name string, table *sol.TableElem)

SetTable sets the column name and table of the foreign key

func (*ImmutableFK) UnmarshalJSON

func (fk *ImmutableFK) UnmarshalJSON(b []byte) error

UnmarshalJSON allows an ID to be set once, but only once TODO Why not use UnmarshalText? https://github.com/golang/go/issues/9650

func (ImmutableFK) Value

func (fk ImmutableFK) Value() (driver.Value, error)

Value implements the database/sql/driver.Valuer interface

type JSON

type JSON map[string]interface{}

func (JSON) Get

func (j JSON) Get(key string) string

Get returns the value as a string

func (JSON) Int64

func (j JSON) Int64(key string) (int64, error)

Int64 returns the value as an int64

func (*JSON) Scan

func (j *JSON) Scan(value interface{}) error

Scan converts an SQL value into JSON

func (JSON) Value

func (j JSON) Value() (driver.Value, error)

Value returns the JSON formatted for insert into SQL

type NullableFK

type NullableFK struct {
	ImmutableFK
	Valid bool
}

NullableFK is a foreign key that can be NULL. It embeds an ImmutableFK

func (NullableFK) Exists

func (fk NullableFK) Exists(conn sol.Conn) bool

Exists returns true if the foreign key table has an entry with the given ID or the FK is NULL.

func (NullableFK) MarshalJSON

func (fk NullableFK) MarshalJSON() ([]byte, error)

MarshalJSON returns the JSON output of the FK

func (NullableFK) Modify

func (fk NullableFK) Modify(table sol.Tabular) error

Modify implements the sol.Modifier interface

func (*NullableFK) Scan

func (fk *NullableFK) Scan(value interface{}) error

Scan converts the raw SQL value into a NullableFK

func (*NullableFK) UnmarshalJSON

func (fk *NullableFK) UnmarshalJSON(b []byte) error

func (NullableFK) Value

func (fk NullableFK) Value() (driver.Value, error)

Value returns the FK ID or nil if the FK is not valid

type Serial

type Serial struct {
	ID uint64 `db:"id,omitempty" json:"id" xml:"ID"`
}

Serial is an embeddable type that can be used as a primary key for a table

func NewSerial

func NewSerial(id uint64) Serial

NewSerial creates a new Serial

func (Serial) Exists

func (serial Serial) Exists() bool

Exists returns true if the Pk is non-zero

func (Serial) GetID

func (serial Serial) GetID() uint64

GetID returns the ID as a uint64

func (Serial) Keys

func (serial Serial) Keys() []interface{}

func (Serial) Modify

func (serial Serial) Modify(table sol.Tabular) error

Modify implements the sol.Modifier interface

type Timestamp

type Timestamp struct {
	CreatedAt time.Time   `db:"created_at,omitempty" json:"created_at"`
	UpdatedAt pq.NullTime `db:"updated_at" json:"updated_at,omitempty"`
}

Timestamp records create and update timestamps.

func TimestampColumns

func TimestampColumns() Timestamp

TimestampColumns returns a Modifier suitable for inclusion in a Table

func (Timestamp) Age

func (ts Timestamp) Age() time.Duration

Age returns the duration since the timestamp was created.

func (Timestamp) LastActivity

func (ts Timestamp) LastActivity() time.Time

LastActivity returns the time of the lastest activity on the timestamp - either when it was updated or created. Updated is assumed to have always been at or after creation.

func (Timestamp) Modify

func (ts Timestamp) Modify(table sol.Tabular) error

func (*Timestamp) SetUpdatedAt

func (ts *Timestamp) SetUpdatedAt(when time.Time)

SetUpdatedAt sets the updated_at field

func (Timestamp) WasUpdated

func (ts Timestamp) WasUpdated() bool

Updated returns true if the timestamp has been updated

type URL

type URL string

URL is a URL field TODO Just boilerplate for now

func NewURL

func NewURL(url string) URL

NewURL creates a new URL

func (*URL) Scan

func (url *URL) Scan(value interface{}) error

Scan converts an SQL value into a URL

func (*URL) UnmarshalJSON

func (url *URL) UnmarshalJSON(text []byte) error

UnmarshalJSON

func (URL) Value

func (url URL) Value() (driver.Value, error)

Value returns the URL as a string

type UUID

type UUID [16]byte

func ParseUUID

func ParseUUID(s string) (UUID, error)

TODO require v4

func (UUID) Equals

func (uuid UUID) Equals(other UUID) bool

Equals returns true if the UUIDs are equal

func (UUID) Exists

func (uuid UUID) Exists() bool

Exists returns true if the UUID is a valid UUID

func (UUID) Keys

func (uuid UUID) Keys() []interface{}

func (UUID) MarshalJSON

func (uuid UUID) MarshalJSON() ([]byte, error)

TODO remove the nesting

func (UUID) Modify

func (uuid UUID) Modify(table sol.Tabular) error

func (*UUID) Scan

func (uuid *UUID) Scan(value interface{}) error

Scan converts an SQL value into a UUID

func (UUID) String

func (uuid UUID) String() string

String returns the string form of uuid, xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx , or "" if uuid is invalid.

func (*UUID) UnmarshalJSON

func (u *UUID) UnmarshalJSON(data []byte) error

func (UUID) Value

func (uuid UUID) Value() (driver.Value, error)

Value returns the UUID formatted for insert into SQL

Jump to

Keyboard shortcuts

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