Skip to content

Commit

Permalink
optimize total and exists methods
Browse files Browse the repository at this point in the history
  • Loading branch information
sxwebdev committed Aug 21, 2024
1 parent 7342fdc commit 6b913e2
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions internal/crud/crud.go
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ func (s *crud) processTotal(cfg config.CrudParams, p processParams) error {
}

p.builder.WriteString(fmt.Sprintf("-- name: %s :one\n", methodName))
p.builder.WriteString("SELECT count(*) as total FROM ")
p.builder.WriteString("SELECT count(1) as total FROM ")
p.builder.WriteString(p.table)
lastIndex := 1
if err := s.processWhereParam(p, METHOD_TOTAL, &lastIndex); err != nil {
Expand All @@ -502,13 +502,13 @@ func (s *crud) processExists(cfg config.CrudParams, p processParams) error {
}

p.builder.WriteString(fmt.Sprintf("-- name: %s :one\n", methodName))
p.builder.WriteString("SELECT EXISTS (SELECT * FROM ")
p.builder.WriteString("SELECT EXISTS (SELECT 1 FROM ")
p.builder.WriteString(p.table)
lastIndex := 1
if err := s.processWhereParam(p, METHOD_EXISTS, &lastIndex); err != nil {
return err
}
p.builder.WriteString(")::boolean;\n\n")
p.builder.WriteString(" LIMIT 1)::boolean;\n\n")

return nil
}
Expand Down

0 comments on commit 6b913e2

Please sign in to comment.