1 Commits

Author SHA1 Message Date
2ec328059f func return type change 2025-07-26 21:45:09 +05:30
2 changed files with 20 additions and 22 deletions

19
pgm.go
View File

@@ -4,11 +4,9 @@
package pgm package pgm
import ( import (
"errors"
"strings" "strings"
"time" "time"
"github.com/jackc/pgx/v5"
"github.com/jackc/pgx/v5/pgtype" "github.com/jackc/pgx/v5/pgtype"
) )
@@ -116,19 +114,14 @@ func PgTimeNow() pgtype.Timestamptz {
return pgtype.Timestamptz{Time: time.Now(), Valid: true} return pgtype.Timestamptz{Time: time.Now(), Valid: true}
} }
// IsNotFound error check func ConcatWs(sep string, fields ...Field) Field {
func IsNotFound(err error) bool { return Field("concat_ws('" + sep + "'," + joinFileds(fields) + ")")
return errors.Is(err, pgx.ErrNoRows)
} }
func ConcatWs(sep string, fields ...Field) string { func StringAgg(exp, sep string) Field {
return "concat_ws('" + sep + "'," + joinFileds(fields) + ")" return Field("string_agg(" + exp + ",'" + sep + "')")
} }
func StringAgg(exp, sep string) string { func StringAggCast(exp, sep string) Field {
return "string_agg(" + exp + ",'" + sep + "')" return Field("string_agg(cast(" + exp + " as varchar),'" + sep + "')")
}
func StringAggCast(exp, sep string) string {
return "string_agg(cast(" + exp + " as varchar),'" + sep + "')"
} }

23
pool.go
View File

@@ -77,6 +77,17 @@ func InitPool(conf Config) {
poolPGX.Store(p) poolPGX.Store(p)
} }
// get string builder from pool
func getSB() *strings.Builder {
return poolStringBuilder.Get().(*strings.Builder)
}
// put string builder back to pool
func putSB(sb *strings.Builder) {
sb.Reset()
poolStringBuilder.Put(sb)
}
// GetPool instance // GetPool instance
func GetPool() *pgxpool.Pool { func GetPool() *pgxpool.Pool {
return poolPGX.Load() return poolPGX.Load()
@@ -93,13 +104,7 @@ func BeginTx(ctx context.Context) (pgx.Tx, error) {
return tx, err return tx, err
} }
// get string builder from pool // IsNotFound error check
func getSB() *strings.Builder { func IsNotFound(err error) bool {
return poolStringBuilder.Get().(*strings.Builder) return errors.Is(err, pgx.ErrNoRows)
}
// put string builder back to pool
func putSB(sb *strings.Builder) {
sb.Reset()
poolStringBuilder.Put(sb)
} }