github.com/team-ide/go-dialect@v1.9.20/worker/index.go (about) 1 package worker 2 3 import ( 4 "database/sql" 5 "errors" 6 "github.com/team-ide/go-dialect/dialect" 7 ) 8 9 func PrimaryKeysSelect(db *sql.DB, dia dialect.Dialect, param *dialect.ParamModel, ownerName string, tableName string, ignoreError bool) (list []*dialect.PrimaryKeyModel, err error) { 10 sqlInfo, err := dia.PrimaryKeysSelectSql(param, ownerName, tableName) 11 if err != nil { 12 return 13 } 14 if sqlInfo == "" { 15 return 16 } 17 dataList, err := DoQuery(db, sqlInfo, nil) 18 if err != nil { 19 err = errors.New("PrimaryKeysSelect error sql:" + sqlInfo + ",error:" + err.Error()) 20 return 21 } 22 for _, data := range dataList { 23 model, e := dia.PrimaryKeyModel(data) 24 if e != nil { 25 if !ignoreError { 26 err = e 27 return 28 } 29 model = &dialect.PrimaryKeyModel{ 30 Error: e.Error(), 31 } 32 } 33 list = append(list, model) 34 } 35 return 36 } 37 38 func IndexesSelect(db *sql.DB, dia dialect.Dialect, param *dialect.ParamModel, ownerName string, tableName string, ignoreError bool) (list []*dialect.IndexModel, err error) { 39 sqlInfo, err := dia.IndexesSelectSql(param, ownerName, tableName) 40 if err != nil { 41 return 42 } 43 if sqlInfo == "" { 44 return 45 } 46 dataList, err := DoQuery(db, sqlInfo, nil) 47 if err != nil { 48 err = errors.New("IndexesSelect error sql:" + sqlInfo + ",error:" + err.Error()) 49 return 50 } 51 for _, data := range dataList { 52 model, e := dia.IndexModel(data) 53 if e != nil { 54 if !ignoreError { 55 err = e 56 return 57 } 58 model = &dialect.IndexModel{ 59 Error: e.Error(), 60 } 61 } 62 list = append(list, model) 63 } 64 return 65 }