gouda

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

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

Go to latest
Published: Apr 26, 2010 License: MIT Imports: 11 Imported by: 0

README

GoUDA : Go Unified Data Accessor

Gouda is an experimental ORM for Go.

Features (and planned features):

  • Backend agnostic (though at the moment it knows only how to connect to MySQL and XML files ...)
  • Nice syntax for querying (ex : MyModel.Where(gouda.F("i").Eq("j")).Where(gouda.F("a").Eq("b")).Order("c","ASC").First())
  • Not so intrusive...
  • Pure Go

Installing

You first need Thoj Mysql Client Library

$ git clone git://github.com/zetaben/gouda.git
$ cd gouda
$ make
$ make install

Usage

  1. Declare your structs as ModelInterface (by implementing all the interface methods or by embeding gouda.NullModel)
  2. Connect to your database backend (eg : gouda.OpenMysql("mysql://root:@localhost:3306/test_db"))
  3. Optional : Register your models using gouda.GetModelStore().RegisterModel(m)
  4. Use it !

Peruse through Model_test.go to view typical usages A sample application application can be found in misc directory

Known limitations

At the moment Gouda as the following limitations :

  • Connects only to mysql and XML files
  • limited support for associations (railslike HasMany, BelongsTo)
  • Knows only how to handle int and string attributes !
  • Connections needs to be registered in the store to be usable automatically...
  • Needs way more documentation !

Acknowlegments

This work is using work or ideas from other go projects :

Documentation

Index

Constants

View Source
const (
	EOOKind = iota
	NumberKind
	StringKind
	BooleanKind
	NullKind
	IntKind
	LongKind
)

Variables

This section is empty.

Functions

func Delete

func Delete(a interface{}) interface{}

func Equal

func Equal(v1, v2 Value) bool

func GetTableName

func GetTableName(m ModelInterface) string

func Less

func Less(v1, v2 Value) bool

func LessOrEqual

func LessOrEqual(v1, v2 Value) bool

func ModelName

func ModelName(m ModelInterface) (ret string)

func More

func More(v1, v2 Value) bool

func MoreOrEqual

func MoreOrEqual(v1, v2 Value) bool

func Refresh

func Refresh(a interface{}) interface{}

func Save

func Save(a interface{}) interface{}

Types

type Association

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

type AssociationKind

type AssociationKind int
const (
	BELONGS_TO AssociationKind = iota
	HAS_MANY
	HAS_ONE
	HAS_AND_BELONGS_TO_MANY
)

type Condition

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

func F

func F(field string) (c *Condition)

func (*Condition) Eq

func (c *Condition) Eq(v interface{}) *Condition

func (*Condition) Gt

func (c *Condition) Gt(v interface{}) *Condition

func (*Condition) GtEq

func (c *Condition) GtEq(v interface{}) *Condition

func (*Condition) IsNotNull

func (c *Condition) IsNotNull() *Condition

func (*Condition) IsNull

func (c *Condition) IsNull() *Condition

func (*Condition) Lt

func (c *Condition) Lt(v interface{}) *Condition

func (*Condition) LtEq

func (c *Condition) LtEq(v interface{}) *Condition

func (*Condition) NEq

func (c *Condition) NEq(v interface{}) *Condition

func (*Condition) Or

func (c *Condition) Or(c2 *Condition) *Condition

func (*Condition) String

func (c *Condition) String() string

func (*Condition) Value

func (c *Condition) Value(v interface{}) *Condition

type Connection

type Connection interface {
	Open(connectionString string) bool
	Query(r *Relation) *vector.Vector
	Close()
}

func OpenMysql

func OpenMysql(conStr string) Connection

func OpenXML

func OpenXML(conStr string) Connection

type ConnectionStore

type ConnectionStore []*Connection

func GetConnectionStore

func GetConnectionStore() *ConnectionStore

func (*ConnectionStore) Last

func (cs *ConnectionStore) Last() *Connection

func (*ConnectionStore) RegisterConnection

func (cs *ConnectionStore) RegisterConnection(c *Connection) *Connection

type Model

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

func M

func M(m ModelInterface) *Model

func (*Model) All

func (m *Model) All() []interface{}

func (*Model) Attributes

func (m *Model) Attributes() map[string]reflect.Type

func (*Model) AttributesNames

func (m *Model) AttributesNames() (ret []string)

func (*Model) BelongsToKey

func (m *Model) BelongsToKey(am *Model, name, key string)

func (*Model) Count

func (m *Model) Count(fields ...[]string) int

func (*Model) Delete

func (m *Model) Delete(a interface{}) interface{}

func (*Model) First

func (m *Model) First() interface{}

func (*Model) GetAssociated

func (m *Model) GetAssociated(name string, in interface{}) interface{}

func (*Model) HasManyKey

func (m *Model) HasManyKey(am *Model, name, key string)

func (*Model) HasONEKey

func (m *Model) HasONEKey(am *Model, name, key string)

func (*Model) Last

func (m *Model) Last() interface{}

func (*Model) Order

