model

package
v0.0.0-...-c063610 Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2015 License: Apache-2.0, MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Model

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

Model describes the data model for a table/object.

func New

func New(schema interface{}, table string, mq ModelQueries) *Model

New creates a new Model for a specific table, along with the CRUD queries for interacting with that model.

func (*Model) Q

func (m *Model) Q(db *sqlx.DB) *Query

Q takes a database connection to use for a query.

func (*Model) T

func (m *Model) T(query string) string

T takes a query with a %s token in it and adds the table. This method allows us to divorce a query from the models table.

func (*Model) Table

func (m *Model) Table() string

Table returns the name of the table for a model.

type ModelQueries

type ModelQueries struct {
	Insert string
}

ModelQueries holds the different types of sql queries to perform tasks such as insert on a model

type Query

type Query struct {
	*Model
	*sqlx.DB
}

Query holds the model and the connection to the database for performing queries against that model.

func (*Query) ByID

func (q *Query) ByID(id int) (interface{}, error)

ByID queries a model by its primary (integer) key.

func (*Query) Insert

func (q *Query) Insert(item interface{}) error

Insert performs a database insert.

Jump to

Keyboard shortcuts

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