benchmark

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: May 8, 2017 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

IMPORTANT! This is auto generated code by https://github.com/src-d/go-kallax Please, do not touch the code below, and if you do, do it under your own risk. Take into account that all the code you write here will be completely erased from earth the next time you generate the kallax models.

Index

Constants

This section is empty.

Variables

View Source
var Schema = &schema{
	Person: &schemaPerson{
		BaseSchema: kallax.NewBaseSchema(
			"people",
			"__person",
			kallax.NewSchemaField("id"),
			kallax.ForeignKeys{
				"Pets": kallax.NewForeignKey("person_id", false),
			},
			func() kallax.Record {
				return new(Person)
			},
			true,
			kallax.NewSchemaField("id"),
			kallax.NewSchemaField("name"),
		),
		ID:   kallax.NewSchemaField("id"),
		Name: kallax.NewSchemaField("name"),
	},
	Pet: &schemaPet{
		BaseSchema: kallax.NewBaseSchema(
			"pets",
			"__pet",
			kallax.NewSchemaField("id"),
			kallax.ForeignKeys{},
			func() kallax.Record {
				return new(Pet)
			},
			true,
			kallax.NewSchemaField("id"),
			kallax.NewSchemaField("name"),
			kallax.NewSchemaField("kind"),
		),
		ID:   kallax.NewSchemaField("id"),
		Name: kallax.NewSchemaField("name"),
		Kind: kallax.NewSchemaField("kind"),
	},
}

Functions

This section is empty.

Types

type GORMPerson

type GORMPerson struct {
	ID   int64 `gorm:"primary_key"`
	Name string
	Pets []*GORMPet `gorm:"ForeignKey:PersonID"`
}

func (GORMPerson) TableName

func (GORMPerson) TableName() string

type GORMPet

type GORMPet struct {
	ID       int64 `gorm:"primary_key"`
	PersonID int64
	Name     string
	Kind     string
}

func (GORMPet) TableName

func (GORMPet) TableName() string

type Person

type Person struct {
	kallax.Model `table:"people"`
	ID           int64 `pk:"autoincr"`
	Name         string
	Pets         []*Pet
}

func NewPerson

func NewPerson() (record *Person)

NewPerson returns a new instance of Person.

func (*Person) ColumnAddress

func (r *Person) ColumnAddress(col string) (interface{}, error)

ColumnAddress returns the pointer to the value of the given column.

func (*Person) GetID

func (r *Person) GetID() kallax.Identifier

GetID returns the primary key of the model.

func (*Person) NewRelationshipRecord

func (r *Person) NewRelationshipRecord(field string) (kallax.Record, error)

NewRelationshipRecord returns a new record for the relatiobship in the given field.

func (*Person) SetRelationship

func (r *Person) SetRelationship(field string, rel interface{}) error

SetRelationship sets the given relationship in the given field.

func (*Person) Value

func (r *Person) Value(col string) (interface{}, error)

Value returns the value of the given column.

type PersonQuery

type PersonQuery struct {
	*kallax.BaseQuery
}

PersonQuery is the object used to create queries for the Person entity.

func NewPersonQuery

func NewPersonQuery() *PersonQuery

NewPersonQuery returns a new instance of PersonQuery.

func (*PersonQuery) BatchSize

func (q *PersonQuery) BatchSize(size uint64) *PersonQuery

BatchSize sets the number of items to fetch per batch when there are 1:N relationships selected in the query.

func (*PersonQuery) Copy

func (q *PersonQuery) Copy() *PersonQuery

Copy returns a new identical copy of the query. Remember queries are mutable so make a copy any time you need to reuse them.

func (*PersonQuery) FindByID

func (q *PersonQuery) FindByID(v ...int64) *PersonQuery

FindByID adds a new filter to the query that will require that the ID property is equal to one of the passed values; if no passed values, it will do nothing

func (*PersonQuery) FindByName

func (q *PersonQuery) FindByName(v string) *PersonQuery

FindByName adds a new filter to the query that will require that the Name property is equal to the passed value

func (*PersonQuery) Limit

func (q *PersonQuery) Limit(n uint64) *PersonQuery

Limit sets the max number of items to retrieve.

func (*PersonQuery) Offset

