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

Closed
opened 1 year ago by gepeng · 3 comments
gepeng commented 1 year ago

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?
Poster

// 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 }
Poster

如果是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 1 year ago
lunny added this to the 1.0.4 milestone 1 year ago
lunny modified the milestone from 1.0.4 to 1.0.5 1 year ago
lunny modified the milestone from 1.0.5 to 1.0.6 1 year ago
lunny modified the milestone from 1.0.6 to 1.1.1 11 months ago
lunny modified the milestone from 1.1.1 to 1.3.0 4 months ago
lunny modified the milestone from 1.3.0 to 1.2.0 2 months ago
lunny referenced this issue from a commit 2 months ago
lunny closed this issue 2 months ago
Sign in to join this conversation.
No Milestone
No Assignees
2 Participants
Notifications
Due Date

No due date set.

Dependencies

This issue currently doesn't have any dependencies.

Loading…
There is no content yet.