Resource server improvements and fixes (#90715)
* cleanup dependencies and improve list method * Improve Resource Server API, remove unnecessary dependencies * Reduce the API footprint of ResourceDBInterface and its implementation * Improve LifecycleHooks to use context * Improve testing * reduce API size and improve code * sqltemplate: add DialectForDriver func and improve naming * improve lifecycle API * many small fixes after adding more tests
This commit is contained in:
@@ -57,33 +57,6 @@ var (
|
||||
}
|
||||
)
|
||||
|
||||
// SQLError is an error returned by the database, which includes additionally
|
||||
// debugging information about what was sent to the database.
|
||||
type SQLError struct {
|
||||
Err error
|
||||
CallType string // either Query, QueryRow or Exec
|
||||
TemplateName string
|
||||
Query string
|
||||
RawQuery string
|
||||
ScanDest []any
|
||||
|
||||
// potentially regulated information is not exported and only directly
|
||||
// available for local testing and local debugging purposes, making sure it
|
||||
// is never marshaled to JSON or any other serialization.
|
||||
|
||||
arguments []any
|
||||
}
|
||||
|
||||
func (e SQLError) Unwrap() error {
|
||||
return e.Err
|
||||
}
|
||||
|
||||
func (e SQLError) Error() string {
|
||||
return fmt.Sprintf("%s: %s with %d input arguments and %d output "+
|
||||
"destination arguments: %v", e.TemplateName, e.CallType,
|
||||
len(e.arguments), len(e.ScanDest), e.Err)
|
||||
}
|
||||
|
||||
type sqlResourceRequest struct {
|
||||
*sqltemplate.SQLTemplate
|
||||
GUID string
|
||||
@@ -149,6 +122,18 @@ func (r sqlResourceListRequest) Validate() error {
|
||||
return nil // TODO
|
||||
}
|
||||
|
||||
func (r sqlResourceListRequest) Results() (*resource.ResourceWrapper, error) {
|
||||
// sqlResourceListRequest is a set-returning query. As such, it
|
||||
// should not return its *Response, since that will be overwritten in the
|
||||
// next call to `Scan`, so it needs to return a copy of it. Note, though,
|
||||
// that it is safe to return the same `Response.Value` since `Scan`
|
||||
// allocates a new slice of bytes each time.
|
||||
return &resource.ResourceWrapper{
|
||||
ResourceVersion: r.Response.ResourceVersion,
|
||||
Value: r.Response.Value,
|
||||
}, nil
|
||||
}
|
||||
|
||||
type historyListRequest struct {
|
||||
ResourceVersion, Limit, Offset int64
|
||||
Options *resource.ListOptions
|
||||
@@ -163,6 +148,18 @@ func (r sqlResourceHistoryListRequest) Validate() error {
|
||||
return nil // TODO
|
||||
}
|
||||
|
||||
func (r sqlResourceHistoryListRequest) Results() (*resource.ResourceWrapper, error) {
|
||||
// sqlResourceHistoryListRequest is a set-returning query. As such, it
|
||||
// should not return its *Response, since that will be overwritten in the
|
||||
// next call to `Scan`, so it needs to return a copy of it. Note, though,
|
||||
// that it is safe to return the same `Response.Value` since `Scan`
|
||||
// allocates a new slice of bytes each time.
|
||||
return &resource.ResourceWrapper{
|
||||
ResourceVersion: r.Response.ResourceVersion,
|
||||
Value: r.Response.Value,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// update RV
|
||||
|
||||
type sqlResourceUpdateRVRequest struct {
|
||||
|
||||
Reference in New Issue
Block a user