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

Method Count

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

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 6

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

Tested by

no test coverage detected