persist

package
v0.0.0-...-a8bc1c0 Latest Latest
Warning

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

Go to latest
Published: Jan 3, 2020 License: BSD-3-Clause Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	StoreOptionNone             = StoreOptions(0)
	StoreOptionStoreReferences  = StoreOptions(1 << 0)
	StoreOptionStoreRelated     = StoreOptions(1<<1) | StoreOptionStoreReferences
	StoreOptionDeleteReferences = StoreOptions(1 << 2)
	StoreOptionDeleteOrphans    = StoreOptions(1<<3) | StoreOptionDeleteReferences
	StoreOptionCascade          = StoreOptionStoreReferences | StoreOptionStoreRelated | StoreOptionDeleteReferences | StoreOptionDeleteOrphans
	StoreOptionReserved         = StoreOptions(0xffff) // bits reserved to the `hp/db/persist` package
	StoreUserOption             = 17                   // base for user options
)
View Source
const (
	FetchOptionNone         = FetchOptions(0)
	FetchOptionFetchRelated = FetchOptions(1 << 0)
	FetchOptionCascade      = FetchOptionFetchRelated
	FetchOptionConcurrent   = FetchOptions(1 << 1) // sub-fetches may be performed concurrently
	FetchOptionReserved     = FetchOptions(0xffff) // bits reserved to the `hp/db/persist` package
	FetchUserOption         = 17                   // base for user options
)

Variables

This section is empty.

Functions

func IsEmpty

func IsEmpty(v interface{}) bool

Is this interface "empty"

func Mapping

func Mapping(t reflect.Type) (*mapping, error)

*

  • Obtain a cached mapping or create a mapping

func Scanner

func Scanner(v interface{}) *scanner

*

  • Obtain a struct mapping

Types

type Columns

type Columns map[string]interface{}

func (Columns) Deref

func (c Columns) Deref() Columns

Produce a new map of columns by dereferencing every value in the receiver, each of which is expected to be a pointer and will panic if not

func (Columns) KeysVals

func (c Columns) KeysVals() ([]string, []interface{})

Produce slices of keys and values whose indices correspond to each other

type DeletesReferences

type DeletesReferences interface {
	// Delete dependent entity relationships, but not the entities
	DeleteReferences(interface{}, StoreOptions, godb.Context) error
}

type DeletesRelated

type DeletesRelated interface {
	// Delete dependent entities
	DeleteRelated(interface{}, StoreOptions, godb.Context) error
}

Implemented by persisters with relationships

type FetchOptions

type FetchOptions uint32

Fetch options

type FetchesRelated

type FetchesRelated interface {
	// Fetch dependent entities
	FetchRelated(interface{}, FetchOptions, godb.Context) error
}

Implemented by persisters with relationships

type FetchesRelatedExtra

type FetchesRelatedExtra interface {
	// Fetch dependent entities
	FetchRelatedExtra(interface{}, Columns, FetchOptions, godb.Context) error
}

Implemented by persisters with relationships that support extra properties (e.g., for foreign keys)

type ForeignEntity

type ForeignEntity interface {
	// Obtain the foreign key that identifies this entity
	ForeignKey() interface{}
}

Implemented by foreign entities

type GeneratesIdentifiers

type GeneratesIdentifiers interface {
	// Determine if this entity is transient or not. Within the scope of a single store operation, this method
	// will only be called by the ORM before calling GenerateId (if necessary) and setting the generated identifier.
	IsTransient(interface{}, godb.Context) (bool, error)
	// Generate and set identifiers as necessary for the provided entity
	GenerateId(interface{}, godb.Context) (interface{}, error)
}

Implemented by persisters that explicitly generate identifiers

type Ident

type Ident interface {
	// Produce a new, unique identifier
	New() interface{}
}

Identifier type

type Iter

type Iter interface {
	Next() bool
	Scan(interface{}) error
	Close() error
}

An iterator

type ORM

type ORM interface {
	Context(godb.Context) godb.Context
	DefaultContext() godb.Context

	StoreEntity(Persister, interface{}, StoreOptions, godb.Context) error
	CountEntities(Persister, godb.Context, string, ...interface{}) (int, error)
	FetchEntity(Persister, interface{}, FetchOptions, godb.Context, string, ...interface{}) error
	FetchEntities(Persister, interface{}, FetchOptions, godb.Context, string, ...interface{}) error
	IterEntities(Persister, reflect.Type, FetchOptions, godb.Context, string, ...interface{}) (*iter, error)
	DeleteEntity(Persister, interface{}, StoreOptions, godb.Context) error

	StoreRelated(Persister, interface{}, StoreOptions, godb.Context) error
	FetchRelated(Persister, interface{}, Columns, FetchOptions, godb.Context) error
	StoreReferences(Persister, interface{}, StoreOptions, godb.Context) error
	DeleteRelated(Persister, interface{}, StoreOptions, godb.Context) error
	DeleteReferences(Persister, interface{}, StoreOptions, godb.Context) error
}

An ORM

func New

func New(cxt godb.Context) ORM

Create a persister

type Operation

type Operation int
const (
	Read Operation = iota
	Write
)

type PersistentMapping

type PersistentMapping interface {
	// Obtain the entity's primary key column names.
	PrimaryKeys() []string
	// Obtain the entity's column names.
	Columns() []string
	// Obtain the persistent identifier for an entity. If this identifier is nil or empty the entity is considered transient.
	PersistentId(interface{}) interface{}
	// Set the persistent identifier for an entity, e.g., when inserting.
	SetPersistentId(interface{}, interface{}) error
	// Generate a new persistent identifier.
	NewPersistentId(interface{}) interface{}
	// Obtain a relational column-to-value mapping of this entity's values, EXCLUDING the primary key, which is the persistent id.
	PersistentValues(interface{}) (Columns, error)
	// Obtain scanning destinaions for the provided ordered relational columns INCLUDING the primary key. This weird interface is an artifact of sql.Rows.Scan().
	ValueDestinations(interface{}, []string) ([]interface{}, Columns, error)
}

Implemented by entities that define explicit mappings

type Persister

type Persister interface {
	// Obtain the persistent table name.
	Table() string
}

Implemented by persisters

type Range

type Range struct {
	Location int
	Length   int
}

A range

type StoreOptions

type StoreOptions uint32

Store options

type StoresReferences

type StoresReferences interface {
	// Persist relationships for dependent entities, but not the entities
	StoreReferences(interface{}, StoreOptions, godb.Context) error
}

type StoresRelated

type StoresRelated interface {
	// Persist dependent entities
	StoreRelated(interface{}, StoreOptions, godb.Context) error
}

Implemented by persisters with relationships

Jump to

Keyboard shortcuts

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