Skip to content

Commit 3192036

Browse files
committed
regenerate kallax benchmarks code
Signed-off-by: Miguel Molina <[email protected]>
1 parent 41503a0 commit 3192036

File tree

1 file changed

+9
-18
lines changed

1 file changed

+9
-18
lines changed

benchmarks/kallax.go

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -122,12 +122,12 @@ func (s *PersonStore) DebugWith(logger kallax.LoggerFunc) *PersonStore {
122122
func (s *PersonStore) relationshipRecords(record *Person) []kallax.RecordWithSchema {
123123
var records []kallax.RecordWithSchema
124124

125-
for _, rec := range record.Pets {
126-
rec.ClearVirtualColumns()
127-
rec.AddVirtualColumn("person_id", record.GetID())
125+
for i := range record.Pets {
126+
record.Pets[i].ClearVirtualColumns()
127+
record.Pets[i].AddVirtualColumn("person_id", record.GetID())
128128
records = append(records, kallax.RecordWithSchema{
129129
Schema: Schema.Pet.BaseSchema,
130-
Record: rec,
130+
Record: record.Pets[i],
131131
})
132132
}
133133

@@ -137,12 +137,10 @@ func (s *PersonStore) relationshipRecords(record *Person) []kallax.RecordWithSch
137137
// Insert inserts a Person in the database. A non-persisted object is
138138
// required for this operation.
139139
func (s *PersonStore) Insert(record *Person) error {
140-
141140
records := s.relationshipRecords(record)
142141

143142
if len(records) > 0 {
144143
return s.Store.Transaction(func(s *kallax.Store) error {
145-
146144
if err := s.Insert(Schema.Person.BaseSchema, record); err != nil {
147145
return err
148146
}
@@ -167,7 +165,6 @@ func (s *PersonStore) Insert(record *Person) error {
167165
}
168166

169167
return s.Store.Insert(Schema.Person.BaseSchema, record)
170-
171168
}
172169

173170
// Update updates the given record on the database. If the columns are given,
@@ -177,12 +174,10 @@ func (s *PersonStore) Insert(record *Person) error {
177174
// Only writable records can be updated. Writable objects are those that have
178175
// been just inserted or retrieved using a query with no custom select fields.
179176
func (s *PersonStore) Update(record *Person, cols ...kallax.SchemaField) (updated int64, err error) {
180-
181177
records := s.relationshipRecords(record)
182178

183179
if len(records) > 0 {
184180
err = s.Store.Transaction(func(s *kallax.Store) error {
185-
186181
updated, err = s.Update(Schema.Person.BaseSchema, record, cols...)
187182
if err != nil {
188183
return err
@@ -213,7 +208,6 @@ func (s *PersonStore) Update(record *Person, cols ...kallax.SchemaField) (update
213208
}
214209

215210
return s.Store.Update(Schema.Person.BaseSchema, record, cols...)
216-
217211
}
218212

219213
// Save inserts the object if the record is not persisted, otherwise it updates
@@ -233,9 +227,7 @@ func (s *PersonStore) Save(record *Person) (updated bool, err error) {
233227

234228
// Delete removes the given record from the database.
235229
func (s *PersonStore) Delete(record *Person) error {
236-
237230
return s.Store.Delete(Schema.Person.BaseSchema, record)
238-
239231
}
240232

241233
// Find returns the set of results for the given query.
@@ -641,6 +633,8 @@ func (r *Pet) ColumnAddress(col string) (interface{}, error) {
641633
return &r.Name, nil
642634
case "kind":
643635
return (*string)(&r.Kind), nil
636+
case "person_id":
637+
return types.Nullable(kallax.VirtualColumn("person_id", r, new(kallax.NumericID))), nil
644638

645639
default:
646640
return nil, fmt.Errorf("kallax: invalid column in Pet: %s", col)
@@ -656,6 +650,8 @@ func (r *Pet) Value(col string) (interface{}, error) {
656650
return r.Name, nil
657651
case "kind":
658652
return (string)(r.Kind), nil
653+
case "person_id":
654+
return r.Model.VirtualColumn(col), nil
659655

660656
default:
661657
return nil, fmt.Errorf("kallax: invalid column in Pet: %s", col)
@@ -710,9 +706,7 @@ func (s *PetStore) DebugWith(logger kallax.LoggerFunc) *PetStore {
710706
// Insert inserts a Pet in the database. A non-persisted object is
711707
// required for this operation.
712708
func (s *PetStore) Insert(record *Pet) error {
713-
714709
return s.Store.Insert(Schema.Pet.BaseSchema, record)
715-
716710
}
717711

718712
// Update updates the given record on the database. If the columns are given,
@@ -722,9 +716,7 @@ func (s *PetStore) Insert(record *Pet) error {
722716
// Only writable records can be updated. Writable objects are those that have
723717
// been just inserted or retrieved using a query with no custom select fields.
724718
func (s *PetStore) Update(record *Pet, cols ...kallax.SchemaField) (updated int64, err error) {
725-
726719
return s.Store.Update(Schema.Pet.BaseSchema, record, cols...)
727-
728720
}
729721

730722
// Save inserts the object if the record is not persisted, otherwise it updates
@@ -744,9 +736,7 @@ func (s *PetStore) Save(record *Pet) (updated bool, err error) {
744736

745737
// Delete removes the given record from the database.
746738
func (s *PetStore) Delete(record *Pet) error {
747-
748739
return s.Store.Delete(Schema.Pet.BaseSchema, record)
749-
750740
}
751741

752742
// Find returns the set of results for the given query.
@@ -1095,6 +1085,7 @@ var Schema = &schema{
10951085
kallax.NewSchemaField("id"),
10961086
kallax.NewSchemaField("name"),
10971087
kallax.NewSchemaField("kind"),
1088+
kallax.NewSchemaField("person_id"),
10981089
),
10991090
ID: kallax.NewSchemaField("id"),
11001091
Name: kallax.NewSchemaField("name"),

0 commit comments

Comments
 (0)