feat: modify sql count value int64 (#2266)

This commit is contained in:
houseme
2022-11-07 17:52:25 +08:00
committed by GitHub
parent ee58255418
commit d37b75442d
3 changed files with 5 additions and 5 deletions

View File

@ -118,7 +118,7 @@ type DB interface {
GetOne(ctx context.Context, sql string, args ...interface{}) (Record, error) // See Core.GetOne.
GetValue(ctx context.Context, sql string, args ...interface{}) (Value, error) // See Core.GetValue.
GetArray(ctx context.Context, sql string, args ...interface{}) ([]Value, error) // See Core.GetArray.
GetCount(ctx context.Context, sql string, args ...interface{}) (int, error) // See Core.GetCount.
GetCount(ctx context.Context, sql string, args ...interface{}) (int64, error) // See Core.GetCount.
GetScan(ctx context.Context, objPointer interface{}, sql string, args ...interface{}) error // See Core.GetScan.
Union(unions ...*Model) *Model // See Core.Union.
UnionAll(unions ...*Model) *Model // See Core.UnionAll.

View File

@ -241,7 +241,7 @@ func (c *Core) GetValue(ctx context.Context, sql string, args ...interface{}) (V
}
// GetCount queries and returns the count from database.
func (c *Core) GetCount(ctx context.Context, sql string, args ...interface{}) (int, error) {
func (c *Core) GetCount(ctx context.Context, sql string, args ...interface{}) (int64, error) {
// If the query fields do not contain function "COUNT",
// it replaces the sql string and adds the "COUNT" function to the fields.
if !gregex.IsMatchString(`(?i)SELECT\s+COUNT\(.+\)\s+FROM`, sql) {
@ -251,7 +251,7 @@ func (c *Core) GetCount(ctx context.Context, sql string, args ...interface{}) (i
if err != nil {
return 0, err
}
return value.Int(), nil
return value.Int64(), nil
}
// Union does "(SELECT xxx FROM xxx) UNION (SELECT xxx FROM xxx) ..." statement.

View File

@ -382,7 +382,7 @@ func (tx *TX) GetValue(sql string, args ...interface{}) (Value, error) {
}
// GetCount queries and returns the count from database.
func (tx *TX) GetCount(sql string, args ...interface{}) (int, error) {
func (tx *TX) GetCount(sql string, args ...interface{}) (int64, error) {
if !gregex.IsMatchString(`(?i)SELECT\s+COUNT\(.+\)\s+FROM`, sql) {
sql, _ = gregex.ReplaceString(`(?i)(SELECT)\s+(.+)\s+(FROM)`, `$1 COUNT($2) $3`, sql)
}
@ -390,7 +390,7 @@ func (tx *TX) GetCount(sql string, args ...interface{}) (int, error) {
if err != nil {
return 0, err
}
return value.Int(), nil
return value.Int64(), nil
}
// Insert does "INSERT INTO ..." statement for the table.