(ctx context.Context, v interface{}, opts ...model.QueryOption)
| 237 | } |
| 238 | |
| 239 | func (d *postgresModel) Count(ctx context.Context, v interface{}, opts ...model.QueryOption) (int64, error) { |
| 240 | schema, err := d.schema(v) |
| 241 | if err != nil { |
| 242 | return 0, err |
| 243 | } |
| 244 | q := model.ApplyQueryOptions(opts...) |
| 245 | |
| 246 | query := fmt.Sprintf("SELECT COUNT(*) FROM %s", quoteIdent(schema.Table)) |
| 247 | var args []any |
| 248 | paramN := 1 |
| 249 | |
| 250 | if len(q.Filters) > 0 { |
| 251 | where, fArgs, _ := buildWhere(q.Filters, paramN) |
| 252 | query += " WHERE " + where |
| 253 | args = append(args, fArgs...) |
| 254 | } |
| 255 | |
| 256 | var count int64 |
| 257 | err = d.db.QueryRowContext(ctx, query, args...).Scan(&count) |
| 258 | if err != nil { |
| 259 | return 0, fmt.Errorf("model/postgres: count: %w", err) |
| 260 | } |
| 261 | return count, nil |
| 262 | } |
| 263 | |
| 264 | func (d *postgresModel) Close() error { |
| 265 | return d.db.Close() |
nothing calls this directly
no test coverage detected