func (rs *AResultSet) 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.A.BaseSchema)
	if rs.lastErr != nil {
		rs.last = nil
	} else {
		var ok bool
		rs.last, ok = record.(*A)
		if !ok {
			rs.lastErr = fmt.Errorf("kallax: unable to convert record to *A")
			rs.last = nil
		}
	}
	return true
}
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.
package tests
import (
	"database/sql"
	"fmt"
	"net/url"
	"time"
	"gopkg.in/src-d/go-kallax.v1"
	"gopkg.in/src-d/go-kallax.v1/tests/fixtures"
	"gopkg.in/src-d/go-kallax.v1/types"
)
var _ types.SQLType
var _ fmt.Formatter
type modelSaveFunc func(*kallax.Store) error
func NewA(name string) (record *A) {
	return newA(name)
}
func (r *A) GetID() kallax.Identifier {
	return (*kallax.NumericID)(&r.ID)
}
func (r *A) 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 A: %s", col)
	}
}
func (r *A) 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 A: %s", col)
	}
}
func (r *A) NewRelationshipRecord(field string) (kallax.Record, error) {
	switch field {
	case "B":
		return new(B), nil
	}
	return nil, fmt.Errorf("kallax: model A has no relationship %s", field)
}
func (r *A) SetRelationship(field string, rel interface{}) error {
	switch field {
	case "B":
		val, ok := rel.(*B)
		if !ok {
			return fmt.Errorf("kallax: record of type %t can't be assigned to relationship B", rel)
		}
		if !val.GetID().IsEmpty() {
			r.B = val
		}
		return nil
	}
	return fmt.Errorf("kallax: model A has no relationship %s", field)
}
type AStore struct {
	*kallax.Store
}
func NewAStore(db *sql.DB) *AStore {
	return &AStore{kallax.NewStore(db)}
}
func (s *AStore) GenericStore() *kallax.Store {
	return s.Store
}
func (s *AStore) SetGenericStore(store *kallax.Store) {
	s.Store = store
}
func (s *AStore) Debug() *AStore {
	return &AStore{s.Store.Debug()}
}
func (s *AStore) DebugWith(logger kallax.LoggerFunc) *AStore {
	return &AStore{s.Store.DebugWith(logger)}
}
func (s *AStore) DisableCacher() *AStore {
	return &AStore{s.Store.DisableCacher()}
}
func (s *AStore) relationshipRecords(record *A) []modelSaveFunc {
	var result []modelSaveFunc
	if record.B != nil && !record.B.IsSaving() {
		r := record.B
		r.AddVirtualColumn("a_id", record.GetID())
		result = append(result, func(store *kallax.Store) error {
			_, err := (&BStore{store}).Save(r)
			return err
		})
	}
	return result
}
func (s *AStore) Insert(record *A) error {
	record.SetSaving(true)
	defer record.SetSaving(false)
	records := s.relationshipRecords(record)
	if len(records) > 0 {
		return s.Store.Transaction(func(s *kallax.Store) error {
			if err := s.Insert(Schema.A.BaseSchema, record); err != nil {
				return err
			}
			for _, r := range records {
				if err := r(s); err != nil {
					return err
				}
			}
			return nil
		})
	}
	return s.Store.Insert(Schema.A.BaseSchema, record)
}
func (s *AStore) Update(record *A, cols ...kallax.SchemaField) (updated int64, err error) {
	record.SetSaving(true)
	defer record.SetSaving(false)
	records := s.relationshipRecords(record)
	if len(records) > 0 {
		err = s.Store.Transaction(func(s *kallax.Store) error {
			updated, err = s.Update(Schema.A.BaseSchema, record, cols...)
			if err != nil {
				return err
			}
			for _, r := range records {
				if err := r(s); err != nil {
					return err
				}
			}
			return nil
		})
		if err != nil {
			return 0, err
		}
		return updated, nil
	}
	return s.Store.Update(Schema.A.BaseSchema, record, cols...)
}
func (s *AStore) Save(record *A) (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 *AStore) Delete(record *A) error {
	return s.Store.Delete(Schema.A.BaseSchema, record)
}
func (s *AStore) Find(q *AQuery) (*AResultSet, error) {
	rs, err := s.Store.Find(q)
	if err != nil {
		return nil, err
	}
	return NewAResultSet(rs), nil
}
func (s *AStore) MustFind(q *AQuery) *AResultSet {
	return NewAResultSet(s.Store.MustFind(q))
}
func (s *AStore) Count(q *AQuery) (int64, error) {
	return s.Store.Count(q)
}
func (s *AStore) MustCount(q *AQuery) int64 {
	return s.Store.MustCount(q)
}
func (s *AStore) FindOne(q *AQuery) (*A, 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 *AStore) FindAll(q *AQuery) ([]*A, error) {
	rs, err := s.Find(q)
	if err != nil {
		return nil, err
	}
	return rs.All()
}
func (s *AStore) MustFindOne(q *AQuery) *A {
	record, err := s.FindOne(q)
	if err != nil {
		panic(err)
	}
	return record
}
func (s *AStore) Reload(record *A) error {
	return s.Store.Reload(Schema.A.BaseSchema, record)
}
func (s *AStore) Transaction(callback func(*AStore) error) error {
	if callback == nil {
		return kallax.ErrInvalidTxCallback
	}
	return s.Store.Transaction(func(store *kallax.Store) error {
		return callback(&AStore{store})
	})
}
func (s *AStore) RemoveB(record *A) error {
	var r kallax.Record = record.B
	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.B.BaseSchema, r)
			if err != nil {
				return err
			}
			return afterDeleter.AfterDelete()
		})
	} else {
		err = s.Store.Delete(Schema.B.BaseSchema, r)
	}
	if err != nil {
		return err
	}
	record.B = nil
	return nil
}
type AQuery struct {
	*kallax.BaseQuery
}
func NewAQuery() *AQuery {
	return &AQuery{
		BaseQuery: kallax.NewBaseQuery(Schema.A.BaseSchema),
	}
}
func (q *AQuery) Select(columns ...kallax.SchemaField) *AQuery {
	if len(columns) == 0 {
		return q
	}
	q.BaseQuery.Select(columns...)
	return q
}
func (q *AQuery) SelectNot(columns ...kallax.SchemaField) *AQuery {
	q.BaseQuery.SelectNot(columns...)
	return q
}
func (q *AQuery) Copy() *AQuery {
	return &AQuery{
		BaseQuery: q.BaseQuery.Copy(),
	}
}
func (q *AQuery) Order(cols ...kallax.ColumnOrder) *AQuery {
	q.BaseQuery.Order(cols...)
	return q
}
func (q *AQuery) BatchSize(size uint64) *AQuery {
	q.BaseQuery.BatchSize(size)
	return q
}
func (q *AQuery) Limit(n uint64) *AQuery {
	q.BaseQuery.Limit(n)
	return q
}
func (q *AQuery) Offset(n uint64) *AQuery {
	q.BaseQuery.Offset(n)
	return q
}
func (q *AQuery) Where(cond kallax.Condition) *AQuery {
	q.BaseQuery.Where(cond)
	return q
}
func (q *AQuery) WithB() *AQuery {
	q.AddRelation(Schema.B.BaseSchema, "B", kallax.OneToOne, nil)
	return q
}
func (q *AQuery) FindByID(v ...int64) *AQuery {
	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.A.ID, values...))
}
func (q *AQuery) FindByName(v string) *AQuery {
	return q.Where(kallax.Eq(Schema.A.Name, v))
}
type AResultSet struct {
	ResultSet kallax.ResultSet
	last      *A
	lastErr   error
}
func NewAResultSet(rs kallax.ResultSet) *AResultSet {
	return &AResultSet{ResultSet: rs}
}