internal/postgres: use squirrel in isLatestVersion

github.com/Masterminds/squirrel is now used to build the query for
isLatestVersion.

For golang/go#42708

Change-Id: I61b1d82cecbf147ffd929ac807da26d6b06d5c18
Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/271398
Trust: Julie Qiu <julie@golang.org>
Run-TryBot: Julie Qiu <julie@golang.org>
TryBot-Result: kokoro <noreply+kokoro@google.com>
Reviewed-by: Jonathan Amsterdam <jba@google.com>
Reviewed-by: Johan Brandhorst <johan.brandhorst@gmail.com>
diff --git a/internal/postgres/insert_module.go b/internal/postgres/insert_module.go
index 3d1a598..bb59b7a 100644
--- a/internal/postgres/insert_module.go
+++ b/internal/postgres/insert_module.go
@@ -16,6 +16,7 @@
 	"strings"
 	"unicode/utf8"
 
+	"github.com/Masterminds/squirrel"
 	"github.com/lib/pq"
 	"go.opencensus.io/trace"
 	"golang.org/x/mod/module"
@@ -496,15 +497,18 @@
 }
 
 // isLatestVersion reports whether version is the latest version of the module.
-func isLatestVersion(ctx context.Context, db *database.DB, modulePath, resolvedVersion string) (_ bool, err error) {
+func isLatestVersion(ctx context.Context, ddb *database.DB, modulePath, resolvedVersion string) (_ bool, err error) {
 	defer derrors.Wrap(&err, "isLatestVersion(ctx, tx, %q)", modulePath)
 
-	query := fmt.Sprintf(`
-		SELECT version FROM modules m WHERE m.module_path = $1
-		%s
-		LIMIT 1`, orderByLatestStmt)
-
-	row := db.QueryRow(ctx, query, modulePath)
+	q, args, err := orderByLatest(squirrel.Select("m.version").
+		From("modules m").
+		Where(squirrel.Eq{"m.module_path": modulePath})).
+		Limit(1).
+		ToSql()
+	if err != nil {
+		return false, err
+	}
+	row := ddb.QueryRow(ctx, q, args...)
 	var v string
 	if err := row.Scan(&v); err != nil {
 		if err == sql.ErrNoRows {