FindRecordsByIds finds all records by the specified ids. If no records are found, returns an empty slice.
( collectionModelOrIdentifier any, recordIds []string, optFilters ...func(q *dbx.SelectQuery) error, )
| 244 | // FindRecordsByIds finds all records by the specified ids. |
| 245 | // If no records are found, returns an empty slice. |
| 246 | func (app *BaseApp) FindRecordsByIds( |
| 247 | collectionModelOrIdentifier any, |
| 248 | recordIds []string, |
| 249 | optFilters ...func(q *dbx.SelectQuery) error, |
| 250 | ) ([]*Record, error) { |
| 251 | collection, err := getCollectionByModelOrIdentifier(app, collectionModelOrIdentifier) |
| 252 | if err != nil { |
| 253 | return nil, err |
| 254 | } |
| 255 | |
| 256 | query := app.RecordQuery(collection). |
| 257 | AndWhere(dbx.In( |
| 258 | collection.Name+".id", |
| 259 | list.ToInterfaceSlice(recordIds)..., |
| 260 | )) |
| 261 | |
| 262 | for _, filter := range optFilters { |
| 263 | if filter == nil { |
| 264 | continue |
| 265 | } |
| 266 | if err = filter(query); err != nil { |
| 267 | return nil, err |
| 268 | } |
| 269 | } |
| 270 | |
| 271 | records := make([]*Record, 0, len(recordIds)) |
| 272 | |
| 273 | err = query.All(&records) |
| 274 | if err != nil { |
| 275 | return nil, err |
| 276 | } |
| 277 | |
| 278 | return records, nil |
| 279 | } |
| 280 | |
| 281 | // FindAllRecords finds all records matching specified db expressions. |
| 282 | // |
no test coverage detected