2023-04-18 13:21:46 +00:00
|
|
|
package mongo
|
|
|
|
|
|
|
|
import (
|
2023-05-24 11:04:29 +00:00
|
|
|
"git.kmsign.ru/royalcat/repogen/internal/codegen"
|
|
|
|
"git.kmsign.ru/royalcat/repogen/internal/spec"
|
2023-04-18 13:21:46 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func (g RepositoryGenerator) generateCountBody(
|
|
|
|
operation spec.CountOperation) (codegen.FunctionBody, error) {
|
|
|
|
|
|
|
|
querySpec, err := g.convertQuerySpec(operation.Query)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return codegen.FunctionBody{
|
|
|
|
codegen.DeclAssignStatement{
|
|
|
|
Vars: []string{"count", "err"},
|
|
|
|
Values: codegen.StatementList{
|
|
|
|
codegen.NewChainBuilder("r").
|
|
|
|
Chain("collection").
|
|
|
|
Call("CountDocuments",
|
|
|
|
codegen.Identifier("arg0"),
|
|
|
|
querySpec.Code(),
|
|
|
|
).Build(),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
ifErrReturn0Err,
|
|
|
|
codegen.ReturnStatement{
|
|
|
|
codegen.CallStatement{
|
|
|
|
FuncName: "int",
|
|
|
|
Params: codegen.StatementList{
|
|
|
|
codegen.Identifier("count"),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
codegen.Identifier("nil"),
|
|
|
|
},
|
|
|
|
}, nil
|
|
|
|
}
|