gemini

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

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

Go to latest
Published: Jan 12, 2015 License: MIT Imports: 7 Imported by: 0

README

gemini

Eventually, gemini will be an orm for go which supports joins properly (as well as eager and lazy mode for them).

Also, gemini will support an in memory mode for testing your code such that it does not rely on the underlying database(s) that it uses.

Currently, development is ongoing and so no promises are made about stability.

Currently, I am not accepting any pull requests as I'm playing fast and loose with gemini.

A huge shout out needs to be made to coopernurse (github.com/coopernurse/gorp). Gorp influenced/influences gemini in many ways, and I do think it was one of the first, extremely useful ORMs in go.

Soon to come:

  • Criterions?

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	NoPrimaryKey  = errors.New("table has no primary keys")
	NoDbSpecified = errors.New("cannot perform action without a specified database (currently gemini knows about more/less than one")
	NoDbForStruct = errors.New("no database is specified for the given struct")
)
View Source
var TestMode = true

Functions

func CreateTableQueryFor

func CreateTableQueryFor(i interface{}, dialect Dialect) string

Types

type ColumnMapping

type ColumnMapping struct {
	// contains filtered or unexported fields
}

type DbDialect

type DbDialect int

type DbInfo

type DbInfo struct {
	Dialect   Dialect
	Db        *sql.DB
	MongoSesh *mgo.Session
	DbName    string
}

type Dialect

type Dialect interface {
	ToSqlType(val reflect.Type, maxsize int, isAutoIncr bool) string
	NextPlaceholder(curr int) (int, string)
}

type Gemini

type Gemini struct {
	Dbs []*sql.DB

	StructsMap map[string]*TableMap

	TablesToDb map[string]*sql.DB

	DbToDriver map[*sql.DB]Dialect

	// ugh adding these for the moment, table name -> db info
	TableToDatabaseInfo map[string]*DbInfo

	DatabaseInfo []*DbInfo
	// contains filtered or unexported fields
}

func NewGemini

func NewGemini(dbsInfo []*DbInfo) *Gemini

func (*Gemini) AddTable

func (g *Gemini) AddTable(i interface{}) error

func (*Gemini) AddTableToDb

func (g *Gemini) AddTableToDb(i interface{}, dbInfo *DbInfo) *Gemini

func (*Gemini) AddTableWithName

func (g *Gemini) AddTableWithName(i interface{}, tableName string) error

func (*Gemini) AddTableWithNameToDb

func (g *Gemini) AddTableWithNameToDb(
	i interface{},
	tableName string,
	dbInfo *DbInfo) *Gemini

func (*Gemini) CreateTableFor

func (g *Gemini) CreateTableFor(i interface{}, d Dialect) error

func (*Gemini) Delete

func (g *Gemini) Delete(i interface{}) error

func (*Gemini) Exec

func (g *Gemini) Exec(query string, args ...interface{}) (sql.Result, error)

func (*Gemini) ExecWithInfo

func (g *Gemini) ExecWithInfo(query string, info *DbInfo, args ...interface{}) (sql.Result, error)

func (*Gemini) Get

func (g *Gemini) Get(i interface{}, keys ...interface{}) error

func (*Gemini) Insert

func (g *Gemini) Insert(i interface{}) error

func (*Gemini) Select

func (g *Gemini) Select(i interface{}, query string, args ...interface{}) error

func (*Gemini) Update

func (g *Gemini) Update(i interface{}) error

type JoinInfoError

type JoinInfoError struct {
	// contains filtered or unexported fields
}

func (JoinInfoError) Error

func (j JoinInfoError) Error() string

type MongoDB

type MongoDB struct{}

////////// MongoDB ////////////

func (MongoDB) NextPlaceholder

func (m MongoDB) NextPlaceholder(curr int) (int, string)

func (MongoDB) ToSqlType

func (m MongoDB) ToSqlType(val reflect.Type, maxsize int, isAutoIncr bool) string

type MySQL

type MySQL struct{}

func (MySQL) NextPlaceholder

func (m MySQL) NextPlaceholder(curr int) (int, string)

func (MySQL) ToSqlType

func (m MySQL) ToSqlType(val reflect.Type, maxsize int, isAutoIncr bool) string

type PostgresDialect

type PostgresDialect struct{}

func (PostgresDialect) NextPlaceholder

func (p PostgresDialect) NextPlaceholder(curr int) (int, string)

func (PostgresDialect) ToSqlType

func (d PostgresDialect) ToSqlType(val reflect.Type, maxsize int, isAutoIncr bool) string

type SqliteDialect

type SqliteDialect struct{}

func (SqliteDialect) NextPlaceholder

func (s SqliteDialect) NextPlaceholder(curr int) (int, string)

func (SqliteDialect) ToSqlType

func (d SqliteDialect) ToSqlType(val reflect.Type, maxsize int, isAutoIncr bool) string

type TableInfo

type TableInfo struct{}

The sole purpose of TableInfo is to tag extra information you would like. For now the main use is to specify a table name different than the struct name - this can be done by setting, `name:"tableName"`

type TableMap

type TableMap struct {
	TableName           string
	StructName          string
	Fields              []ColumnMapping
	ColumnNameToMapping map[string]ColumnMapping
	// contains filtered or unexported fields
}

func TableMapFromStruct

func TableMapFromStruct(i interface{}, tableName string) *TableMap

func (*TableMap) HasPrimaryKey

func (t *TableMap) HasPrimaryKey() bool

func (*TableMap) PrimaryKey

func (t *TableMap) PrimaryKey() []reflect.StructField

Jump to

Keyboard shortcuts

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