Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions gee-orm/day3-save-query/session/record.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,20 @@ import (

// Insert one or more records in database
func (s *Session) Insert(values ...interface{}) (int64, error) {
if len(values) < 1 {
panic("There is no value to insert")
}
recordValues := make([]interface{}, 0)

baseValue := values[0]
table := s.Model(baseValue).RefTable()
baseType := reflect.TypeOf(baseValue)
s.clause.Set(clause.INSERT, table.Name, table.FieldNames)

for _, value := range values {
table := s.Model(value).RefTable()
s.clause.Set(clause.INSERT, table.Name, table.FieldNames)
if reflect.TypeOf(value) != baseType {
panic("All insert values must be the same type")
}
recordValues = append(recordValues, table.RecordValues(value))
}

Expand Down