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:
@@ -12,6 +12,21 @@ var (
|
||||
ErrInvalidRowLockingClause = errors.New("invalid row-locking clause")
|
||||
)
|
||||
|
||||
// DialectForDriver returns a predefined Dialect for the given driver name, or
|
||||
// nil if no Dialect is known for that driver.
|
||||
func DialectForDriver(driverName string) Dialect {
|
||||
switch strings.ToLower(driverName) {
|
||||
case "mysql":
|
||||
return MySQL
|
||||
case "postgres", "pgx":
|
||||
return PostgreSQL
|
||||
case "sqlite", "sqlite3":
|
||||
return SQLite
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// Dialect should be added to the data types passed to SQL templates to
|
||||
// provide methods that deal with SQL implementation-specific traits. It can be
|
||||
// embedded for ease of use, or with a named struct field if any of its methods
|
||||
@@ -21,7 +36,7 @@ type Dialect interface {
|
||||
// than one DBMS (e.g. "postgres" is common to PostgreSQL and to
|
||||
// CockroachDB), while we can maintain different Dialects for the same DBMS
|
||||
// but different versions (e.g. "mysql5" and "mysql8").
|
||||
Name() string
|
||||
DialectName() string
|
||||
|
||||
// Ident returns the given string quoted in a way that is suitable to be
|
||||
// used as an identifier. Database names, schema names, table names, column
|
||||
@@ -135,6 +150,6 @@ var (
|
||||
|
||||
type name string
|
||||
|
||||
func (n name) Name() string {
|
||||
func (n name) DialectName() string {
|
||||
return string(n)
|
||||
}
|
||||
|
||||
@@ -178,7 +178,7 @@ func TestName_Name(t *testing.T) {
|
||||
|
||||
const v = "some dialect name"
|
||||
n := name(v)
|
||||
if n.Name() != v {
|
||||
t.Fatalf("unexpected dialect name %q", n.Name())
|
||||
if n.DialectName() != v {
|
||||
t.Fatalf("unexpected dialect name %q", n.DialectName())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -171,6 +171,51 @@ func (_c *SQLTemplateIface_ArgPlaceholder_Call) RunAndReturn(run func(int) strin
|
||||
return _c
|
||||
}
|
||||
|
||||
// DialectName provides a mock function with given fields:
|
||||
func (_m *SQLTemplateIface) DialectName() string {
|
||||
ret := _m.Called()
|
||||
|
||||
if len(ret) == 0 {
|
||||
panic("no return value specified for DialectName")
|
||||
}
|
||||
|
||||
var r0 string
|
||||
if rf, ok := ret.Get(0).(func() string); ok {
|
||||
r0 = rf()
|
||||
} else {
|
||||
r0 = ret.Get(0).(string)
|
||||
}
|
||||
|
||||
return r0
|
||||
}
|
||||
|
||||
// SQLTemplateIface_DialectName_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'DialectName'
|
||||
type SQLTemplateIface_DialectName_Call struct {
|
||||
*mock.Call
|
||||
}
|
||||
|
||||
// DialectName is a helper method to define mock.On call
|
||||
func (_e *SQLTemplateIface_Expecter) DialectName() *SQLTemplateIface_DialectName_Call {
|
||||
return &SQLTemplateIface_DialectName_Call{Call: _e.mock.On("DialectName")}
|
||||
}
|
||||
|
||||
func (_c *SQLTemplateIface_DialectName_Call) Run(run func()) *SQLTemplateIface_DialectName_Call {
|
||||
_c.Call.Run(func(args mock.Arguments) {
|
||||
run()
|
||||
})
|
||||
return _c
|
||||
}
|
||||
|
||||
func (_c *SQLTemplateIface_DialectName_Call) Return(_a0 string) *SQLTemplateIface_DialectName_Call {
|
||||
_c.Call.Return(_a0)
|
||||
return _c
|
||||
}
|
||||
|
||||
func (_c *SQLTemplateIface_DialectName_Call) RunAndReturn(run func() string) *SQLTemplateIface_DialectName_Call {
|
||||
_c.Call.Return(run)
|
||||
return _c
|
||||
}
|
||||
|
||||
// GetArgs provides a mock function with given fields:
|
||||
func (_m *SQLTemplateIface) GetArgs() []interface{} {
|
||||
ret := _m.Called()
|
||||
@@ -425,51 +470,6 @@ func (_c *SQLTemplateIface_Into_Call) RunAndReturn(run func(reflect.Value, strin
|
||||
return _c
|
||||
}
|
||||
|
||||
// Name provides a mock function with given fields:
|
||||
func (_m *SQLTemplateIface) Name() string {
|
||||
ret := _m.Called()
|
||||
|
||||
if len(ret) == 0 {
|
||||
panic("no return value specified for Name")
|
||||
}
|
||||
|
||||
var r0 string
|
||||
if rf, ok := ret.Get(0).(func() string); ok {
|
||||
r0 = rf()
|
||||
} else {
|
||||
r0 = ret.Get(0).(string)
|
||||
}
|
||||
|
||||
return r0
|
||||
}
|
||||
|
||||
// SQLTemplateIface_Name_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Name'
|
||||
type SQLTemplateIface_Name_Call struct {
|
||||
*mock.Call
|
||||
}
|
||||
|
||||
// Name is a helper method to define mock.On call
|
||||
func (_e *SQLTemplateIface_Expecter) Name() *SQLTemplateIface_Name_Call {
|
||||
return &SQLTemplateIface_Name_Call{Call: _e.mock.On("Name")}
|
||||
}
|
||||
|
||||
func (_c *SQLTemplateIface_Name_Call) Run(run func()) *SQLTemplateIface_Name_Call {
|
||||
_c.Call.Run(func(args mock.Arguments) {
|
||||
run()
|
||||
})
|
||||
return _c
|
||||
}
|
||||
|
||||
func (_c *SQLTemplateIface_Name_Call) Return(_a0 string) *SQLTemplateIface_Name_Call {
|
||||
_c.Call.Return(_a0)
|
||||
return _c
|
||||
}
|
||||
|
||||
func (_c *SQLTemplateIface_Name_Call) RunAndReturn(run func() string) *SQLTemplateIface_Name_Call {
|
||||
_c.Call.Return(run)
|
||||
return _c
|
||||
}
|
||||
|
||||
// Reset provides a mock function with given fields:
|
||||
func (_m *SQLTemplateIface) Reset() {
|
||||
_m.Called()
|
||||
|
||||
@@ -171,6 +171,51 @@ func (_c *WithResults_ArgPlaceholder_Call[T]) RunAndReturn(run func(int) string)
|
||||
return _c
|
||||
}
|
||||
|
||||
// DialectName provides a mock function with given fields:
|
||||
func (_m *WithResults[T]) DialectName() string {
|
||||
ret := _m.Called()
|
||||
|
||||
if len(ret) == 0 {
|
||||
panic("no return value specified for DialectName")
|
||||
}
|
||||
|
||||
var r0 string
|
||||
if rf, ok := ret.Get(0).(func() string); ok {
|
||||
r0 = rf()
|
||||
} else {
|
||||
r0 = ret.Get(0).(string)
|
||||
}
|
||||
|
||||
return r0
|
||||
}
|
||||
|
||||
// WithResults_DialectName_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'DialectName'
|
||||
type WithResults_DialectName_Call[T interface{}] struct {
|
||||
*mock.Call
|
||||
}
|
||||
|
||||
// DialectName is a helper method to define mock.On call
|
||||
func (_e *WithResults_Expecter[T]) DialectName() *WithResults_DialectName_Call[T] {
|
||||
return &WithResults_DialectName_Call[T]{Call: _e.mock.On("DialectName")}
|
||||
}
|
||||
|
||||
func (_c *WithResults_DialectName_Call[T]) Run(run func()) *WithResults_DialectName_Call[T] {
|
||||
_c.Call.Run(func(args mock.Arguments) {
|
||||
run()
|
||||
})
|
||||
return _c
|
||||
}
|
||||
|
||||
func (_c *WithResults_DialectName_Call[T]) Return(_a0 string) *WithResults_DialectName_Call[T] {
|
||||
_c.Call.Return(_a0)
|
||||
return _c
|
||||
}
|
||||
|
||||
func (_c *WithResults_DialectName_Call[T]) RunAndReturn(run func() string) *WithResults_DialectName_Call[T] {
|
||||
_c.Call.Return(run)
|
||||
return _c
|
||||
}
|
||||
|
||||
// GetArgs provides a mock function with given fields:
|
||||
func (_m *WithResults[T]) GetArgs() []interface{} {
|
||||
ret := _m.Called()
|
||||
@@ -425,51 +470,6 @@ func (_c *WithResults_Into_Call[T]) RunAndReturn(run func(reflect.Value, string)
|
||||
return _c
|
||||
}
|
||||
|
||||
// Name provides a mock function with given fields:
|
||||
func (_m *WithResults[T]) Name() string {
|
||||
ret := _m.Called()
|
||||
|
||||
if len(ret) == 0 {
|
||||
panic("no return value specified for Name")
|
||||
}
|
||||
|
||||
var r0 string
|
||||
if rf, ok := ret.Get(0).(func() string); ok {
|
||||
r0 = rf()
|
||||
} else {
|
||||
r0 = ret.Get(0).(string)
|
||||
}
|
||||
|
||||
return r0
|
||||
}
|
||||
|
||||
// WithResults_Name_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Name'
|
||||
type WithResults_Name_Call[T interface{}] struct {
|
||||
*mock.Call
|
||||
}
|
||||
|
||||
// Name is a helper method to define mock.On call
|
||||
func (_e *WithResults_Expecter[T]) Name() *WithResults_Name_Call[T] {
|
||||
return &WithResults_Name_Call[T]{Call: _e.mock.On("Name")}
|
||||
}
|
||||
|
||||
func (_c *WithResults_Name_Call[T]) Run(run func()) *WithResults_Name_Call[T] {
|
||||
_c.Call.Run(func(args mock.Arguments) {
|
||||
run()
|
||||
})
|
||||
return _c
|
||||
}
|
||||
|
||||
func (_c *WithResults_Name_Call[T]) Return(_a0 string) *WithResults_Name_Call[T] {
|
||||
_c.Call.Return(_a0)
|
||||
return _c
|
||||
}
|
||||
|
||||
func (_c *WithResults_Name_Call[T]) RunAndReturn(run func() string) *WithResults_Name_Call[T] {
|
||||
_c.Call.Return(run)
|
||||
return _c
|
||||
}
|
||||
|
||||
// Reset provides a mock function with given fields:
|
||||
func (_m *WithResults[T]) Reset() {
|
||||
_m.Called()
|
||||
|
||||
Reference in New Issue
Block a user