func (q *PersonQuery) Offset(n uint64) *PersonQuery

Offset sets the number of items to skip from the result set of items.

func (*PersonQuery) Order

func (q *PersonQuery) Order(cols ...kallax.ColumnOrder) *PersonQuery

Order adds order clauses to the query for the given columns.

func (*PersonQuery) Select

func (q *PersonQuery) Select(columns ...kallax.SchemaField) *PersonQuery

Select adds columns to select in the query.

func (*PersonQuery) SelectNot

func (q *PersonQuery) SelectNot(columns ...kallax.SchemaField) *PersonQuery

SelectNot excludes columns from being selected in the query.

func (*PersonQuery) Where

func (q *PersonQuery) Where(cond kallax.Condition) *PersonQuery

Where adds a condition to the query. All conditions added are concatenated using a logical AND.

func (*PersonQuery) WithPets

func (q *PersonQuery) WithPets(cond kallax.Condition) *PersonQuery

type PersonResultSet

type PersonResultSet struct {
	ResultSet kallax.ResultSet
	// contains filtered or unexported fields
}

PersonResultSet is the set of results returned by a query to the database.

func NewPersonResultSet

func NewPersonResultSet(rs kallax.ResultSet) *PersonResultSet

NewPersonResultSet creates a new result set for rows of the type Person.

func (*PersonResultSet) All

func (rs *PersonResultSet) All() ([]*Person, error)

All returns all records on the result set and closes the result set.

func (*PersonResultSet) Close

func (rs *PersonResultSet) Close() error

Close closes the result set.

func (*PersonResultSet) Err

func (rs *PersonResultSet) Err() error

Err returns the last error occurred.

func (*PersonResultSet) ForEach

func (rs *PersonResultSet) ForEach(fn func(*Person) error) error

ForEach iterates over the complete result set passing every record found to the given callback. It is possible to stop the iteration by returning `kallax.ErrStop` in the callback. Result set is always closed at the end.

func (*PersonResultSet) Get

func (rs *PersonResultSet) Get() (*Person, error)

Get retrieves the last fetched item from the result set and the last error.

func (*PersonResultSet) Next

func (rs *PersonResultSet) Next() bool

Next fetches the next item in the result set and returns true if there is a next item. The result set is closed automatically when there are no more items.

func (*PersonResultSet) One

func (rs *PersonResultSet) One() (*Person, error)

One returns the first record on the result set and closes the result set.

type PersonStore

type PersonStore struct {
	*kallax.Store
}

PersonStore is the entity to access the records of the type Person in the database.

func NewPersonStore

func NewPersonStore(db *sql.DB) *PersonStore

NewPersonStore creates a new instance of PersonStore using a SQL database.

func (*PersonStore) Count

func (s *PersonStore) Count(q *PersonQuery) (int64, error)

Count returns the number of rows that would be retrieved with the given query.

func (*PersonStore) Delete

func (s *PersonStore) Delete(record *Person) error

Delete removes the given record from the database.

func (*PersonStore) Find

func (s *PersonStore) Find(q *PersonQuery) (*PersonResultSet, error)

Find returns the set of results for the given query.

func (*PersonStore) FindOne

func (s *PersonStore) FindOne(q *PersonQuery) (*Person, error)

FindOne returns the first row returned by the given query. `ErrNotFound` is returned if there are no results.

func (*PersonStore) Insert

func (s *PersonStore) Insert(record *Person) error

Insert inserts a Person in the database. A non-persisted object is required for this operation.

func (*PersonStore) MustCount

func (s *PersonStore) MustCount(q *PersonQuery) int64

MustCount returns the number of rows that would be retrieved with the given query, but panics if there is an error.

func (*PersonStore) MustFind

func (s *PersonStore) MustFind(q *PersonQuery) *PersonResultSet

MustFind returns the set of results for the given query, but panics if there is any error.

func (*PersonStore) MustFindOne

func (s *PersonStore) MustFindOne(q *PersonQuery) *Person

MustFindOne returns the first row retrieved by the given query. It panics if there is an error or if there are no rows.

func (*PersonStore) Reload

func (s *PersonStore) Reload(record *Person) error

Reload refreshes the Person with the data in the database and makes it writable.

func (*PersonStore) RemovePets

