MCPcopy Index your code
hub / github.com/micro/go-micro / Count

Method Count

model/sqlite/sqlite.go:239–261  ·  view source on GitHub ↗
(ctx context.Context, v interface{}, opts ...model.QueryOption)

Source from the content-addressed store, hash-verified

237}
238
239func (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
263func (d *sqliteModel) Close() error {
264 return d.db.Close()

Callers

nothing calls this directly

Calls 5

schemaMethod · 0.95
ApplyQueryOptionsFunction · 0.92
buildWhereFunction · 0.70
ScanMethod · 0.65
ErrorfMethod · 0.45

Tested by

no test coverage detected