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)
}
Insert inserts a Person in the database. A non-persisted object is
required for this operation.
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
}