Use executor as name
This commit is contained in:
parent
ee0978a108
commit
9e140216aa
|
@ -0,0 +1,38 @@
|
||||||
|
// Copyright 2023 The Xorm Authors. All rights reserved.
|
||||||
|
// Use of this source code is governed by a BSD-style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
package executor
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"database/sql"
|
||||||
|
|
||||||
|
"xorm.io/xorm/v2"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Executor[T any] struct {
|
||||||
|
client xorm.Interface
|
||||||
|
}
|
||||||
|
|
||||||
|
func New[T any](c xorm.Interface) *Executor[T] {
|
||||||
|
return &Executor[T]{
|
||||||
|
client: c,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (q *Executor[T]) Exec(ctx context.Context) (sql.Result, error) {
|
||||||
|
return q.client.Exec()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (q *Executor[T]) All(ctx context.Context) ([]T, error) {
|
||||||
|
var result []T
|
||||||
|
return result, q.client.Find(&result)
|
||||||
|
}
|
||||||
|
|
||||||
|
type Filter interface{}
|
||||||
|
|
||||||
|
func (q *Executor[T]) Filter(ctx context.Context, filter ...Filter) ([]T, error) {
|
||||||
|
// implementation
|
||||||
|
return nil, nil
|
||||||
|
}
|
|
@ -2,7 +2,7 @@
|
||||||
// Use of this source code is governed by a BSD-style
|
// Use of this source code is governed by a BSD-style
|
||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
package executors
|
package executor
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
@ -14,7 +14,7 @@ import (
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestQuerier(t *testing.T) {
|
func TestExecutor(t *testing.T) {
|
||||||
type User struct {
|
type User struct {
|
||||||
Id int64
|
Id int64
|
||||||
Name string
|
Name string
|
||||||
|
@ -25,7 +25,7 @@ func TestQuerier(t *testing.T) {
|
||||||
assert.NoError(t, engine.Sync(new(User)))
|
assert.NoError(t, engine.Sync(new(User)))
|
||||||
|
|
||||||
// create querier
|
// create querier
|
||||||
querier := NewQuerier[User](engine)
|
querier := New[User](engine)
|
||||||
|
|
||||||
users, err := querier.All(context.Background())
|
users, err := querier.All(context.Background())
|
||||||
if err != nil {
|
if err != nil {
|
|
@ -1,33 +0,0 @@
|
||||||
// Copyright 2023 The Xorm Authors. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style
|
|
||||||
// license that can be found in the LICENSE file.
|
|
||||||
|
|
||||||
package executors
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
|
|
||||||
"xorm.io/xorm/v2"
|
|
||||||
)
|
|
||||||
|
|
||||||
type Querier[T any] struct {
|
|
||||||
client xorm.Interface
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewQuerier[T any](c xorm.Interface) *Querier[T] {
|
|
||||||
return &Querier[T]{
|
|
||||||
client: c,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (q *Querier[T]) All(ctx context.Context) ([]T, error) {
|
|
||||||
var result []T
|
|
||||||
return result, q.client.Find(&result)
|
|
||||||
}
|
|
||||||
|
|
||||||
type Filter interface{}
|
|
||||||
|
|
||||||
func (q *Querier[T]) Filter(ctx context.Context, filter ...Filter) ([]T, error) {
|
|
||||||
// implementation
|
|
||||||
return nil, nil
|
|
||||||
}
|
|
Loading…
Reference in New Issue