Use executor as name

This commit is contained in:
Lunny Xiao 2023-10-28 17:45:30 +08:00
parent ee0978a108
commit 9e140216aa
No known key found for this signature in database
GPG Key ID: C3B7C91B632F738A
3 changed files with 41 additions and 36 deletions

38
executor/executor.go Normal file
View File

@ -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
}

View File

@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package executors
package executor
import (
"context"
@ -14,7 +14,7 @@ import (
"github.com/stretchr/testify/assert"
)
func TestQuerier(t *testing.T) {
func TestExecutor(t *testing.T) {
type User struct {
Id int64
Name string
@ -25,7 +25,7 @@ func TestQuerier(t *testing.T) {
assert.NoError(t, engine.Sync(new(User)))
// create querier
querier := NewQuerier[User](engine)
querier := New[User](engine)
users, err := querier.All(context.Background())
if err != nil {

View File

@ -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
}