func (s *PersonStore) RemovePets(record *Person, deleted ...*Pet) error

RemovePets removes the given items of the Pets field of the model. If no items are given, it removes all of them. The items will also be removed from the passed record inside this method.

func (*PersonStore) Save

func (s *PersonStore) Save(record *Person) (updated bool, err error)

Save inserts the object if the record is not persisted, otherwise it updates it. Same rules of Update and Insert apply depending on the case.

func (*PersonStore) Transaction

func (s *PersonStore) Transaction(callback func(*PersonStore) error) error

Transaction executes the given callback in a transaction and rollbacks if an error is returned. The transaction is only open in the store passed as a parameter to the callback.

func (*PersonStore) Update

func (s *PersonStore) Update(record *Person, cols ...kallax.SchemaField) (updated int64, err error)

Update updates the given record on the database. If the columns are given, only these columns will be updated. Otherwise all of them will be. Be very careful with this, as you will have a potentially different object in memory but not on the database. Only writable records can be updated. Writable objects are those that have been just inserted or retrieved using a query with no custom select fields.

type Pet

type Pet struct {
	kallax.Model `table:"pets"`
	ID           int64 `pk:"autoincr"`
	Name         string
	Kind         PetKind
}

func NewPet

func NewPet() (record *Pet)

NewPet returns a new instance of Pet.

func (*Pet) ColumnAddress

func (r *Pet) ColumnAddress(col string) (interface{}, error)

ColumnAddress returns the pointer to the value of the given column.

func (*Pet) GetID

func (r *Pet) GetID() kallax.Identifier

GetID returns the primary key of the model.

func (*Pet) NewRelationshipRecord

func (r *Pet) NewRelationshipRecord(field string) (kallax.Record, error)

NewRelationshipRecord returns a new record for the relatiobship in the given field.

func (*Pet) SetRelationship

func (r *Pet) SetRelationship(field string, rel interface{}) error

SetRelationship sets the given relationship in the given field.

func (*Pet) Value

func (r *Pet) Value(col string) (interface{}, error)

Value returns the value of the given column.

type PetKind

type PetKind string
const (
	Cat  PetKind = "cat"
	Dog  PetKind = "dog"
	Fish PetKind = "fish"
)

type PetQuery

type PetQuery struct {
	*kallax.BaseQuery
}

PetQuery is the object used to create queries for the Pet entity.

func NewPetQuery

func NewPetQuery() *PetQuery

NewPetQuery returns a new instance of PetQuery.

func (*PetQuery) BatchSize

func (q *PetQuery) BatchSize(size uint64) *PetQuery

BatchSize sets the number of items to fetch per batch when there are 1:N relationships selected in the query.

func (*PetQuery) Copy

func (q *PetQuery) Copy() *PetQuery

Copy returns a new identical copy of the query. Remember queries are mutable so make a copy any time you need to reuse them.

func (*PetQuery) FindByID

func (q *PetQuery) FindByID(v ...int64) *PetQuery

FindByID adds a new filter to the query that will require that the ID property is equal to one of the passed values; if no passed values, it will do nothing

func (*PetQuery) FindByKind

func (q *PetQuery) FindByKind(v PetKind) *PetQuery

FindByKind adds a new filter to the query that will require that the Kind property is equal to the passed value

func (*PetQuery) FindByName

func (q *PetQuery) FindByName(v string) *PetQuery

FindByName adds a new filter to the query that will require that the Name property is equal to the passed value

func (*PetQuery) Limit

func (q *PetQuery) Limit(n uint64) *PetQuery

Limit sets the max number of items to retrieve.

func (*PetQuery) Offset

func (q *PetQuery) Offset(n uint64) *PetQuery

Offset sets the number of items to skip from the result set of items.

func (*PetQuery) Order

func (q *PetQuery) Order(cols ...kallax.ColumnOrder) *PetQuery

Order adds order clauses to the query for the given columns.

func (*PetQuery) Select

func (q *PetQuery) Select(columns ...kallax.SchemaField) *PetQuery

Select adds columns to select in the query.

func (*PetQuery) SelectNot

func (q *PetQuery) SelectNot(columns ...kallax.SchemaField) *PetQuery

SelectNot excludes columns from being selected in the query.