func (m *Model) Order(x, y string) *ModelRelation

func (*Model) Refresh

func (m *Model) Refresh(a interface{}) interface{}

func (*Model) Save

func (m *Model) Save(a interface{}) interface{}

func (*Model) TableName

func (m *Model) TableName() string

* Model *

func (*Model) Where

func (m *Model) Where(x *Condition) *ModelRelation

type ModelInterface

type ModelInterface interface {
	TableName() string
	Identifier() string
}

* Types *

type ModelRelation

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

func (*ModelRelation) All

func (r *ModelRelation) All() []interface{}

func (*ModelRelation) Count

func (r *ModelRelation) Count(fields ...[]string) int

func (*ModelRelation) First

func (r *ModelRelation) First() interface{}

func (*ModelRelation) Last

func (r *ModelRelation) Last() interface{}

func (*ModelRelation) Order

func (r *ModelRelation) Order(x, y string) *ModelRelation

func (*ModelRelation) Where

func (r *ModelRelation) Where(x *Condition) *ModelRelation

type ModelStore

type ModelStore map[string]*Model

func GetModelStore

func GetModelStore() *ModelStore

func (*ModelStore) RegisterModel

func (st *ModelStore) RegisterModel(m ModelInterface) *Model

func (*ModelStore) RegisterModelWithConnection

func (st *ModelStore) RegisterModelWithConnection(m ModelInterface, conn *Connection) *Model

type MysqlConnector

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

func (*MysqlConnector) Close

func (e *MysqlConnector) Close()

func (*MysqlConnector) Open

func (e *MysqlConnector) Open(connectionString string) bool

func (*MysqlConnector) Query

func (e *MysqlConnector) Query(r *Relation) *vector.Vector

type NullModel

type NullModel struct{}

func (NullModel) Identifier

func (n NullModel) Identifier() string

func (NullModel) TableName

func (n NullModel) TableName() string

type OperandKind

type OperandKind int
const (
	NULL OperandKind = iota
	EQUAL
	NOTEQUAL
	ISNOTNULL
	ISNULL
	GREATER
	LOWER
	GREATEROREQUAL
	LOWEROREQUAL
	OR
)

type Relation

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

func From

func From(t interface{}) (r *Relation)

func NewRelation

func NewRelation(t interface{}) (r *Relation)

func (*Relation) Count

func (r *Relation) Count(fields []string) *Relation

func (*Relation) Delete

func (r *Relation) Delete() *Relation

func (*Relation) First

func (r *Relation) First() *Relation

func (*Relation) Insert

func (r *Relation) Insert(mp map[string]Value) *Relation

func (*Relation) Limit

func (r *Relation) Limit(offset, count int) *Relation

func (*Relation) Order

func (r *Relation) Order(field, direction string) *Relation

func (*Relation) String

func (r *Relation) String() string

func (*Relation) Table

func (r *Relation) Table(t string) *Relation

func (*Relation) Update

func (r *Relation) Update(mp map[string]Value, identifier string, id int) *Relation

func (*Relation) Where

func (r *Relation) Where(s *Condition) *Relation

type RequestKind

type RequestKind int
const (
	SELECT RequestKind = iota
	UPDATE
	INSERT
	COUNT
	DELETE
)

type SysInt

type SysInt int

func (SysInt) Value

func (i SysInt) Value() (ii *_Int)

type SysString

type SysString string

func (SysString) Value

func (i SysString) Value() (ii *_String)

type Value

type Value interface {
	Kind() int
	Number() float64
	String() SysString
	Bool() bool
	Int() SysInt
}

type ValueVector

type ValueVector struct {
	vector.Vector
	// contains filtered or unexported fields
}

func (*ValueVector) Less

func (v *ValueVector) Less(i, j int) bool

type WriteValue

type WriteValue interface {
	SetNumber(float64)
	SetString(SysString)
	SetBool(bool)
	SetInt(SysInt)
}

type XMLConnector

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

func (*XMLConnector) Close

func (e *XMLConnector) Close()

func (*XMLConnector) Commit

func (e *XMLConnector) Commit()

func (*XMLConnector) CreateTable

func (e *XMLConnector) CreateTable(table string) *XMLTable

func (*XMLConnector) CreateTableWithoutId

func (e *XMLConnector) CreateTableWithoutId(table string) *XMLTable

func (*XMLConnector) Open

func (e *XMLConnector) Open(connectionString string) bool

func (*XMLConnector) Query

func (e *XMLConnector) Query(r *Relation) *vector.Vector

func (*XMLConnector) Table

func (e *XMLConnector) Table(table string) *XMLTable

type XMLTable

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

func (*XMLTable) AddAttribute

func (e *XMLTable) AddAttribute(name string, typ int)

func (*XMLTable) Attributes

func (e *XMLTable) Attributes() map[string]int

func (*XMLTable) Data

func (e *XMLTable) Data() *ValueVector

func (*XMLTable) Insert

func (e *XMLTable) Insert(val map[string]Value)

unprotected

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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