func (r *Pet) ColumnAddress(col string) (interface{}, error) {
	switch col {
	case "id":
		return (*kallax.NumericID)(&r.ID), nil
	case "name":
		return &r.Name, nil
	case "kind":
		return (*string)(&r.Kind), nil
	case "person_id":
		return types.Nullable(kallax.VirtualColumn("person_id", r, new(kallax.NumericID))), nil
	default:
		return nil, fmt.Errorf("kallax: invalid column in Pet: %s", col)
	}
}
ColumnAddress returns the pointer to the value of the given column.
package benchmark
import (
	"database/sql"
	"fmt"
	"gopkg.in/src-d/go-kallax.v1"
	"gopkg.in/src-d/go-kallax.v1/types"
)
var _ types.SQLType
var _ fmt.Formatter
func NewPerson() (record *Person) {
	return new(Person)
}
func (r *Person) GetID() kallax.Identifier {
	return (*kallax.NumericID)(&r.ID)
}
func (r *Person) ColumnAddress(col string) (interface{}, error) {
	switch col {
	case "id":
		return (*kallax.NumericID)(&r.ID), nil
	case "name":
		return &r.Name, nil
	default:
		return nil, fmt.Errorf("kallax: invalid column in Person: %s", col)
	}
}
func (r *Person) Value(col string) (interface{}, error) {
	switch col {
	case "id":
		return r.ID, nil
	case "name":
		return r.Name, nil
	default:
		return nil, fmt.Errorf("kallax: invalid column in Person: %s", col)
	}
}
func (r *Person) NewRelationshipRecord(field string) (kallax.Record, error) {
	switch field {
	case "Pets":
		return new(Pet), nil
	}
	return nil, fmt.Errorf("kallax: model Person has no relationship %s", field)
}
func (r *Person) SetRelationship(field string, rel interface{}) error {
	switch field {
	case "Pets":
		records, ok := rel.([]kallax.Record)
		if !ok {
			return fmt.Errorf("kallax: relationship field %s needs a collection of records, not %T", field, rel)
		}
		r.Pets = make([]*Pet, len(records))
		for i, record := range records {
			rel, ok := record.(*Pet)
			if !ok {
				return fmt.Errorf("kallax: element of type %T cannot be added to relationship %s", record, field)
			}
			r.Pets[i] = rel
		}
		return nil
	}
	return fmt.Errorf("kallax: model Person has no relationship %s", field)
}
type PersonStore struct {
	*kallax.Store
}
func NewPersonStore(db *sql.DB) *PersonStore {
	return &PersonStore{kallax.NewStore(db)}
}
func (s *PersonStore) GenericStore() *kallax.Store {
	return s.Store
}
func (s *PersonStore) SetGenericStore(store *kallax.Store) {
	s.Store = store
}
func (s *PersonStore) Debug() *PersonStore {
	return &PersonStore{s.Store.Debug()}
}
func (s *PersonStore) DebugWith(logger kallax.LoggerFunc) *PersonStore {
	return &PersonStore{s.Store.DebugWith(logger)}
}
func (s *PersonStore) relationshipRecords(record *Person) []kallax.RecordWithSchema {
	var records []kallax.RecordWithSchema
	for i := range record.Pets {
		record.Pets[i].ClearVirtualColumns()
		record.Pets[i].AddVirtualColumn("person_id", record.GetID())
		records = append(records, kallax.RecordWithSchema{
			Schema: Schema.Pet.BaseSchema,
			Record: record.Pets[i],
		})
	}
	return records
}
func (s *PersonStore) Insert(record *Person) error {
	records := s.relationshipRecords(record)
	if len(records) > 0 {
		return s.Store.Transaction(func(s *kallax.Store) error {
			if err := s.Insert(Schema.Person.BaseSchema, record); err != nil {
				return err
			}
			for _, r := range records {
				if err := kallax.ApplyBeforeEvents(r.Record); err != nil {
					return err
				}
				persisted := r.Record.IsPersisted()
				if _, err := s.Save(r.Schema, r.Record); err != nil {
					return err
				}
				if err := kallax.ApplyAfterEvents(r.Record, persisted); err != nil {
					return err
				}
			}
			return nil
		})
	}
	return s.Store.Insert(Schema.Person.BaseSchema, record)
}
func (s *PersonStore) Update(record *Person, cols ...kallax.SchemaField) (updated int64, err error) {
	records := s.relationshipRecords(record)
	if len(records) > 0 {
		err = s.Store.Transaction(func(s *kallax.Store) error {
			updated, err = s.Update(Schema.Person.BaseSchema, record, cols...)
			if err != nil {
				return err
			}
			for _, r := range records {
				if err := kallax.ApplyBeforeEvents(r.Record); err != nil {
					return err
				}
				persisted := r.Record.IsPersisted()
				if _, err := s.Save(r.Schema, r.Record); err != nil {
					return err
				}
				if err := kallax.ApplyAfterEvents(r.Record, persisted); err != nil {
					return err
				}
			}
			return nil
		})
		if err != nil {
			return 0, err
		}
		return updated, nil
	}
	return s.Store.Update(Schema.Person.BaseSchema, record, cols...)
}
func (s *PersonStore) Save(record *Person) (updated bool, err error) {
	if !record.IsPersisted() {
		return false, s.Insert(record)
	}
	rowsUpdated, err := s.Update(record)
	if err != nil {
		return false, err
	}
	return rowsUpdated > 0, nil
}
func (s *PersonStore) Delete(record *Person) error {
	return s.Store.Delete(Schema.Person.BaseSchema, record)
}
func (s *PersonStore) Find(q *PersonQuery) (*PersonResultSet, error) {
	rs, err := s.Store.Find(q)
	if err != nil {
		return nil, err
	}
	return NewPersonResultSet(rs), nil
}
func (s *PersonStore) MustFind(q *PersonQuery) *PersonResultSet {
	return NewPersonResultSet(s.Store.MustFind(q))
}
func (s *PersonStore) Count(q *PersonQuery) (int64, error) {
	return s.Store.Count(q)
}
func (s *PersonStore) MustCount(q *PersonQuery) int64 {
	return s.Store.MustCount(q)
}
func (s *PersonStore) FindOne(q *PersonQuery) (*Person, error) {
	q.Limit(1)
	q.Offset(0)
	rs, err := s.Find(q)
	if err != nil {
		return nil, err
	}
	if !rs.Next() {
		return nil, kallax.ErrNotFound
	}
	record, err := rs.Get()
	if err != nil {
		return nil, err
	}
	if err := rs.Close(); err != nil {
		return nil, err
	}
	return record, nil
}
func (s *PersonStore) FindAll(q *PersonQuery) ([]*Person, error) {
	rs, err := s.Find(q)
	if err != nil {
		return nil, err
	}
	return rs.All()
}
func (s *PersonStore) MustFindOne(q *PersonQuery) *Person {
	record, err := s.FindOne(q)
	if err != nil {
		panic(err)
	}
	return record
}
func (s *PersonStore) Reload(record *Person) error {
	return s.Store.Reload(Schema.Person.BaseSchema, record)
}
func (s *PersonStore) Transaction(callback func(*PersonStore) error) error {
	if callback == nil {
		return kallax.ErrInvalidTxCallback
	}
	return s.Store.Transaction(func(store *kallax.Store) error {
		return callback(&PersonStore{store})
	})
}
func (s *PersonStore) RemovePets(record *Person, deleted ...*Pet) error {
	var updated []*Pet
	var clear bool
	if len(deleted) == 0 {
		clear = true
		deleted = record.Pets
		if len(deleted) == 0 {
			return nil
		}
	}
	if len(deleted) > 1 {
		err := s.Store.Transaction(func(s *kallax.Store) error {
			for _, d := range deleted {
				var r kallax.Record = d
				if beforeDeleter, ok := r.(kallax.BeforeDeleter); ok {
					if err := beforeDeleter.BeforeDelete(); err != nil {
						return err
					}
				}
				if err := s.Delete(Schema.Pet.BaseSchema, d); err != nil {
					return err
				}
				if afterDeleter, ok := r.(kallax.AfterDeleter); ok {
					if err := afterDeleter.AfterDelete(); err != nil {
						return err
					}
				}
			}
			return nil
		})
		if err != nil {
			return err
		}
		if clear {
			record.Pets = nil
			return nil
		}
	} else {
		var r kallax.Record = deleted[0]
		if beforeDeleter, ok := r.(kallax.BeforeDeleter); ok {
			if err := beforeDeleter.BeforeDelete(); err != nil {
				return err
			}
		}
		var err error
		if afterDeleter, ok := r.(kallax.AfterDeleter); ok {
			err = s.Store.Transaction(func(s *kallax.Store) error {
				err := s.Delete(Schema.Pet.BaseSchema, r)
				if err != nil {
					return err
				}
				return afterDeleter.AfterDelete()
			})
		} else {
			err = s.Store.Delete(Schema.Pet.BaseSchema, deleted[0])
		}
		if err != nil {
			return err
		}
	}
	for _, r := range record.Pets {
		var found bool
		for _, d := range deleted {
			if d.GetID().Equals(r.GetID()) {
				found = true
				break
			}
		}
		if !found {
			updated = append(updated, r)
		}
	}
	record.Pets = updated
	return nil
}
type PersonQuery struct {
	*kallax.BaseQuery
}
func NewPersonQuery() *PersonQuery {
	return &PersonQuery{
		BaseQuery: kallax.NewBaseQuery(Schema.Person.BaseSchema),
	}
}
func (q *PersonQuery) Select(columns ...kallax.SchemaField) *PersonQuery {
	if len(columns) == 0 {
		return q
	}
	q.BaseQuery.Select(columns...)
	return q
}
func (q *PersonQuery) SelectNot(columns ...kallax.SchemaField) *PersonQuery {
	q.BaseQuery.SelectNot(columns...)
	return q
}
func (q *PersonQuery) Copy() *PersonQuery {
	return &PersonQuery{
		BaseQuery: q.BaseQuery.Copy(),
	}
}
func (q *PersonQuery) Order(cols ...kallax.ColumnOrder) *PersonQuery {
	q.BaseQuery.Order(cols...)
	return q
}
func (q *PersonQuery) BatchSize(size uint64) *PersonQuery {
	q.BaseQuery.BatchSize(size)
	return q
}
func (q *PersonQuery) Limit(n uint64) *PersonQuery {
	q.BaseQuery.Limit(n)
	return q
}
func (q *PersonQuery) Offset(n uint64) *PersonQuery {
	q.BaseQuery.Offset(n)
	return q
}
func (q *PersonQuery) Where(cond kallax.Condition) *PersonQuery {
	q.BaseQuery.Where(cond)
	return q
}
func (q *PersonQuery) WithPets(cond kallax.Condition) *PersonQuery {
	q.AddRelation(Schema.Pet.BaseSchema, "Pets", kallax.OneToMany, cond)
	return q
}
func (q *PersonQuery) FindByID(v ...int64) *PersonQuery {
	if len(v) == 0 {
		return q
	}
	values := make([]interface{}, len(v))
	for i, val := range v {
		values[i] = val
	}
	return q.Where(kallax.In(Schema.Person.ID, values...))
}
func (q *PersonQuery) FindByName(v string) *PersonQuery {
	return q.Where(kallax.Eq(Schema.Person.Name, v))
}
type PersonResultSet struct {
	ResultSet kallax.ResultSet
	last      *Person
	lastErr   error
}
func NewPersonResultSet(rs kallax.ResultSet) *PersonResultSet {
	return &PersonResultSet{ResultSet: rs}
}
func (rs *PersonResultSet) Next() bool {
	if !rs.ResultSet.Next() {
		rs.lastErr = rs.ResultSet.Close()
		rs.last = nil
		return false
	}
	var record kallax.Record
	record, rs.lastErr = rs.ResultSet.Get(Schema.Person.BaseSchema)
	if rs.lastErr != nil {
		rs.last = nil
	} else {
		var ok bool
		rs.last, ok = record.(*Person)
		if !ok {
			rs.lastErr = fmt.Errorf("kallax: unable to convert record to *Person")
			rs.last = nil
		}
	}
	return true
}
func (rs *PersonResultSet) Get() (*Person, error) {
	return rs.last, rs.lastErr
}
func (rs *PersonResultSet) ForEach(fn func(*Person) error) error {
	for rs.Next() {
		record, err := rs.Get()
		if err != nil {
			return err
		}
		if err := fn(record); err != nil {
			if err == kallax.ErrStop {
				return rs.Close()
			}
			return err
		}
	}
	return nil
}
func (rs *PersonResultSet) All() ([]*Person, error) {
	var result []*Person
	for rs.Next() {
		record, err := rs.Get()
		if err != nil {
			return nil, err
		}
		result = append(result, record)
	}
	return result, nil
}
func (rs *PersonResultSet) One() (*Person, error) {
	if !rs.Next() {
		return nil, kallax.ErrNotFound
	}
	record, err := rs.Get()
	if err != nil {
		return nil, err
	}
	if err := rs.Close(); err != nil {
		return nil, err
	}
	return record, nil
}
func (rs *PersonResultSet) Err() error {
	return rs.lastErr
}
func (rs *PersonResultSet) Close() error {
	return rs.ResultSet.Close()
}
func NewPet() (record *Pet) {
	return new(Pet)
}
func (r *Pet) GetID() kallax.Identifier {
	return (*kallax.NumericID)(&r.ID)
}