From 9e140216aaab9f49fba40688357fefa22e5f7c0c Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Sat, 28 Oct 2023 17:45:30 +0800 Subject: [PATCH] Use executor as name --- executor/executor.go | 38 +++++++++++++++++++ .../executor_test.go | 6 +-- executors/querier.go | 33 ---------------- 3 files changed, 41 insertions(+), 36 deletions(-) create mode 100644 executor/executor.go rename executors/querier_test.go => executor/executor_test.go (87%) delete mode 100644 executors/querier.go diff --git a/executor/executor.go b/executor/executor.go new file mode 100644 index 00000000..7804d3a3 --- /dev/null +++ b/executor/executor.go @@ -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 +} diff --git a/executors/querier_test.go b/executor/executor_test.go similarity index 87% rename from executors/querier_test.go rename to executor/executor_test.go index 2fa11e8b..e0b83363 100644 --- a/executors/querier_test.go +++ b/executor/executor_test.go @@ -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 { diff --git a/executors/querier.go b/executors/querier.go deleted file mode 100644 index 817d6a67..00000000 --- a/executors/querier.go +++ /dev/null @@ -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 -}