package models import ( "errors" "time" ) // CardPrice - type CardPrice struct { Card string `db:"card" cc:"card"` PriceN float32 `db:"price_n" cc:"price_n"` PriceF float32 `db:"price_f" cc:"price_f"` Ctime time.Time `db:"ctime" cc:"ctime"` } type InsertCardPriceOpts struct { Data []CardPrice } // InsertCardPrice - func InsertCardPrice(arg InsertCardPriceOpts) (err error) { if len(arg.Data) == 0 { return errors.New("data list is empty") } tmp := make([]CardPrice, 0, len(arg.Data)) for _, v := range arg.Data { if len(v.Card) > 0 { tmp = append(tmp, v) } } query := `insert into "public"."card_price" ("card", "price_n", "price_f", "ctime") values ` insStr := "" for i := 0; i < len(tmp); i++ { if len(insStr) > 0 { insStr += "," } insStr += " (:card, :price_n, :price_f, now()) " } _, err = x.NamedExec(query+insStr, tmp) return }