improve cache feature for package gdb

This commit is contained in:
John Guo
2022-03-31 16:15:44 +08:00
parent 372bae4799
commit 05508e4fcb
2 changed files with 11 additions and 5 deletions

View File

@ -34,9 +34,10 @@ type CacheOption struct {
Force bool
}
// selectCacheItem is the cache item for SELECT statement result.
type selectCacheItem struct {
Result Result
FirstResultColumn string
Result Result // Sql result of SELECT statement.
FirstResultColumn string // The first column name of result, for Value/Count functions.
}
// Cache sets the cache feature for the model. It caches the result of the sql, which means
@ -128,7 +129,6 @@ func (m *Model) makeSelectCacheKey(sql string, args ...interface{}) string {
if len(cacheKey) == 0 {
cacheKey = fmt.Sprintf(
`GCache@Schema(%s):%s`,
m.db.GetSchema(),
gmd5.MustEncryptString(sql+", @PARAMS:"+gconv.String(args)),
)
}

View File

@ -176,7 +176,10 @@ func (m *Model) Value(fieldsAndWhere ...interface{}) (Value, error) {
return v, nil
}
}
return nil, gerror.NewCode(gcode.CodeInternalError, `query value error`)
return nil, gerror.NewCode(
gcode.CodeInternalError,
`query value error: the internal context data is missing. there's' internal issue should be fixed'`,
)
}
// Array queries and returns data values as slice from database.
@ -390,7 +393,10 @@ func (m *Model) Count(where ...interface{}) (int, error) {
return v.Int(), nil
}
}
return 0, gerror.NewCode(gcode.CodeInternalError, `query count error`)
return 0, gerror.NewCode(
gcode.CodeInternalError,
`query count error: the internal context data is missing. there's' internal issue should be fixed'`,
)
}
return 0, nil
}