Documentation
¶
Overview ¶
Package gomodel is an ORM that provides the resources to define data models and a database-abstraction API that lets you create, retrieve, update and delete objects.
Index ¶
- func ClearRegistry()
- func Databases() map[string]Database
- func Register(apps ...AppSettings)
- func Registry() map[string]*Application
- func Start(options map[string]Database) error
- func Stop() error
- type AppSettings
- type Application
- type BooleanField
- func (f BooleanField) DBColumn(name string) string
- func (f BooleanField) DataType(dvr string) string
- func (f BooleanField) DefaultValue() (Value, bool)
- func (f BooleanField) DisplayValue(val Value) string
- func (f BooleanField) DriverValue(v Value, dvr string) (interface{}, error)
- func (f BooleanField) HasIndex() bool
- func (f BooleanField) IsAuto() bool
- func (f BooleanField) IsAutoNow() bool
- func (f BooleanField) IsAutoNowAdd() bool
- func (f BooleanField) IsNull() bool
- func (f BooleanField) IsPK() bool
- func (f BooleanField) IsUnique() bool
- func (f BooleanField) Recipient() interface{}
- func (f BooleanField) Value(rec interface{}) Value
- type Builder
- type CharField
- func (f CharField) DBColumn(name string) string
- func (f CharField) DataType(driver string) string
- func (f CharField) DefaultValue() (Value, bool)
- func (f CharField) DisplayValue(val Value) string
- func (f CharField) DriverValue(val Value, dvr string) (interface{}, error)
- func (f CharField) HasIndex() bool
- func (f CharField) IsAuto() bool
- func (f CharField) IsAutoNow() bool
- func (f CharField) IsAutoNowAdd() bool
- func (f CharField) IsNull() bool
- func (f CharField) IsPK() bool
- func (f CharField) IsUnique() bool
- func (f CharField) Recipient() interface{}
- func (f CharField) Value(rec interface{}) Value
- type Choice
- type Conditioner
- type Container
- type ContainerError
- type Database
- type DatabaseError
- type DateField
- func (f DateField) DBColumn(name string) string
- func (f DateField) DataType(dvr string) string
- func (f DateField) DefaultValue() (Value, bool)
- func (f DateField) DisplayValue(val Value) string
- func (f DateField) DriverValue(v Value, dvr string) (interface{}, error)
- func (f DateField) HasIndex() bool
- func (f DateField) IsAuto() bool
- func (f DateField) IsAutoNow() bool
- func (f DateField) IsAutoNowAdd() bool
- func (f DateField) IsNull() bool
- func (f DateField) IsPK() bool
- func (f DateField) IsUnique() bool
- func (f DateField) MarshalJSON() ([]byte, error)
- func (f DateField) Recipient() interface{}
- func (f *DateField) UnmarshalJSON(data []byte) error
- func (f DateField) Value(rec interface{}) Value
- type DateTimeField
- func (f DateTimeField) DBColumn(name string) string
- func (f DateTimeField) DataType(dvr string) string
- func (f DateTimeField) DefaultValue() (Value, bool)
- func (f DateTimeField) DisplayValue(val Value) string
- func (f DateTimeField) DriverValue(v Value, dvr string) (interface{}, error)
- func (f DateTimeField) HasIndex() bool
- func (f DateTimeField) IsAuto() bool
- func (f DateTimeField) IsAutoNow() bool
- func (f DateTimeField) IsAutoNowAdd() bool
- func (f DateTimeField) IsNull() bool
- func (f DateTimeField) IsPK() bool
- func (f DateTimeField) IsUnique() bool
- func (f DateTimeField) MarshalJSON() ([]byte, error)
- func (f DateTimeField) Recipient() interface{}
- func (f DateTimeField) Value(rec interface{}) Value
- type Dispatcher
- type Engine
- type ErrorTrace
- type Field
- type Fields
- type GenericQuerySet
- func (qs GenericQuerySet) Count() (int64, error)
- func (qs GenericQuerySet) Delete() (int64, error)
- func (qs GenericQuerySet) Exclude(c Conditioner) QuerySet
- func (qs GenericQuerySet) Exists() (bool, error)
- func (qs GenericQuerySet) Filter(c Conditioner) QuerySet
- func (qs GenericQuerySet) Get(c Conditioner) (*Instance, error)
- func (qs GenericQuerySet) Load() ([]*Instance, error)
- func (qs GenericQuerySet) Model() *Model
- func (qs GenericQuerySet) New(m *Model, parent QuerySet) QuerySet
- func (qs GenericQuerySet) Only(fields ...string) QuerySet
- func (qs GenericQuerySet) Query() (Query, error)
- func (qs GenericQuerySet) Slice(start int64, end int64) ([]*Instance, error)
- func (qs GenericQuerySet) Update(container Container) (int64, error)
- func (qs GenericQuerySet) WithContainer(container Container) QuerySet
- func (qs GenericQuerySet) WithDB(database string) QuerySet
- func (qs GenericQuerySet) WithTx(tx *Transaction) QuerySet
- func (qs GenericQuerySet) Wrap(parent GenericQuerySet) QuerySet
- type Getter
- type Indexes
- type Instance
- func (i Instance) Container() Container
- func (i Instance) Delete() error
- func (i Instance) DeleteOn(target interface{}) error
- func (i Instance) Display(name string) string
- func (i Instance) Get(name string) Value
- func (i Instance) GetIf(name string) (val Value, hasField bool)
- func (i Instance) Model() *Model
- func (i Instance) Save(fields ...string) error
- func (i Instance) SaveOn(target interface{}, fields ...string) error
- func (i Instance) Set(name string, val Value) error
- func (i Instance) SetValues(values Container) error
- type IntegerField
- func (f IntegerField) DBColumn(name string) string
- func (f IntegerField) DataType(dvr string) string
- func (f IntegerField) DefaultValue() (Value, bool)
- func (f IntegerField) DisplayValue(val Value) string
- func (f IntegerField) DriverValue(v Value, dvr string) (interface{}, error)
- func (f IntegerField) HasIndex() bool
- func (f IntegerField) IsAuto() bool
- func (f IntegerField) IsAutoNow() bool
- func (f IntegerField) IsAutoNowAdd() bool
- func (f IntegerField) IsNull() bool
- func (f IntegerField) IsPK() bool
- func (f IntegerField) IsUnique() bool
- func (f IntegerField) Recipient() interface{}
- func (f IntegerField) Value(rec interface{}) Value
- type Manager
- func (m Manager) All() QuerySet
- func (m Manager) Create(values Container) (*Instance, error)
- func (m Manager) CreateOn(target interface{}, values Container) (*Instance, error)
- func (m Manager) Exclude(c Conditioner) QuerySet
- func (m Manager) Filter(c Conditioner) QuerySet
- func (m Manager) Get(c Conditioner) (*Instance, error)
- func (m Manager) GetQuerySet() QuerySet
- func (m Manager) WithContainer(container Container) QuerySet
- type MockedEngine
- func (e MockedEngine) AddColumns(model *Model, fields Fields) error
- func (e MockedEngine) AddIndex(m *Model, name string, fields ...string) error
- func (e MockedEngine) BeginTx() (Engine, error)
- func (e MockedEngine) Calls(method string) int
- func (e MockedEngine) CommitTx() error
- func (e MockedEngine) CountRows(m *Model, opt QueryOptions) (int64, error)
- func (e MockedEngine) CreateTable(model *Model, force bool) error
- func (e MockedEngine) DB() *sql.DB
- func (e MockedEngine) DeleteRows(m *Model, opt QueryOptions) (int64, error)
- func (e MockedEngine) DropColumns(model *Model, fields ...string) error
- func (e MockedEngine) DropIndex(model *Model, name string) error
- func (e MockedEngine) DropTable(model *Model) error
- func (e MockedEngine) Exists(m *Model, opt QueryOptions) (bool, error)
- func (e MockedEngine) GetRows(model *Model, opt QueryOptions) (Rows, error)
- func (e MockedEngine) InsertRow(model *Model, values Values) (int64, error)
- func (e MockedEngine) RenameTable(old *Model, new *Model) error
- func (e MockedEngine) Reset()
- func (e MockedEngine) RollbackTx() error
- func (e MockedEngine) SelectQuery(m *Model, opt QueryOptions) (Query, error)
- func (e MockedEngine) Start(db Database) (Engine, error)
- func (e MockedEngine) Stop() error
- func (e MockedEngine) Tx() *sql.Tx
- func (e MockedEngine) TxSupport() bool
- func (e MockedEngine) UpdateRows(model *Model, values Values, options QueryOptions) (int64, error)
- type MockedEngineArgs
- type MockedEngineResults
- type Model
- func (m *Model) AddField(name string, field Field) error
- func (m *Model) AddIndex(name string, fields ...string) error
- func (m Model) App() *Application
- func (m Model) Container() Container
- func (m Model) Fields() Fields
- func (m Model) Indexes() Indexes
- func (m Model) Name() string
- func (m *Model) Register(app *Application) error
- func (m *Model) RemoveField(name string) error
- func (m *Model) RemoveIndex(name string) error
- func (m *Model) SetupIndexes() error
- func (m *Model) SetupPrimaryKey() error
- func (m Model) Table() string
- type MultipleObjectsError
- type NullInt32
- type NullTime
- type ObjectNotFoundError
- type Options
- type PostgresEngine
- func (e PostgresEngine) AddColumns(model *Model, fields Fields) error
- func (e PostgresEngine) AddIndex(m *Model, name string, fields ...string) error
- func (e PostgresEngine) BeginTx() (Engine, error)
- func (e PostgresEngine) CommitTx() error
- func (e PostgresEngine) CountRows(m *Model, opt QueryOptions) (int64, error)
- func (e PostgresEngine) CreateTable(model *Model, force bool) error
- func (e PostgresEngine) DB() *sql.DB
- func (e PostgresEngine) DeleteRows(m *Model, opt QueryOptions) (int64, error)
- func (e PostgresEngine) DropColumns(model *Model, fields ...string) error
- func (e PostgresEngine) DropIndex(model *Model, name string) error
- func (e PostgresEngine) DropTable(model *Model) error
- func (e PostgresEngine) Exists(m *Model, opt QueryOptions) (bool, error)
- func (e PostgresEngine) GetRows(model *Model, opt QueryOptions) (Rows, error)
- func (e PostgresEngine) InsertRow(model *Model, values Values) (int64, error)
- func (e PostgresEngine) RenameTable(old *Model, new *Model) error
- func (e PostgresEngine) RollbackTx() error
- func (e PostgresEngine) SelectQuery(m *Model, opt QueryOptions) (Query, error)
- func (e PostgresEngine) Start(db Database) (Engine, error)
- func (e PostgresEngine) Stop() error
- func (e PostgresEngine) Tx() *sql.Tx
- func (e PostgresEngine) TxSupport() bool
- func (e PostgresEngine) UpdateRows(model *Model, values Values, options QueryOptions) (int64, error)
- type Q
- func (q Q) And(next Conditioner) Conditioner
- func (q Q) AndNot(next Conditioner) Conditioner
- func (q Q) Conditions() map[string]Value
- func (q Q) Next() (Conditioner, bool, bool)
- func (q Q) Or(next Conditioner) Conditioner
- func (q Q) OrNot(next Conditioner) Conditioner
- func (q Q) Root() (Conditioner, bool)
- type Query
- type QueryOptions
- type QuerySet
- type QuerySetError
- type Rows
- type Setter
- type SqliteEngine
- func (e SqliteEngine) AddColumns(model *Model, fields Fields) error
- func (e SqliteEngine) AddIndex(m *Model, name string, fields ...string) error
- func (e SqliteEngine) BeginTx() (Engine, error)
- func (e SqliteEngine) CommitTx() error
- func (e SqliteEngine) CountRows(m *Model, opt QueryOptions) (int64, error)
- func (e SqliteEngine) CreateTable(model *Model, force bool) error
- func (e SqliteEngine) DB() *sql.DB
- func (e SqliteEngine) DeleteRows(m *Model, opt QueryOptions) (int64, error)
- func (e SqliteEngine) DropColumns(model *Model, fields ...string) error
- func (e SqliteEngine) DropIndex(model *Model, name string) error
- func (e SqliteEngine) DropTable(model *Model) error
- func (e SqliteEngine) Exists(m *Model, opt QueryOptions) (bool, error)
- func (e SqliteEngine) GetRows(model *Model, opt QueryOptions) (Rows, error)
- func (e SqliteEngine) InsertRow(model *Model, values Values) (int64, error)
- func (e SqliteEngine) RenameTable(old *Model, new *Model) error
- func (e SqliteEngine) RollbackTx() error
- func (e SqliteEngine) SelectQuery(m *Model, opt QueryOptions) (Query, error)
- func (e SqliteEngine) Start(db Database) (Engine, error)
- func (e SqliteEngine) Stop() error
- func (e SqliteEngine) Tx() *sql.Tx
- func (e SqliteEngine) TxSupport() bool
- func (e SqliteEngine) UpdateRows(model *Model, values Values, options QueryOptions) (int64, error)
- type TimeField
- func (f TimeField) DBColumn(name string) string
- func (f TimeField) DataType(dvr string) string
- func (f TimeField) DefaultValue() (Value, bool)
- func (f TimeField) DisplayValue(val Value) string
- func (f TimeField) DriverValue(v Value, dvr string) (interface{}, error)
- func (f TimeField) HasIndex() bool
- func (f TimeField) IsAuto() bool
- func (f TimeField) IsAutoNow() bool
- func (f TimeField) IsAutoNowAdd() bool
- func (f TimeField) IsNull() bool
- func (f TimeField) IsPK() bool
- func (f TimeField) IsUnique() bool
- func (f TimeField) MarshalJSON() ([]byte, error)
- func (f TimeField) Recipient() interface{}
- func (f *TimeField) UnmarshalJSON(data []byte) error
- func (f TimeField) Value(rec interface{}) Value
- type Transaction
- type Value
- type Values
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Register ¶
func Register(apps ...AppSettings)
Register validates the given application settings and their models and adds them to the registry. The function will panic on any validation error.
func Registry ¶
func Registry() map[string]*Application
Registry returns a map containing all the registered applications.
Types ¶
type AppSettings ¶
type AppSettings struct { // Name is the application name, which must be unique. Name string // Path must be an existing directory path or blank if migrations won't be // managed by the gomodel/migration package. If relative, the full path will // be constructed from $GOPATH/src. Path string // Models is the list of models that will be registered to the application. Models []*Model }
AppSettings holds the options te register a new application.
func NewApp ¶
func NewApp(name string, path string, models ...*Model) AppSettings
NewApp returns an application settings struct constructed from the given arguments, ready to registered using the Register function.
The name is the applicatoin name, which must be unique.
The path must be an existing directory path or blank if migrations won't be managed by the gomodel/migration package. If relative, the full path will be constructed from $GOPATH/src.
The last argument is the list of models that will be registered to the app.
type Application ¶
type Application struct {
// contains filtered or unexported fields
}
Application holds a registered application and the validated models ready to interact with the database.
func (Application) FullPath ¶
func (app Application) FullPath() string
FullPath returns the full path to the migrations directory.
func (Application) Models ¶
func (app Application) Models() map[string]*Model
Models returns a map of models registered to the application.
func (Application) Path ¶
func (app Application) Path() string
Path returns the migrations path for the application.
type BooleanField ¶
type BooleanField struct { // Null is true if the field can have null values. Null bool `json:",omitempty"` // Blank is true if the field is not required. Only used for validation. Blank bool `json:",omitempty"` // Index is true if the field column should be indexed. Index bool `json:",omitempty"` // Column is the name of the db column. If blank, it will be the field name. Column string `json:",omitempty"` // Default is the default value for the field. Blank for no default. Default bool `json:",omitempty"` // DefaultFalse is true if false is the field default value. DefaultFalse bool `json:",omitempty"` }
BooleanField implements the Field interface for true/false fields.
func (BooleanField) DBColumn ¶
func (f BooleanField) DBColumn(name string) string
DBColumn implements the DBColumn method of the Field interface.
func (BooleanField) DataType ¶
func (f BooleanField) DataType(dvr string) string
DataType implements the DataType method of the Field interface.
func (BooleanField) DefaultValue ¶
func (f BooleanField) DefaultValue() (Value, bool)
DefaultValue implements the DefaultValue method of the Field interface.
func (BooleanField) DisplayValue ¶
func (f BooleanField) DisplayValue(val Value) string
DisplayValue implements the DisplayValue method of the Field interface.
func (BooleanField) DriverValue ¶
func (f BooleanField) DriverValue(v Value, dvr string) (interface{}, error)
DriverValue implements the DriverValue method of the Field interface.
func (BooleanField) HasIndex ¶
func (f BooleanField) HasIndex() bool
HasIndex implements the HasIndex method of the Field interface.
func (BooleanField) IsAuto ¶
func (f BooleanField) IsAuto() bool
IsAuto implements the IsAuto method of the Field interface.
func (BooleanField) IsAutoNow ¶
func (f BooleanField) IsAutoNow() bool
IsAutoNow implements the IsAutoNow method of the Field interface.
func (BooleanField) IsAutoNowAdd ¶
func (f BooleanField) IsAutoNowAdd() bool
IsAutoNowAdd implements the IsAutoNowAdd method of the Field interface.
func (BooleanField) IsNull ¶
func (f BooleanField) IsNull() bool
IsNull implements the IsNull method of the Field interface.
func (BooleanField) IsPK ¶
func (f BooleanField) IsPK() bool
IsPK implements the IsPK method of the Field interface.
func (BooleanField) IsUnique ¶
func (f BooleanField) IsUnique() bool
IsUnique implements the IsUnique method of the Field interface.
func (BooleanField) Recipient ¶
func (f BooleanField) Recipient() interface{}
Recipient implements the Recipient method of the Field interface.
func (BooleanField) Value ¶
func (f BooleanField) Value(rec interface{}) Value
Value implements the Value method of the Field interface.
type Builder ¶
The Builder interface represents a model container that implements the Getter interface, the Setter interface and the New method to return a new empty container.
type CharField ¶
type CharField struct { // PrimaryKey is true if the field is the model primary key. PrimaryKey bool `json:",omitempty"` // Unique is true if the field value must be unique. Unique bool `json:",omitempty"` // Null is true if the field can have null values. Null bool `json:",omitempty"` // Blank is true if the field is not required. Only used for validation. Blank bool `json:",omitempty"` // MaxLength is the max length accepted for field values. MaxLength int `json:",omitempty"` // Index is true if the field column should be indexed. Index bool `json:",omitempty"` // Column is the name of the db column. If blank, it will be the field name. Column string `json:",omitempty"` // Choices is a list of possible choices for the field. Choices []Choice `json:",omitempty"` // Default is the default value for the field. Blank for no default. Default string `json:",omitempty"` // DefaultEmpty is true if the empty string is the field default value. DefaultEmpty bool `json:",omitempty"` }
CharField implements the Field interface for small to medium-sized strings.
func (CharField) DefaultValue ¶
DefaultValue implements the DefaultValue method of the Field interface.
func (CharField) DisplayValue ¶
DisplayValue implements the DisplayValue method of the Field interface.
func (CharField) DriverValue ¶
DriverValue implements the DriverValue method of the Field interface.
func (CharField) IsAutoNowAdd ¶
IsAutoNowAdd implements the IsAutoNowAdd method of the Field interface.
type Choice ¶
type Choice struct { Value Value // Value is the choice value. Label string // Label is the choice label. }
Choice holds a choice option for a Field.
type Conditioner ¶
type Conditioner interface { // Root returns the first part of a composite predicate, that can be another // composite one if isChain is true or a simple one otherwise. // // For example, let's take the Conditioner representing this predicate: // (username = 'alice' OR username = 'bob') AND isAdmin = FALSE // // The method should return isChain as true and a Conditioner representing: // username = 'alice' OR username = 'bob' // // Whose Root method should return isChain as false and the Conditioner: // username = 'alice' Root() (conditioner Conditioner, isChain bool) // Conditions returns a map of values representing a predicate consisting // of simple conditions joined by the AND operator, where the key is the // column and operator part of the condition. // // The = operator can be omitted. For example: // // active = True AND id >= 10 // // Would return: map[string]Value{"active": true, "id >=": 10} Conditions() map[string]Value // Next returns the next conditioner and the operator joining them: // AND: isOr is false, isNot is false // AND NOT: isOr is false, isNot is true // OR: isOr is true, isNot is false // OR NOT: isOr is true, isNot is true Next() (conditioner Conditioner, isOr bool, isNot bool) // And joins the given conditioner and the current one by the AND operator. And(conditioner Conditioner) Conditioner // AndNot joins the given conditioner and the current one by the AND NOT // operator. AndNot(conditioner Conditioner) Conditioner // Or joins the given conditioner and the current one by the OR operator. Or(conditioner Conditioner) Conditioner // OrNot joins the given conditioner and the current one by the OR NOT // operator. OrNot(conditioner Conditioner) Conditioner }
The Conditioner interface defines the methods necessary to construct SQL predicates from the data types implementing the interface, and combine them to create composite predicates.
type Container ¶
type Container interface{}
The Container interface represents a type that holds the field values for a model object. It should be either a type implementing the Builder interface or a struct with the necessary exported fields.
type ContainerError ¶
type ContainerError struct {
Trace ErrorTrace
}
ContainerError is raised when a model container related error occurs.
func (*ContainerError) Error ¶
func (e *ContainerError) Error() string
Error implements the error interface.
type Database ¶
type Database struct { // Engine is the interface providing the database-abstraction API. // // It's automatically set from the selected Driver. Engine // Driver is the name of the database/sql driver that will be used to // interact with the database. Driver string // Name is the name of the database used to open a connection. Name string // User is the user, if required, to open a db connection. User string // Password is the password, if required, to open a db connection. Password string // contains filtered or unexported fields }
A Database holds the details required for the ORM to interact with the db.
func (Database) BeginTx ¶
func (db Database) BeginTx() (*Transaction, error)
BeginTx starts and returns a new database Transaction.
type DatabaseError ¶
type DatabaseError struct { Name string // Name is the database key in the gomodel registry. Trace ErrorTrace }
DatabaseError is raised when a database related error occurs.
func (*DatabaseError) Error ¶
func (e *DatabaseError) Error() string
Error implements the error interface.
type DateField ¶
type DateField struct { // PrimaryKey is true if the field is the model primary key. PrimaryKey bool `json:",omitempty"` // Unique is true if the field value must be unique. Unique bool `json:",omitempty"` // Null is true if the field can have null values. Null bool `json:",omitempty"` // AutoNow is true if the value is auto generated on row updates. AutoNow bool `json:",omitempty"` // AutoNowAdd is true if the value is auto generated on row inserts. AutoNowAdd bool `json:",omitempty"` // Blank is true if the field is not required. Only used for validation. Blank bool `json:",omitempty"` // Index is true if the field column should be indexed. Index bool `json:",omitempty"` // Column is the name of the db column. If blank, it will be the field name. Column string `json:",omitempty"` // Choices is a list of possible choices for the field. Choices []Choice `json:",omitempty"` // Default is the default value for the field. Blank for no default Default time.Time `json:",omitempty"` }
DateField implements the Field interface for dates.
func (DateField) DefaultValue ¶
DefaultValue implements the DefaultValue method of the Field interface.
func (DateField) DisplayValue ¶
DisplayValue implements the DisplayValue method of the Field interface.
func (DateField) DriverValue ¶
DriverValue implements the DriverValue method of the Field interface.
func (DateField) IsAutoNowAdd ¶
IsAutoNowAdd implements the IsAutoNowAdd method of the Field interface.
func (DateField) MarshalJSON ¶
MarshalJSON implements the json.Marshaler interface.
func (DateField) Recipient ¶
func (f DateField) Recipient() interface{}
Recipient implements the Recipient method of the Field interface.
func (*DateField) UnmarshalJSON ¶
UnmarshalJSON implements the json.Unmarshaler interface.
type DateTimeField ¶
type DateTimeField struct { // PrimaryKey is true if the field is the model primary key. PrimaryKey bool `json:",omitempty"` // Unique is true if the field value must be unique. Unique bool `json:",omitempty"` // Null is true if the field can have null values. Null bool `json:",omitempty"` // AutoNow is true if the value is auto generated on row updates. AutoNow bool `json:",omitempty"` // AutoNowAdd is true if the value is auto generated on row inserts. AutoNowAdd bool `json:",omitempty"` // Blank is true if the field is not required. Only used for validation. Blank bool `json:",omitempty"` // Index is true if the field column should be indexed. Index bool `json:",omitempty"` // Column is the name of the db column. If blank, it will be the field name. Column string `json:",omitempty"` // Choices is a list of possible choices for the field. Choices []Choice `json:",omitempty"` // Default is the default value for the field. Blank for no default Default time.Time `json:",omitempty"` }
DateTimeField implements the Field interface for datetime values.
func (DateTimeField) DBColumn ¶
func (f DateTimeField) DBColumn(name string) string
DBColumn implements the DBColumn method of the Field interface.
func (DateTimeField) DataType ¶
func (f DateTimeField) DataType(dvr string) string
DataType implements the DataType method of the Field interface.
func (DateTimeField) DefaultValue ¶
func (f DateTimeField) DefaultValue() (Value, bool)
DefaultValue implements the DefaultValue method of the Field interface.
func (DateTimeField) DisplayValue ¶
func (f DateTimeField) DisplayValue(val Value) string
DisplayValue implements the DisplayValue method of the Field interface.
func (DateTimeField) DriverValue ¶
func (f DateTimeField) DriverValue(v Value, dvr string) (interface{}, error)
DriverValue implements the DriverValue method of the Field interface.
func (DateTimeField) HasIndex ¶
func (f DateTimeField) HasIndex() bool
HasIndex implements the HasIndex method of the Field interface.
func (DateTimeField) IsAuto ¶
func (f DateTimeField) IsAuto() bool
IsAuto implements the IsAuto method of the Field interface.
func (DateTimeField) IsAutoNow ¶
func (f DateTimeField) IsAutoNow() bool
IsAutoNow implements the IsAutoNow method of the Field interface.
func (DateTimeField) IsAutoNowAdd ¶
func (f DateTimeField) IsAutoNowAdd() bool
IsAutoNowAdd implements the IsAutoNowAdd method of the Field interface.
func (DateTimeField) IsNull ¶
func (f DateTimeField) IsNull() bool
IsNull implements the IsNull method of the Field interface.
func (DateTimeField) IsPK ¶
func (f DateTimeField) IsPK() bool
IsPK implements the IsPK method of the Field interface.
func (DateTimeField) IsUnique ¶
func (f DateTimeField) IsUnique() bool
IsUnique implements the IsUnique method of the Field interface.
func (DateTimeField) MarshalJSON ¶
func (f DateTimeField) MarshalJSON() ([]byte, error)
MarshalJSON implements the json.Marshaler interface.
func (DateTimeField) Recipient ¶
func (f DateTimeField) Recipient() interface{}
Recipient implements the Recipient method of the Field interface.
func (DateTimeField) Value ¶
func (f DateTimeField) Value(rec interface{}) Value
Value implements the Value method of the Field interface.
type Dispatcher ¶
A Dispatcher embedds a Model definition and holds the default Objects Manager that gives access to the methods to interact with the database.
func New ¶
func New(name string, fields Fields, options Options) *Dispatcher
New creates a new model definition with the given arguments. It returns a Dispatcher embedding the model and holding the default Objects Manager.
The model won't be ready to interact with the database until it's been registered to an application using either the Register function or the homonymous model method.
type Engine ¶
type Engine interface { // Start opens a connection using the given Database details and returns // a new Engine holding the connection. Start(Database) (Engine, error) // Stop closes the db connection held by the engine. Stop() error // TxSupport indicates whether the engine supports transactions or not. TxSupport() bool // DB returns the underlying *sql.DB or nil if not applicable. DB() *sql.DB // BeginTx starts a new transaction and returns a new Engine holding it. BeginTx() (Engine, error) // Tx returns the underlying *sql.Tx or nil if not applicable. Tx() *sql.Tx // CommitTx commits the transaction held by the engine. CommitTx() error // RollbackTx rolls back the transaction held by the engine. RollbackTx() error // CreateTable creates the table for the given model. If force is true, the // method should return an error if the table already exists. CreateTable(model *Model, force bool) error // RenameTable renames the table from the given old model to the new one. RenameTable(old *Model, new *Model) error // DropTable drops the table for the given model. DropTable(model *Model) error // AddIndex creates a new index for the given model and fields. AddIndex(model *Model, name string, fields ...string) error // DropIndex drops the named index for the given model. DropIndex(model *Model, name string) error // AddColumns creates the columns for the given fields on the model table. AddColumns(model *Model, fields Fields) error // DropColumns drops the columns given by fields from the model table. DropColumns(model *Model, fields ...string) error // SelectQuery returns the SELECT SQL query details for the given model and // query options. SelectQuery(model *Model, options QueryOptions) (Query, error) // GetRows returns the Rows resulting from querying the database with // the query options, where options.Start is the first row index (starting // at 0) and options.End the last row index (-1 for all rows). GetRows(model *Model, options QueryOptions) (Rows, error) // InsertRow inserts the given values in the model table. InsertRow(model *Model, values Values) (int64, error) // UpdateRows updates the model rows selected by the given conditioner with // the given values. UpdateRows(model *Model, values Values, options QueryOptions) (int64, error) // DeleteRows deletes the model rows selected by the given conditioner. DeleteRows(model *Model, options QueryOptions) (int64, error) // CountRows counts the model rows selected by the given conditioner. CountRows(model *Model, options QueryOptions) (int64, error) // Exists returns whether any model row exists for the given conditioner. Exists(model *Model, options QueryOptions) (bool, error) }
Engine is the interface providing the database-abstraction API methods.
type ErrorTrace ¶
type ErrorTrace struct { App *Application Model *Model Field string Err error }
ErrorTrace holds the context information of a gomodel error.
func (ErrorTrace) String ¶
func (e ErrorTrace) String() string
String implements the fmt.Stringer interface.
type Field ¶
type Field interface { // IsPK returns true if the field is the model primary key. IsPK() bool // IsUnique returns true if the model field value must be unique. IsUnique() bool // IsNull returns true if the model field value can be null. IsNull() bool // IsAuto returns true if the field is an auto incremented one. IsAuto() bool // If IsAutoNow returns true, the field value will be time.Now() every // time a new row is inserted. IsAutoNow() bool // If IsAutoNowAdd returns true, the field value will be time.now() every // time a row is updated. IsAutoNowAdd() bool // If HasIndex returns true, the field column will be indexed. HasIndex() bool // DBColumn receives the model field name and returns the database column // name. DBColumn(fieldName string) string // DataType returns the field column type for the given driver. DataType(driver string) string // DefaultValue returns a default value for the field when hasDefault is // true. DefaultValue() (val Value, hasDefault bool) // Recipient returns a pointer to the variable that will hold a field value // coming from the database. Recipient() interface{} // Value receives the recipient holding the field value for a particular // instance, and returns the Value that will be presented when the Instance // Get method is called. Value(recipient interface{}) Value // DriverValue receives a field value and returns the value that should // be used on database queries for the given driver. DriverValue(val Value, driver string) (interface{}, error) // DisplayValue returns the string representation of the given value. DisplayValue(val Value) string }
Field is the interface that represents a model field.
type Fields ¶
Fields represents the fields map of a model.
func (Fields) MarshalJSON ¶
MarshalJSON implements the json.Marshaler interface.
func (*Fields) UnmarshalJSON ¶
UnmarshalJSON implements the json.Unmarshaler interface. An error is returned if the field type is not registered.
type GenericQuerySet ¶
type GenericQuerySet struct {
// contains filtered or unexported fields
}
GenericQuerySet implements the QuerySet interface.
func (GenericQuerySet) Count ¶
func (qs GenericQuerySet) Count() (int64, error)
Count implements the Count method of the QuerySet interface.
func (GenericQuerySet) Delete ¶
func (qs GenericQuerySet) Delete() (int64, error)
Delete implements the Delete method of the QuerySet interface.
func (GenericQuerySet) Exclude ¶
func (qs GenericQuerySet) Exclude(c Conditioner) QuerySet
Exclude implements the Exclude method of the QuerySet interface.
func (GenericQuerySet) Exists ¶
func (qs GenericQuerySet) Exists() (bool, error)
Exists implements the Exists method of the QuerySet interface.
func (GenericQuerySet) Filter ¶
func (qs GenericQuerySet) Filter(c Conditioner) QuerySet
Filter implements the Filter method of the QuerySet interface.
func (GenericQuerySet) Get ¶
func (qs GenericQuerySet) Get(c Conditioner) (*Instance, error)
Get implements the Get method of the QuerySet interface.
func (GenericQuerySet) Load ¶
func (qs GenericQuerySet) Load() ([]*Instance, error)
Load implements the Load method of the QuerySet interface.
func (GenericQuerySet) Model ¶
func (qs GenericQuerySet) Model() *Model
Model implements the Model method of the QuerySet interface.
func (GenericQuerySet) New ¶
func (qs GenericQuerySet) New(m *Model, parent QuerySet) QuerySet
New implements the New method of the QuerySet interface.
func (GenericQuerySet) Only ¶
func (qs GenericQuerySet) Only(fields ...string) QuerySet
Only implements the Only method of the QuerySet interface.
func (GenericQuerySet) Query ¶
func (qs GenericQuerySet) Query() (Query, error)
Query implements the Query method of the QuerySet interface.
func (GenericQuerySet) Slice ¶
func (qs GenericQuerySet) Slice(start int64, end int64) ([]*Instance, error)
Slice implemetns the Slice method of the QuerySet interface.
func (GenericQuerySet) Update ¶
func (qs GenericQuerySet) Update(container Container) (int64, error)
Update implements the Update method of the QuerySet interface.
func (GenericQuerySet) WithContainer ¶
func (qs GenericQuerySet) WithContainer(container Container) QuerySet
WithContainer implements the WithContainer method of the QuerySet interface.
func (GenericQuerySet) WithDB ¶
func (qs GenericQuerySet) WithDB(database string) QuerySet
WithDB implements the WithDB method of the QuerySet interface.
func (GenericQuerySet) WithTx ¶
func (qs GenericQuerySet) WithTx(tx *Transaction) QuerySet
WithTx implements the WithTx method of the QuerySet interface.
func (GenericQuerySet) Wrap ¶
func (qs GenericQuerySet) Wrap(parent GenericQuerySet) QuerySet
Wrap implements the Wrap method of the QuerySet interface.
type Getter ¶
Getter is the interface that wraps the basic Get method for model containers.
Get returns the value of the given field, and a boolean indicating whether the the field was found or not.
type Indexes ¶
The Indexes type describes the indexes of a model, where the key is the index name and the value the list of indexes fields.
type Instance ¶
type Instance struct {
// contains filtered or unexported fields
}
An Instance represents a particular model object and offers some methods to interact with its field values and the database.
func (Instance) Container ¶
Container returns the container holding the values of this model object.
func (Instance) DeleteOn ¶
Delete removes the object from the table on the given target, that can be a *Transaction or a string representing a database identifier.
func (Instance) Display ¶
Display returns the string representation of the value for the given field name, blank if not found.
func (Instance) GetIf ¶
GetIf returns the value for the given field name, and a hasField boolean indicating if the field was actually found in the underlying container.
func (Instance) Save ¶
Save propagates the instance field values to the database. If no field names are provided, all fields will be saved.
The method will try to update the row matching the instance pk. If no row is updated, a new one will be inserted.
If the pk field is auto incremented and the pk has the zero value, a new row will be inserted.
func (Instance) SaveOn ¶
SaveOn works as Save, but the changes are propagated to the given target, that can be a *Transaction or a string representing a database identifier.
type IntegerField ¶
type IntegerField struct { // PrimaryKey is true if the field is the model primary key. PrimaryKey bool `json:",omitempty"` // Unique is true if the field value must be unique. Unique bool `json:",omitempty"` // Null is true if the field can have null values. Null bool `json:",omitempty"` // Auto is true if the field value will be auto incremented. Auto bool `json:",omitempty"` // Blank is true if the field is not required. Only used for validation. Blank bool `json:",omitempty"` // Index is true if the field column should be indexed. Index bool `json:",omitempty"` // Column is the name of the db column. If blank, it will be the field name. Column string `json:",omitempty"` // Choices is a list of possible choices for the field. Choices []Choice `json:",omitempty"` // Default is the default value for the field. Blank for no default. Default int32 `json:",omitempty"` // DefaultZero is true if zero is the field default value. DefaultZero bool `json:",omitempty"` }
IntegerField implements the Field interface for small to medium-sized strings.
func (IntegerField) DBColumn ¶
func (f IntegerField) DBColumn(name string) string
DBColumn implements the DBColumn method of the Field interface.
func (IntegerField) DataType ¶
func (f IntegerField) DataType(dvr string) string
DataType implements the DataType method of the Field interface.
func (IntegerField) DefaultValue ¶
func (f IntegerField) DefaultValue() (Value, bool)
DefaultValue implements the DefaultValue method of the Field interface.
func (IntegerField) DisplayValue ¶
func (f IntegerField) DisplayValue(val Value) string
DisplayValue implements the DisplayValue method of the Field interface.
func (IntegerField) DriverValue ¶
func (f IntegerField) DriverValue(v Value, dvr string) (interface{}, error)
DriverValue implements the DriverValue method of the Field interface.
func (IntegerField) HasIndex ¶
func (f IntegerField) HasIndex() bool
HasIndex implements the HasIndex method of the Field interface.
func (IntegerField) IsAuto ¶
func (f IntegerField) IsAuto() bool
IsAuto implements the IsAuto method of the Field interface.
func (IntegerField) IsAutoNow ¶
func (f IntegerField) IsAutoNow() bool
IsAutoNow implements the IsAutoNow method of the Field interface.
func (IntegerField) IsAutoNowAdd ¶
func (f IntegerField) IsAutoNowAdd() bool
IsAutoNowAdd implements the IsAutoNowAdd method of the Field interface.
func (IntegerField) IsNull ¶
func (f IntegerField) IsNull() bool
IsNull implements the IsNull method of the Field interface.
func (IntegerField) IsPK ¶
func (f IntegerField) IsPK() bool
IsPK implements the IsPK method of the Field interface.
func (IntegerField) IsUnique ¶
func (f IntegerField) IsUnique() bool
IsUnique implements the IsUnique method of the Field interface.
func (IntegerField) Recipient ¶
func (f IntegerField) Recipient() interface{}
Recipient implements the Recipient method of the Field interface.
func (IntegerField) Value ¶
func (f IntegerField) Value(rec interface{}) Value
Value implements the Value method of the Field interface.
type Manager ¶
type Manager struct { // Model is the model making the queries. Model *Model // QuerySet is the base queryset for the manager. QuerySet QuerySet }
A Manager is the interface through which database query operations are provided to models.
func (Manager) Create ¶
Create makes a new object with the given values, saves it to the default database and returns the instance representing the object.
func (Manager) CreateOn ¶
CreateOn works as Create, but saves the object on the given target, that can be a *Transaction or a string representing a database identifier.
func (Manager) Exclude ¶
func (m Manager) Exclude(c Conditioner) QuerySet
Exclude returns a QuerySet exluding objects by the given conditioner.
func (Manager) Filter ¶
func (m Manager) Filter(c Conditioner) QuerySet
Filter returns a QuerySet filtered by the given conditioner.
func (Manager) Get ¶
func (m Manager) Get(c Conditioner) (*Instance, error)
Get returns an instance representing the single object matching the given conditioner.
If no object is found, *ObjectNotFoundError is returned.
If multiple objects match the conditions, *MultipleObjectsError is returned.
func (Manager) GetQuerySet ¶
GetQuerySet calls the New method of the base QuerySet and returns the result.
func (Manager) WithContainer ¶
WithContainer returns a QuerySet with the given Container type as a base.
type MockedEngine ¶
type MockedEngine struct { Args *MockedEngineArgs Results *MockedEngineResults // contains filtered or unexported fields }
MockedEngine mocks the Engine interface and can be used to write unit tests without having to open a database connection.
func (MockedEngine) AddColumns ¶
func (e MockedEngine) AddColumns(model *Model, fields Fields) error
AddColumns mocks the AddColumns method of the Engine interface.
func (MockedEngine) AddIndex ¶
func (e MockedEngine) AddIndex(m *Model, name string, fields ...string) error
AddIndex mocks the AddIndex method of the Engine interface.
func (MockedEngine) BeginTx ¶
func (e MockedEngine) BeginTx() (Engine, error)
BeginTx mocks the BeginTx method of the Engine interface. It returns the same MockedEngine.
func (MockedEngine) Calls ¶
func (e MockedEngine) Calls(method string) int
Calls returns the number of calls made to method.
func (MockedEngine) CommitTx ¶
func (e MockedEngine) CommitTx() error
CommitTx mocks the CommitTx method of the Engine interface.
func (MockedEngine) CountRows ¶
func (e MockedEngine) CountRows(m *Model, opt QueryOptions) (int64, error)
CountRows mocks the CountRows method of the Engine interface.
func (MockedEngine) CreateTable ¶
func (e MockedEngine) CreateTable(model *Model, force bool) error
CreateTable mocks the CreateTable method of the Engine interface.
func (MockedEngine) DB ¶
func (e MockedEngine) DB() *sql.DB
DB mocks the DB method of the Engine interface. It always returns nil.
func (MockedEngine) DeleteRows ¶
func (e MockedEngine) DeleteRows(m *Model, opt QueryOptions) (int64, error)
DeleteRows mocks the DeleteRows method of the Engine interface.
func (MockedEngine) DropColumns ¶
func (e MockedEngine) DropColumns(model *Model, fields ...string) error
DropColumns mocks the DropColumns method of the Engine interface.
func (MockedEngine) DropIndex ¶
func (e MockedEngine) DropIndex(model *Model, name string) error
DropIndex mocks the DropIndex method of the Engine interface.
func (MockedEngine) DropTable ¶
func (e MockedEngine) DropTable(model *Model) error
DropTable mocks the DropTable method of the Engine interface.
func (MockedEngine) Exists ¶
func (e MockedEngine) Exists(m *Model, opt QueryOptions) (bool, error)
Exists mocks the Exists method of the Engine interface.
func (MockedEngine) GetRows ¶
func (e MockedEngine) GetRows(model *Model, opt QueryOptions) (Rows, error)
GetRows mocks the GetRows method of the Engine interface.
func (MockedEngine) InsertRow ¶
func (e MockedEngine) InsertRow(model *Model, values Values) (int64, error)
InsertRow mocks the InsertRow method of the Engine interface.
func (MockedEngine) RenameTable ¶
func (e MockedEngine) RenameTable(old *Model, new *Model) error
RenameTable mocks the RenameTable method of the Engine interface.
func (MockedEngine) Reset ¶
func (e MockedEngine) Reset()
Reset sets all calls, results and arguments back to zero values.
func (MockedEngine) RollbackTx ¶
func (e MockedEngine) RollbackTx() error
RollbackTx mocks the RollbackTx method of the Engine interface.
func (MockedEngine) SelectQuery ¶
func (e MockedEngine) SelectQuery(m *Model, opt QueryOptions) (Query, error)
SelectQuery mocks the SelectQuery method of the Engine interface.
func (MockedEngine) Start ¶
func (e MockedEngine) Start(db Database) (Engine, error)
Start implements the Start method of the Engine interface.
func (MockedEngine) Stop ¶
func (e MockedEngine) Stop() error
Stop mocks the Stop method of the Engine interface.
func (MockedEngine) Tx ¶
func (e MockedEngine) Tx() *sql.Tx
Tx mocks the Tx method of the Engine interface. It always returns nil.
func (MockedEngine) TxSupport ¶
func (e MockedEngine) TxSupport() bool
TxSupport mocks the TxSupport of the Engine interface.
func (MockedEngine) UpdateRows ¶
func (e MockedEngine) UpdateRows( model *Model, values Values, options QueryOptions, ) (int64, error)
UpdateRows mocks the UpdateRows method of the Engine interface.
type MockedEngineArgs ¶
type MockedEngineArgs struct { CreateTable *Model RenameTable struct { Old *Model New *Model } DropTable *Model AddIndex struct { Model *Model Name string Fields []string } DropIndex struct { Model *Model Name string } AddColumns struct { Model *Model Fields Fields } DropColumns struct { Model *Model Fields []string } SelectQuery struct { Model *Model Options QueryOptions } GetRows struct { Model *Model Options QueryOptions } InsertRow struct { Model *Model Values Values } UpdateRows struct { Model *Model Values Values Options QueryOptions } DeleteRows struct { Model *Model Options QueryOptions } CountRows struct { Model *Model Options QueryOptions } Exists struct { Model *Model Options QueryOptions } }
MockedEngineArgs holds the arguments of the Engine interface methods when they've been called from a MockedEngine.
func (*MockedEngineArgs) Reset ¶
func (a *MockedEngineArgs) Reset()
Reset sets all the arguments back to zero values.
type MockedEngineResults ¶
type MockedEngineResults struct { Stop error TxSupport bool BeginTx error CommitTx error RollbackTx error CreateTable error RenameTable error CopyTable error DropTable error AddIndex error DropIndex error AddColumns error DropColumns error SelectQuery struct { Query Query Err error } GetRows struct { Rows Rows Err error } InsertRow struct { Id int64 Err error } UpdateRows struct { Number int64 Err error } DeleteRows struct { Number int64 Err error } CountRows struct { Number int64 Err error } Exists struct { Result bool Err error } }
MockedEngineResults holds the results of the Engine interface methods to be returned by a MockedEngine.
func (*MockedEngineResults) Reset ¶
func (r *MockedEngineResults) Reset()
Reset sets all the results back to zero values.
type Model ¶
type Model struct {
// contains filtered or unexported fields
}
A Model represents a single basic data structure of an application and how to map that data to the database schema.
func (*Model) AddField ¶
AddField adds a new Field to the model definition. It returns an error if the field name already exists or if a duplicate primary key is added.
This method should only be used to modify a model state during migration operations or to construct models programatically. Changing the model definition after it has been registered could cause unexpected errors.
func (*Model) AddIndex ¶
AddIndex adds a new index to the model definition. It returns an error if the name is duplicate or any of the indexed fields doesn't exist.
This method should only be used to modify a model state during migration operations or to construct models programatically. Changing the model definition after it has been registered could cause unexpected errors.
func (Model) App ¶
func (m Model) App() *Application
App returns the Application containing the model.
func (*Model) Register ¶
func (m *Model) Register(app *Application) error
Register validates the model definition, calls the SetupPrimaryKey and SetupIndexes methods, and adds the model to the given app.
func (*Model) RemoveField ¶
RemoveField removes the named field from the model definition. It returns an error if the fields is the primary key, the field is indexed or it doesn't exist.
This method should only be used to modify a model state during migration operations or to construct models programatically. Changing the model definition after it has been registered could cause unexpected errors.
func (*Model) RemoveIndex ¶
RemoveIndex removes the named index from the model definition. It returns an error if the index doesn't exist.
This method should only be used to modify a model state during migration operations or to construct models programatically. Changing the model definition after it has been registered could cause unexpected errors.
func (*Model) SetupIndexes ¶
SetupIndexes validates the model Indexes definition and adds individually indexes fields.
This method ia automatically called when a model is registered and should only be used to modify a model state during migration operations.
func (*Model) SetupPrimaryKey ¶
SetupPrimaryKey searches the model fields for a primary key. If not found, it will add an auto incremented IntegerField called id.
This method ia automatically called when a model is registered and should only be used to modify a model state during migration operations.
type MultipleObjectsError ¶
type MultipleObjectsError struct {
Trace ErrorTrace
}
MultipleObjectsError is raised when the Get returns more than one object.
func (*MultipleObjectsError) Error ¶
func (e *MultipleObjectsError) Error() string
Error implements the error interface.
type NullInt32 ¶
NullInt32 represents an int32 that may be null. TODO: remove for Golang 1.13
type NullTime ¶
NullTime represents a time.Time that may be null.
type ObjectNotFoundError ¶
type ObjectNotFoundError struct {
Trace ErrorTrace
}
ObjectNotFoundError is raised when the Get returns no objects.
func (*ObjectNotFoundError) Error ¶
func (e *ObjectNotFoundError) Error() string
Error implements the error interface.
type Options ¶
type Options struct { // Table is the name of the database Table for the model. If blank, the // table will be {app_name}_{model_name} all lowercase. Table string // Container is a value of the type that will be used to hold the model // field when a new instance is created. If nil, the Values type will be // the default Container. Container Container // Indexes is used to declare composite indexes. Indexes with one column // should be defined at field level. Indexes Indexes }
Options holds extra model options.
type PostgresEngine ¶
type PostgresEngine struct {
// contains filtered or unexported fields
}
PostgresEngine implements the Engine interface for the postgres driver.
func (PostgresEngine) AddColumns ¶
AddColumns implements the AddColumns method of the Engine interface.
func (PostgresEngine) BeginTx ¶
func (e PostgresEngine) BeginTx() (Engine, error)
BeginTx implements the BeginTx method of the Engine interface.
func (PostgresEngine) CommitTx ¶
func (e PostgresEngine) CommitTx() error
CommitTx implements the CommitTx method of the Engine interface.
func (PostgresEngine) CountRows ¶
func (e PostgresEngine) CountRows(m *Model, opt QueryOptions) (int64, error)
CountRows implement the CountRows method of the Engine interface.
func (PostgresEngine) CreateTable ¶
CreateTable implements the CreateTable method of the Engine interface.
func (PostgresEngine) DeleteRows ¶
func (e PostgresEngine) DeleteRows(m *Model, opt QueryOptions) (int64, error)
DeleteRows implements the DeleteRows method of the engine interface.
func (PostgresEngine) DropColumns ¶
DropColumns implements the DropColumns method of the Engine interface.
func (PostgresEngine) DropIndex ¶
DropIndex implements the DropIndex method of the Engine interface.
func (PostgresEngine) DropTable ¶
DropTable implements the DropTable method of the Engine interface.
func (PostgresEngine) Exists ¶
func (e PostgresEngine) Exists(m *Model, opt QueryOptions) (bool, error)
Exsists implements the Exists method of the Engine interface.
func (PostgresEngine) GetRows ¶
func (e PostgresEngine) GetRows(model *Model, opt QueryOptions) (Rows, error)
GetRows implements the GetRows method of the Engine interface.
func (PostgresEngine) InsertRow ¶
InsertRow implements the InsertRow method of the Engine interface.
func (PostgresEngine) RenameTable ¶
RenameTable implements the RenameTable method of the Engine interface.
func (PostgresEngine) RollbackTx ¶
func (e PostgresEngine) RollbackTx() error
RollbackTx implements the RollbackTx method of the Engine interface.
func (PostgresEngine) SelectQuery ¶
func (e PostgresEngine) SelectQuery(m *Model, opt QueryOptions) (Query, error)
SelectQuery implements the SelectQuery method of the Engine interface.
func (PostgresEngine) Start ¶
func (e PostgresEngine) Start(db Database) (Engine, error)
Start implements the Start method of the Engine interface.
func (PostgresEngine) Stop ¶
func (e PostgresEngine) Stop() error
Stop implements the Stop method of the Engine interface.
func (PostgresEngine) TxSupport ¶
func (e PostgresEngine) TxSupport() bool
TxSupport implements the TxSupport method of the Engine interface.
func (PostgresEngine) UpdateRows ¶
func (e PostgresEngine) UpdateRows( model *Model, values Values, options QueryOptions, ) (int64, error)
UpdateRows implements the UpdateRows method of the Engine interface.
type Q ¶
Q is a map of values that implements the Conditioner interface for predicates consisting of simple conditions joined by the AND operator.
func (Q) AndNot ¶
func (q Q) AndNot(next Conditioner) Conditioner
AndNot implements Conditioner interface.
func (Q) Conditions ¶
Conditions implements Conditioner interface.
func (Q) OrNot ¶
func (q Q) OrNot(next Conditioner) Conditioner
OrNot implements Conditioner interface.
type Query ¶
type Query struct { Stmt string // Stmt is the prepared statement. Args []interface{} // Args is the list of values for the statement. }
A Query holds the details of a database query.
type QueryOptions ¶
type QueryOptions struct { // Conditioner holds the conditions to be applied on the query. Conditioner Conditioner // Fields are the columns that will be selected on the query. Fields []string // Start represents the first row index to be selected, starting at 0. Start int64 // End represents the row index to stop the selection. End int64 }
QueryOptions holds common arguments for some Engine interface methods.
type QuerySet ¶
type QuerySet interface { // New returns a QuerySet representing all the objects from the given model. // // The parent will be the type used for all methods returning another // QuerySet. New(model *Model, parent QuerySet) QuerySet // Wrap takes a GenericQuerySet, encloses it and returns a custom type. // // This method is used to create custom QuerySets by embedding a // GenericQuerySet, whose methods will call Wrap and return the custom type. Wrap(qs GenericQuerySet) QuerySet // Model returns the QuerySet model. Model() *Model // WithContainer returns a QuerySet with the given Container type as a base. WithContainer(container Container) QuerySet // WithDB returns a QuerySet where all database operations will be applied // on the database identified by the given name. WithDB(database string) QuerySet // WithTx returns a QuerySet where all database operations will be applied // on the given transaction. WithTx(tx *Transaction) QuerySet // Filter returns a new QuerySet with the given conditioner applied to // the collections of objects represented by this QuerySet. Filter(c Conditioner) QuerySet // Exclude takes the current collection of objects, excludes the ones // matching the given conditioner and returns a new QuerySet. Exclude(c Conditioner) QuerySet // Only returns a QuerySet that will select only the given fields when // loaded. Only(fields ...string) QuerySet // Query returns the SELECT query details for the current QuerySet. Query() (Query, error) // Load retrieves the collection of objects represented by the QuerySet from // the database, and returns a list of instances. Load() ([]*Instance, error) // Slice retrieves the collection of objects represented by the QuerySet // from the start to the end parameters. If end is -1, it will retrieve // all objects from the given start. Slice(start int64, end int64) ([]*Instance, error) // Get returns an instance representing the single object from the current // collection matching the given conditioner. // // If no object is found, *ObjectNotFoundError is returned. // // If multiple objects match the conditions, *MultipleObjectsError is // returned. Get(c Conditioner) (*Instance, error) // Exists returns true if the collection of objects represented by the // QuerySet matches at least one row in the database. Exists() (bool, error) // Count returns the number of rows matching the collection of objects // represented by the QuerySet. Count() (int64, error) // Update modifies the database rows matching the collection of objects // represented by the QuerySet with the given values. Update(values Container) (int64, error) // Delete removes the database rows matching the collection of objects // represented by the QuerySet. Delete() (int64, error) }
The QuerySet interface represents a collection of objects from the database, defining the methods to interact with those objects, narrow down the collection and retrieve them.
type QuerySetError ¶
type QuerySetError struct {
Trace ErrorTrace
}
QuerySetError is raised when a QuerySet related error occurs.
func (*QuerySetError) Error ¶
func (e *QuerySetError) Error() string
Error implements the error interface.
type Rows ¶
type Rows interface { // Close closes the rows. Close() error // Err returns the error, if any, that was encountered during iteration. Err() error // Next prepares the next result row for reading with the Scan method. It // returns true on success, or false if there is no next result row or an // error happened while preparing it. Next() bool // Scan copies the columns in the current row into the values pointed at // by dest. The number of values in dest must be the same as the number of // columns in Rows. Scan(dest ...interface{}) error }
Rows is an interface wrapping the sql.Rows methods, allowing custom types to be returned by the Engine GetRows method.
type Setter ¶
Setter is the interface that wraps the basic Set method for model containers.
Set receives the name, the value and the Field definition, and returns any error.
type SqliteEngine ¶
type SqliteEngine struct {
// contains filtered or unexported fields
}
SqliteEngine implements the Engine interface for the sqlite3 driver.
func (SqliteEngine) AddColumns ¶
func (e SqliteEngine) AddColumns(model *Model, fields Fields) error
AddColumns implements the AddColumns method of the Engine interface.
func (SqliteEngine) BeginTx ¶
func (e SqliteEngine) BeginTx() (Engine, error)
BeginTx implemetns the BeginTx method of the Engine interface.
func (SqliteEngine) CommitTx ¶
func (e SqliteEngine) CommitTx() error
CommitTx implements the CommitTx method of the Engine interface.
func (SqliteEngine) CountRows ¶
func (e SqliteEngine) CountRows(m *Model, opt QueryOptions) (int64, error)
CountRows implement the CountRows method of the Engine interface.
func (SqliteEngine) CreateTable ¶
CreateTable implements the CreateTable method of the Engine interface.
func (SqliteEngine) DeleteRows ¶
func (e SqliteEngine) DeleteRows(m *Model, opt QueryOptions) (int64, error)
DeleteRows implements the DeleteRows method of the engine interface.
func (SqliteEngine) DropColumns ¶
func (e SqliteEngine) DropColumns(model *Model, fields ...string) error
DropColumns implements the DropColumns method of the Engine interface.
Since sqlite3 doesn't support dropping columns, it will perform the operation by creating a new table.
func (SqliteEngine) Exists ¶
func (e SqliteEngine) Exists(m *Model, opt QueryOptions) (bool, error)
Exsists implements the Exists method of the Engine interface.
func (SqliteEngine) GetRows ¶
func (e SqliteEngine) GetRows(model *Model, opt QueryOptions) (Rows, error)
GetRows implements the GetRows method of the Engine interface.
func (SqliteEngine) RenameTable ¶
RenameTable implements the RenameTable method of the Engine interface.
func (SqliteEngine) RollbackTx ¶
func (e SqliteEngine) RollbackTx() error
RollbackTx implements the RollbackTx method of the Engine interface.
func (SqliteEngine) SelectQuery ¶
func (e SqliteEngine) SelectQuery(m *Model, opt QueryOptions) (Query, error)
SelectQuery implements the SelectQuery method of the Engine interface.
func (SqliteEngine) Start ¶
func (e SqliteEngine) Start(db Database) (Engine, error)
Start implemetns the Start method of the Engine interface.
func (SqliteEngine) Stop ¶
func (e SqliteEngine) Stop() error
Stop implements the Stop method of the Engine interface.
func (SqliteEngine) TxSupport ¶
func (e SqliteEngine) TxSupport() bool
TxSupport implements the TxSupport method of the Engine interface.
func (SqliteEngine) UpdateRows ¶
func (e SqliteEngine) UpdateRows( model *Model, values Values, options QueryOptions, ) (int64, error)
UpdateRows implements the UpdateRows method of the Engine interface.
type TimeField ¶
type TimeField struct { // PrimaryKey is true if the field is the model primary key. PrimaryKey bool `json:",omitempty"` // Unique is true if the field value must be unique. Unique bool `json:",omitempty"` // Null is true if the field can have null values. Null bool `json:",omitempty"` // AutoNow is true if the value is auto generated on row updates. AutoNow bool `json:",omitempty"` // AutoNowAdd is true if the value is auto generated on row inserts. AutoNowAdd bool `json:",omitempty"` // Blank is true if the field is not required. Only used for validation. Blank bool `json:",omitempty"` // Index is true if the field column should be indexed. Index bool `json:",omitempty"` // Column is the name of the db column. If blank, it will be the field name. Column string `json:",omitempty"` // Choices is a list of possible choices for the field. Choices []Choice `json:",omitempty"` // Default is the default value for the field. Blank for no default Default time.Time `json:",omitempty"` }
TimeField implements the Field interface for time values.
func (TimeField) DefaultValue ¶
DefaultValue implements the DefaultValue method of the Field interface.
func (TimeField) DisplayValue ¶
DisplayValue implements the DisplayValue method of the Field interface.
func (TimeField) DriverValue ¶
DriverValue implements the DriverValue method of the Field interface.
func (TimeField) IsAutoNowAdd ¶
IsAutoNowAdd implements the IsAutoNowAdd method of the Field interface.
func (TimeField) MarshalJSON ¶
MarshalJSON implements the json.Marshaler interface.
func (TimeField) Recipient ¶
func (f TimeField) Recipient() interface{}
Recipient implements the Recipient method of the Field interface.
func (*TimeField) UnmarshalJSON ¶
type Transaction ¶
type Transaction struct { // Engine is the interface providing the database-abstraction API. Engine // DB is the Database where the transaction was created. DB Database }
Transaction holds a database transaction.
func (Transaction) Rollback ¶
func (tx Transaction) Rollback() error
Rollback rolls back the transction.
Source Files
¶
Directories
¶
Path | Synopsis |
---|---|
Package migration provides the tools to detect and manage the changes made to application models, store them in version control and apply them to the database schema.
|
Package migration provides the tools to detect and manage the changes made to application models, store them in version control and apply them to the database schema. |