func (*PetQuery) Where

func (q *PetQuery) Where(cond kallax.Condition) *PetQuery

Where adds a condition to the query. All conditions added are concatenated using a logical AND.

type PetResultSet

type PetResultSet struct {
	ResultSet kallax.ResultSet
	// contains filtered or unexported fields
}

PetResultSet is the set of results returned by a query to the database.

func NewPetResultSet

func NewPetResultSet(rs kallax.ResultSet) *PetResultSet

NewPetResultSet creates a new result set for rows of the type Pet.

func (*PetResultSet) All

func (rs *PetResultSet) All() ([]*Pet, error)

All returns all records on the result set and closes the result set.

func (*PetResultSet) Close

func (rs *PetResultSet) Close() error

Close closes the result set.

func (*PetResultSet) Err

func (rs *PetResultSet) Err() error

Err returns the last error occurred.

func (*PetResultSet) ForEach

func (rs *PetResultSet) ForEach(fn func(*Pet) error) error

ForEach iterates over the complete result set passing every record found to the given callback. It is possible to stop the iteration by returning `kallax.ErrStop` in the callback. Result set is always closed at the end.

func (*PetResultSet) Get

func (rs *PetResultSet) Get() (*Pet, error)

Get retrieves the last fetched item from the result set and the last error.

func (*PetResultSet) Next

func (rs *PetResultSet) Next() bool

Next fetches the next item in the result set and returns true if there is a next item. The result set is closed automatically when there are no more items.

func (*PetResultSet) One

func (rs *PetResultSet) One() (*Pet, error)

One returns the first record on the result set and closes the result set.

type PetStore

type PetStore struct {
	*kallax.Store
}

PetStore is the entity to access the records of the type Pet in the database.

func NewPetStore

func NewPetStore(db *sql.DB) *PetStore

NewPetStore creates a new instance of PetStore using a SQL database.

func (*PetStore) Count

func (s *PetStore) Count(q *PetQuery) (int64, error)

Count returns the number of rows that would be retrieved with the given query.

func (*PetStore) Delete

func (s *PetStore) Delete(record *Pet) error

Delete removes the given record from the database.

func (*PetStore) Find

func (s *PetStore) Find(q *PetQuery) (*PetResultSet, error)

Find returns the set of results for the given query.

func (*PetStore) FindOne

func (s *PetStore) FindOne(q *PetQuery) (*Pet, error)

FindOne returns the first row returned by the given query. `ErrNotFound` is returned if there are no results.

func (*PetStore) Insert

func (s *PetStore) Insert(record *Pet) error

Insert inserts a Pet in the database. A non-persisted object is required for this operation.

func (*PetStore) MustCount

func (s *PetStore) MustCount(q *PetQuery) int64

MustCount returns the number of rows that would be retrieved with the given query, but panics if there is an error.

func (*PetStore) MustFind

func (s *PetStore) MustFind(q *PetQuery) *PetResultSet

MustFind returns the set of results for the given query, but panics if there is any error.

func (*PetStore) MustFindOne

func (s *PetStore) MustFindOne(q *PetQuery) *Pet

MustFindOne returns the first row retrieved by the given query. It panics if there is an error or if there are no rows.

func (*PetStore) Reload

func (s *PetStore) Reload(record *Pet) error

Reload refreshes the Pet with the data in the database and makes it writable.

func (*PetStore) Save

func (s *PetStore) Save(record *Pet) (updated bool, err error)

Save inserts the object if the record is not persisted, otherwise it updates it. Same rules of Update and Insert apply depending on the case.

func (*PetStore) Transaction

func (s *PetStore) Transaction(callback func(*PetStore) error) error

Transaction executes the given callback in a transaction and rollbacks if an error is returned. The transaction is only open in the store passed as a parameter to the callback.

func (*PetStore) Update

func (s *PetStore) Update(record *Pet, cols ...kallax.SchemaField) (updated int64, err error)

Update updates the given record on the database. If the columns are given, only these columns will be updated. Otherwise all of them will be. Be very careful with this, as you will have a potentially different object in memory but not on the database. Only writable records can be updated. Writable objects are those that have been just inserted or retrieved using a query with no custom select fields.

Jump to

Keyboard shortcuts

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