driver

package
v0.0.0-...-b75375f Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2014 License: MPL-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// No capabilities
	CAP_NONE Capability = 0
	// Can perform JOINs
	CAP_JOIN = 1 << iota
	// Can perform OR queries
	CAP_OR
	// Can create transactions
	CAP_TRANSACTION
	// Can begin/commit/rollback a transaction
	CAP_BEGIN
	// Can automatically assign ids to rows
	CAP_AUTO_ID
	// Automatically assigned ids increase sequentially
	CAP_AUTO_INCREMENT
	// Provides eventual consistency rather than strong consistency
	CAP_EVENTUAL
	// Supports having a primary key
	CAP_PK
	// Primary key can be formed from multiple fields
	CAP_COMPOSITE_PK
	// Can have non-PK unique fields, enforce by the backend.
	CAP_UNIQUE
	// Can have database level defaults.
	CAP_DEFAULTS
	// Can have database level defaults for TEXT fields (unbounded strings).
	CAP_DEFAULTS_TEXT
)

Variables

View Source
var (
	ErrInTransaction    = errors.New("already in transaction")
	ErrNotInTransaction = errors.New("not in transaction")
	ErrFinished         = errors.New("transaction was already finished")
)

Functions

func Direct

func Direct(val reflect.Value) reflect.Value

Direct descends into val.Elem() as long as val.Type().Kind() is reflect.Ptr and returns the result.

func IsFunc

func IsFunc(val string) bool

func IsZero

func IsZero(val reflect.Value) bool

func Register

func Register(name string, opener Opener)

func SplitFuncArgs

func SplitFuncArgs(val string) (string, []string)

func UnescapeDefault

func UnescapeDefault(val string) string

Types

type Capability

type Capability int

Capability indicates the capabilities of an ORM driver.

type Conn

type Conn interface {
	Query(m Model, q query.Q, sort []Sort, limit int, offset int) Iter
	Count(m Model, q query.Q, limit int, offset int) (uint64, error)
	Exists(m Model, q query.Q) (bool, error)
	Insert(m Model, data interface{}) (Result, error)
	Operate(m Model, q query.Q, ops []*operation.Operation) (Result, error)
	Update(m Model, q query.Q, data interface{}) (Result, error)
	Upsert(m Model, q query.Q, data interface{}) (Result, error)
	Delete(m Model, q query.Q) (Result, error)
	Connection() interface{}
}

type Driver

type Driver interface {
	Conn
	Check() error
	Initialize(m []Model) error
	Begin() (Tx, error)
	Transaction(f func(Driver) error) error
	Close() error
	// True if the driver can perform upserts
	Upserts() bool
	// List of struct tags to be read, in decreasing order of priority.
	// The first non-empty tag is used.
	Tags() []string
	Capabilities() Capability
	HasFunc(fname string, retType reflect.Type) bool
}

type Fields

type Fields struct {
	*structs.Struct
	// Quoted mangled names of the fields, including the table
	// name (e.g. "table"."field").
	QuotedNames []string
	// Fields which should be omitted when they are empty
	OmitEmpty []bool
	// Fields which should become null when they are empty
	NullEmpty []bool
	// The index of the primary (-1 if there's no pk)
	PrimaryKey int
	// True if the primary key is an integer type with auto_increment
	AutoincrementPk bool
	// The fields which make the composite primary key, if any
	CompositePrimaryKey []int
	// Model methods called by the ORM
	Methods *Methods
	// Other models referenced by this model. The key
	// is the field name in this model.
	References map[string]*Reference
	// Default values. Key is field index, value is the default
	// which might be a reflect.Func with no arguments and one
	// return value or simply a value assignable to the field.
	Defaults map[int]reflect.Value
}

func (*Fields) DefaultValue

func (f *Fields) DefaultValue(idx int) interface{}

func (*Fields) HasDefault

func (f *Fields) HasDefault(idx int) bool

func (*Fields) IsSubfield

func (f *Fields) IsSubfield(field, parent []int) bool

type Iter

type Iter interface {
	Next(out ...interface{}) bool
	Err() error
	Close() error
}

type Join

type Join interface {
	Model() Model
	Type() JoinType
	Query() query.Q
}

type JoinType

type JoinType int
const (
	InnerJoin JoinType = iota
	OuterJoin
	LeftJoin
	RightJoin
)

type Methods

type Methods struct {
	// The address for the Load method. 0 if there's no Load method
	LoadPointer unsafe.Pointer
	// Wheter Load returns an error
	LoadReturns bool
	// The address for the Save method. 0 if there's no Save method
	SavePointer unsafe.Pointer
	// Wheter Save returns an error
	SaveReturns bool
}

func MakeMethods

func MakeMethods(typ reflect.Type) (m *Methods, err error)

func (*Methods) Load

func (m *Methods) Load(obj interface{}) error

func (*Methods) Save

func (m *Methods) Save(obj interface{}) error

type Model

type Model interface {
	Type() reflect.Type
	Table() string
	Fields() *Fields
	Indexes() []*index.Index
	Map(qname string) (string, reflect.Type, error)
	Skip() bool
	Join() Join
}

type Opener

type Opener func(url *config.URL) (Driver, error)

func Get

func Get(name string) Opener

type Reference

type Reference struct {
	Model Model
	Field string
}

type Result

type Result interface {
	LastInsertId() (int64, error)
	RowsAffected() (int64, error)
}

type Sort

type Sort interface {
	Field() string
	Direction() SortDirection
}

type SortDirection

type SortDirection int
const (
	// These constants are documented in the gnd.la/orm package
	DESC SortDirection = -1
	ASC                = 1
)

type Tx

type Tx interface {
	Conn
	Commit() error
	Rollback() error
}

Directories

Path Synopsis
Package datastore implements an App Engine datastore driver the Gondola's ORM.
Package datastore implements an App Engine datastore driver the Gondola's ORM.

Jump to

Keyboard shortcuts

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