| 12345678910111213141516171819202122232425 |
- func (m *default{{.upperStartCamelObject}}Model) findListByPrimaryKeys(ctx context.Context, {{.lowerStartCamelPrimaryKey}}s []interface{}) ([]*{{.upperStartCamelObject}}, error) {
- if len({{.lowerStartCamelPrimaryKey}}s) == 0 {
- return []*{{.upperStartCamelObject}}{}, nil
- }
- placeholders := make([]string, len({{.lowerStartCamelPrimaryKey}}s))
- args := make([]interface{}, len({{.lowerStartCamelPrimaryKey}}s))
- for i, {{.lowerStartCamelPrimaryKey}} := range {{.lowerStartCamelPrimaryKey}}s {
- {{if .postgreSql}}placeholders[i] = fmt.Sprintf("$%d", i+1){{else}}placeholders[i] = "?"{{end}}
- args[i] = {{.lowerStartCamelPrimaryKey}}
- }
- var resp []*{{.upperStartCamelObject}}
- query := fmt.Sprintf("SELECT %s FROM %s WHERE {{.originalPrimaryKey}} IN (%s)", {{.lowerStartCamelObject}}Rows, m.table, strings.Join(placeholders, ","))
- err := {{if .withCache}}m.QueryRowsNoCacheCtx{{else}}m.conn.QueryRowsCtx{{end}}(ctx, &resp, query, args...)
- if err != nil {
- return nil, err
- }
- return resp, nil
- }
- func (m *default{{.upperStartCamelObject}}Model) getPrimaryKeyValue(data *{{.upperStartCamelObject}}) interface{} {
- return data.{{.upperStartCamelPrimaryKey}}
- }
|