session.innerInsertMulti(bean) 是否可以支持map[string]interface{} 类型的批量插入?现在的批量插入效率低了一些。 #1767

Closed
opened 2020-08-23 01:02:43 +00:00 by gepeng · 3 comments

func (session *Session) Insert(beans ...interface{}) (int64, error) {
...
for _, bean := range beans {
switch bean.(type) {
case map[string]interface{}:
...
case []map[string]interface{}:
s := bean.([]map[string]interface{})
for i := 0; i < len(s); i++ {
cnt, err := session.insertMapInterface(s[i])
if err != nil {
return affected, err
}

affected += cnt
....
}

func (session *Session) Insert(beans ...interface{}) (int64, error) { ... for _, bean := range beans { switch bean.(type) { case map[string]interface{}: ... case []map[string]interface{}: s := bean.([]map[string]interface{}) **for i := 0; i < len(s); i++ { cnt, err := session.insertMapInterface(s[i]) if err != nil { return affected, err }** affected += cnt .... }
Owner

A map[string]interface{} means one record?

A `map[string]interface{}` means one record?
Author

// Like codes followed. Beans may be a big array

func importer(x *xorm.Engine, tableName string, beans []map[string]interface{}) error {
_, err:= x.Table(tableName).Insert(beans)
return err
}

// Like codes followed. Beans may be a big array func importer(x *xorm.Engine, tableName string, beans []map[string]interface{}) error { _, err:= x.Table(tableName).Insert(beans) return err }
Author

如果是mysql,inser(beans []map[string]interface) 会生成多个"insert into table (fields...) values(?,?,...)"。 inert([]struct{...}) 生成的是insert into table (fields...) values(?,?,?...),(?,?,?...),...。效率会有数量级差别。

如果是mysql,inser(beans []map[string]interface) 会生成多个"insert into table (fields...) values(?,?,...)"。 inert([]struct{...}) 生成的是insert into table (fields...) values(?,?,?...),(?,?,?...),...。效率会有数量级差别。
lunny added the
kind
enhancement
label 2020-08-23 06:15:39 +00:00
lunny added this to the 1.0.4 milestone 2020-08-23 06:15:54 +00:00
lunny modified the milestone from 1.0.4 to 1.0.5 2020-08-31 01:21:52 +00:00
lunny modified the milestone from 1.0.5 to 1.0.6 2020-09-08 13:57:08 +00:00
lunny modified the milestone from 1.0.6 to 1.1.1 2020-11-03 07:31:07 +00:00
lunny modified the milestone from 1.1.1 to 1.3.0 2021-06-06 13:17:31 +00:00
lunny modified the milestone from 1.3.0 to 1.2.0 2021-07-29 04:36:14 +00:00
lunny closed this issue 2021-07-29 08:12:10 +00:00
Sign in to join this conversation.
No Milestone
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: xorm/xorm#1767
No description provided.