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 ¶
- Variables
- type GORMPerson
- type GORMPet
- type Person
- func (r *Person) ColumnAddress(col string) (interface{}, error)
- func (r *Person) GetID() kallax.Identifier
- func (r *Person) NewRelationshipRecord(field string) (kallax.Record, error)
- func (r *Person) SetRelationship(field string, rel interface{}) error
- func (r *Person) Value(col string) (interface{}, error)
- type PersonQuery
- func (q *PersonQuery) BatchSize(size uint64) *PersonQuery
- func (q *PersonQuery) Copy() *PersonQuery
- func (q *PersonQuery) FindByID(v ...int64) *PersonQuery
- func (q *PersonQuery) FindByName(v string) *PersonQuery
- func (q *PersonQuery) Limit(n uint64) *PersonQuery
- func (q *PersonQuery) Offset(n uint64) *PersonQuery
- func (q *PersonQuery) Order(cols ...kallax.ColumnOrder) *PersonQuery
- func (q *PersonQuery) Select(columns ...kallax.SchemaField) *PersonQuery
- func (q *PersonQuery) SelectNot(columns ...kallax.SchemaField) *PersonQuery
- func (q *PersonQuery) Where(cond kallax.Condition) *PersonQuery
- func (q *PersonQuery) WithPets(cond kallax.Condition) *PersonQuery
- type PersonResultSet
- func (rs *PersonResultSet) All() ([]*Person, error)
- func (rs *PersonResultSet) Close() error
- func (rs *PersonResultSet) Err() error
- func (rs *PersonResultSet) ForEach(fn func(*Person) error) error
- func (rs *PersonResultSet) Get() (*Person, error)
- func (rs *PersonResultSet) Next() bool
- func (rs *PersonResultSet) One() (*Person, error)
- type PersonStore
- func (s *PersonStore) Count(q *PersonQuery) (int64, error)
- func (s *PersonStore) Delete(record *Person) error
- func (s *PersonStore) Find(q *PersonQuery) (*PersonResultSet, error)
- func (s *PersonStore) FindOne(q *PersonQuery) (*Person, error)
- func (s *PersonStore) Insert(record *Person) error
- func (s *PersonStore) MustCount(q *PersonQuery) int64
- func (s *PersonStore) MustFind(q *PersonQuery) *PersonResultSet
- func (s *PersonStore) MustFindOne(q *PersonQuery) *Person
- func (s *PersonStore) Reload(record *Person) error
- func (s *PersonStore) RemovePets(record *Person, deleted ...*Pet) error
- func (s *PersonStore) Save(record *Person) (updated bool, err error)
- func (s *PersonStore) Transaction(callback func(*PersonStore) error) error
- func (s *PersonStore) Update(record *Person, cols ...kallax.SchemaField) (updated int64, err error)
- type Pet
- type PetKind
- type PetQuery
- func (q *PetQuery) BatchSize(size uint64) *PetQuery
- func (q *PetQuery) Copy() *PetQuery
- func (q *PetQuery) FindByID(v ...int64) *PetQuery
- func (q *PetQuery) FindByKind(v PetKind) *PetQuery
- func (q *PetQuery) FindByName(v string) *PetQuery
- func (q *PetQuery) Limit(n uint64) *PetQuery
- func (q *PetQuery) Offset(n uint64) *PetQuery
- func (q *PetQuery) Order(cols ...kallax.ColumnOrder) *PetQuery
- func (q *PetQuery) Select(columns ...kallax.SchemaField) *PetQuery
- func (q *PetQuery) SelectNot(columns ...kallax.SchemaField) *PetQuery
- func (q *PetQuery) Where(cond kallax.Condition) *PetQuery
- type PetResultSet
- func (rs *PetResultSet) All() ([]*Pet, error)
- func (rs *PetResultSet) Close() error
- func (rs *PetResultSet) Err() error
- func (rs *PetResultSet) ForEach(fn func(*Pet) error) error
- func (rs *PetResultSet) Get() (*Pet, error)
- func (rs *PetResultSet) Next() bool
- func (rs *PetResultSet) One() (*Pet, error)
- type PetStore
- func (s *PetStore) Count(q *PetQuery) (int64, error)
- func (s *PetStore) Delete(record *Pet) error
- func (s *PetStore) Find(q *PetQuery) (*PetResultSet, error)
- func (s *PetStore) FindOne(q *PetQuery) (*Pet, error)
- func (s *PetStore) Insert(record *Pet) error
- func (s *PetStore) MustCount(q *PetQuery) int64
- func (s *PetStore) MustFind(q *PetQuery) *PetResultSet
- func (s *PetStore) MustFindOne(q *PetQuery) *Pet
- func (s *PetStore) Reload(record *Pet) error
- func (s *PetStore) Save(record *Pet) (updated bool, err error)
- func (s *PetStore) Transaction(callback func(*PetStore) error) error
- func (s *PetStore) Update(record *Pet, cols ...kallax.SchemaField) (updated int64, err error)
Constants ¶
This section is empty.
Variables ¶
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 Person ¶
type Person struct { kallax.Model `table:"people"` ID int64 `pk:"autoincr"` Name string Pets []*Pet }
func (*Person) ColumnAddress ¶
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 ¶
NewRelationshipRecord returns a new record for the relatiobship in the given field.
func (*Person) SetRelationship ¶
SetRelationship sets the given relationship in the given field.
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 ¶
func (*Pet) ColumnAddress ¶
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 ¶
NewRelationshipRecord returns a new record for the relatiobship in the given field.
func (*Pet) SetRelationship ¶
SetRelationship sets the given relationship in the given field.
type PetQuery ¶
type PetQuery struct {
*kallax.BaseQuery
}
PetQuery is the object used to create queries for the Pet entity.
func (*PetQuery) BatchSize ¶
BatchSize sets the number of items to fetch per batch when there are 1:N relationships selected in the query.
func (*PetQuery) Copy ¶
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 ¶
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 ¶
FindByKind adds a new filter to the query that will require that the Kind property is equal to the passed value
func (*PetQuery) FindByName ¶
FindByName adds a new filter to the query that will require that the Name property is equal to the passed value
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) 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 ¶
NewPetStore creates a new instance of PetStore using a SQL database.
func (*PetStore) Count ¶
Count returns the number of rows that would be retrieved with the given query.
func (*PetStore) Find ¶
func (s *PetStore) Find(q *PetQuery) (*PetResultSet, error)
Find returns the set of results for the given query.
func (*PetStore) FindOne ¶
FindOne returns the first row returned by the given query. `ErrNotFound` is returned if there are no results.
func (*PetStore) Insert ¶
Insert inserts a Pet in the database. A non-persisted object is required for this operation.
func (*PetStore) MustCount ¶
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 ¶
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 ¶
Reload refreshes the Pet with the data in the database and makes it writable.
func (*PetStore) Save ¶
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 ¶
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 ¶
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.