From 6b913e233a4cbad26572af416aa7f92402e56274 Mon Sep 17 00:00:00 2001 From: sxwebdev Date: Wed, 21 Aug 2024 17:14:53 +0300 Subject: [PATCH] optimize total and exists methods --- internal/crud/crud.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/internal/crud/crud.go b/internal/crud/crud.go index 27f87c8..1198184 100644 --- a/internal/crud/crud.go +++ b/internal/crud/crud.go @@ -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 { @@ -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 }