(ctx context.Context, v interface{}, opts ...model.QueryOption)
| 237 | } |
| 238 | |
| 239 | func (d *sqliteModel) 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 %q", schema.Table) |
| 247 | var args []any |
| 248 | |
| 249 | if len(q.Filters) > 0 { |
| 250 | where, fArgs := buildWhere(q.Filters) |
| 251 | query += " WHERE " + where |
| 252 | args = append(args, fArgs...) |
| 253 | } |
| 254 | |
| 255 | var count int64 |
| 256 | err = d.db.QueryRowContext(ctx, query, args...).Scan(&count) |
| 257 | if err != nil { |
| 258 | return 0, fmt.Errorf("model/sqlite: count: %w", err) |
| 259 | } |
| 260 | return count, nil |
| 261 | } |
| 262 | |
| 263 | func (d *sqliteModel) Close() error { |
| 264 | return d.db.Close() |
nothing calls this directly
no test coverage detected