diff options
author | Joe Chen <jc@unknwon.io> | 2022-11-05 13:12:53 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-05 13:12:53 +0800 |
commit | a66c90462da24a916ee62afcb5a1f79d06ed8399 (patch) | |
tree | ac193502864d4f9309e82adf2b883f2d6cdfe879 /internal/dbutil/string.go | |
parent | 3af5a424f0e1afa9e77a60376bca97bc5c3b5f8b (diff) |
refactor(db): migrate methods off `user.go` and `org.go` (#7219) (#7227)
Diffstat (limited to 'internal/dbutil/string.go')
-rw-r--r-- | internal/dbutil/string.go | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/internal/dbutil/string.go b/internal/dbutil/string.go new file mode 100644 index 00000000..4ee3f012 --- /dev/null +++ b/internal/dbutil/string.go @@ -0,0 +1,25 @@ +// Copyright 2022 The Gogs Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package dbutil + +import ( + "fmt" + + "gogs.io/gogs/internal/conf" +) + +// Quote adds surrounding double quotes for all given arguments before being +// formatted if the current database is UsePostgreSQL. +func Quote(format string, args ...string) string { + anys := make([]any, len(args)) + for i := range args { + if conf.UsePostgreSQL { + anys[i] = `"` + args[i] + `"` + } else { + anys[i] = args[i] + } + } + return fmt.Sprintf(format, anys...) +} |