orm

package
v0.0.0-...-eaf0aa9 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2014 License: BSD-3-Clause Imports: 11 Imported by: 5

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotConnected error = errors.New("Not connected to database")
)
View Source
var (
	ErrNotFound = errors.New("record not found")
)

Functions

func Bool

func Bool(b bool) *bool

func Byte

func Byte(b byte) *byte

func Duration

func Duration(d time.Duration) *time.Duration

func Float32

func Float32(f float32) *float32

func Float64

func Float64(f float64) *float64

func Int

func Int(i int) *int

func Int16

func Int16(i int16) *int16

func Int32

func Int32(i int32) *int32

func Int64

func Int64(i int64) *int64

func Int8

func Int8(i int8) *int8

func Is

func Is(b *bool) bool

func Rune

func Rune(r rune) *rune

func String

func String(s string) *string

func Time

func Time(t time.Time) *time.Time

func Uint

func Uint(u uint) *uint

func Uint16

func Uint16(u uint16) *uint16

func Uint32

func Uint32(u uint32) *uint32

func Uint64

func Uint64(u uint64) *uint64

func Uint8

func Uint8(u uint8) *uint8

Types

type Collection

type Collection interface {
	Name() string
	Count() (n int, err error)
	Drop() error

	Save(Record) error
	Find(Record) error
	Peek(Record) error
	Remove(Record) error

	Query(interface{}) Query
}

type Database

type Database interface {
	Name() string
	URL() *url.URL
	SystemInformation() string
	Version() string

	Connect() error
	Disconnect() error

	C(string) Collection
	GetCollectionName(r Record) string
	DropCollection(Record) error

	SetDebug(bool)
	UniqueId() string

	Save(Record) error
	Find(Record) error
	Peek(Record) error
	Remove(Record) error

	Query(Record) Query

	NewLogger(col, prefix string) io.Writer
}

A database connection

func NewDatabase

func NewDatabase(u *url.URL, name string) (Database, error)

factory method to instantiate database drivers based on the url scheme

func NewMongoDBDriver

func NewMongoDBDriver(u *url.URL, name string) (Database, error)

NewDatabaseDriver

type MongoDB

type MongoDB struct {
	Url      *url.URL
	Database *mgo.Database

	Session     *mgo.Session
	SessionInfo *mgo.BuildInfo
	// contains filtered or unexported fields
}

func NewMongoDB

func NewMongoDB(u *url.URL, name string) *MongoDB

func (*MongoDB) C

func (db *MongoDB) C(name string) Collection

func (*MongoDB) Connect

func (db *MongoDB) Connect() (err error)

func (*MongoDB) Disconnect

func (db *MongoDB) Disconnect() error

func (*MongoDB) DropCollection

func (db *MongoDB) DropCollection(r Record) error

func (*MongoDB) Find

func (db *MongoDB) Find(r Record) error

func (*MongoDB) GetCollectionName

func (db *MongoDB) GetCollectionName(r Record) string

func (*MongoDB) Name

func (db *MongoDB) Name() string

func (*MongoDB) NewLogger

func (db *MongoDB) NewLogger(col, prefix string) (logger io.Writer)

func (*MongoDB) Peek

func (db *MongoDB) Peek(r Record) error

func (*MongoDB) Query

func (db *MongoDB) Query(r Record) Query

func (*MongoDB) Remove

func (db *MongoDB) Remove(r Record) error

func (*MongoDB) Save

func (db *MongoDB) Save(r Record) error

func (*MongoDB) SetDebug

func (db *MongoDB) SetDebug(on bool)

func (*MongoDB) SystemInformation

func (db *MongoDB) SystemInformation() string

func (*MongoDB) URL

func (db *MongoDB) URL() *url.URL

func (*MongoDB) UniqueId

func (db *MongoDB) UniqueId() string

returns a unique id (may be sequential)

func (*MongoDB) Version

func (db *MongoDB) Version() string

type MongoDBCollection

type MongoDBCollection struct {
	*mgo.Collection
}

func (*MongoDBCollection) Drop

func (col *MongoDBCollection) Drop() error

func (*MongoDBCollection) Find

func (col *MongoDBCollection) Find(r Record) error

func (*MongoDBCollection) Name

func (col *MongoDBCollection) Name() string

func (*MongoDBCollection) Peek

func (col *MongoDBCollection) Peek(r Record) (err error)

func (*MongoDBCollection) Query

func (col *MongoDBCollection) Query(q interface{}) Query

func (*MongoDBCollection) Remove

func (col *MongoDBCollection) Remove(r Record) error

func (*MongoDBCollection) Save

func (col *MongoDBCollection) Save(r Record) error

type MongoDBLogger

type MongoDBLogger struct {
	Col    *mgo.Collection
	Prefix string
}

func (*MongoDBLogger) Write

func (l *MongoDBLogger) Write(p []byte) (n int, err error)

type MongoDBQuery

type MongoDBQuery struct {
	*mgo.Query
}

several methods promoted from mgo.Query implement perfect/db.Query

func (*MongoDBQuery) All

func (q *MongoDBQuery) All(result interface{}) (err error)

TODO: write custom driver for mongodb so that 'result' could be of type []Record

func (*MongoDBQuery) Exclude

func (q *MongoDBQuery) Exclude(fields ...string) Query

func (*MongoDBQuery) One

func (q *MongoDBQuery) One(result Record) (err error)

func (*MongoDBQuery) Select

func (q *MongoDBQuery) Select(fields ...string) Query

type NewDatabaseDriver

type NewDatabaseDriver func(*url.URL, string) (Database, error)

All DB drivers must implement a NewDatabaseDriver function They accept a connection url and an optional database name.

type Object

type Object struct {
	Id interface{} `bson:"_id,omitempty" json:"-"`
}

An object that can be stored in a database; implements the Record interface

func (*Object) GetDbId

func (o *Object) GetDbId() interface{}

func (*Object) SetDbId

func (o *Object) SetDbId(id interface{})

type Query

type Query interface {
	Count() (int, error)
	One(Record) error
	Select(...string) Query
	Exclude(...string) Query
	All(interface{}) error
}

type Record

type Record interface {
	GetDbId() interface{}
	SetDbId(interface{})
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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