From 0be826dd40630c314c470cc0c2b35fccb4b787de Mon Sep 17 00:00:00 2001 From: Louis Duchemin <17616580+lsdch@users.noreply.github.com> Date: Tue, 12 Mar 2024 17:30:01 +0100 Subject: [PATCH] Expose a common interface between Client and Tx (#302) --- export.go | 4 ++++ internal/client/executor.go | 29 +++++++++++++++++++++++++++++ rstdocs/api.rst | 12 ++++++++++++ 3 files changed, 45 insertions(+) create mode 100644 internal/client/executor.go diff --git a/export.go b/export.go index fb78edf..bb0c13b 100644 --- a/export.go +++ b/export.go @@ -71,6 +71,10 @@ type ( // ErrorTag is the argument type to Error.HasTag(). ErrorTag = edgedb.ErrorTag + // Executor is a common interface between Client and Tx, + // that can run queries on an EdgeDB database. + Executor = edgedb.Executor + // IsolationLevel documentation can be found here // https://www.edgedb.com/docs/reference/edgeql/tx_start#parameters IsolationLevel = edgedb.IsolationLevel diff --git a/internal/client/executor.go b/internal/client/executor.go new file mode 100644 index 0000000..17262b2 --- /dev/null +++ b/internal/client/executor.go @@ -0,0 +1,29 @@ +// This source file is part of the EdgeDB open source project. +// +// Copyright EdgeDB Inc. and the EdgeDB authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package edgedb + +import "context" + +// Executor is a common interface between *Client and *Tx, +// that can run queries on an EdgeDB database. +type Executor interface { + Execute(context.Context, string, ...any) error + Query(context.Context, string, any, ...any) error + QueryJSON(context.Context, string, *[]byte, ...any) error + QuerySingle(context.Context, string, any, ...any) error + QuerySingleJSON(context.Context, string, any, ...any) error +} diff --git a/rstdocs/api.rst b/rstdocs/api.rst index ccad94c..0368c58 100644 --- a/rstdocs/api.rst +++ b/rstdocs/api.rst @@ -47,6 +47,18 @@ ErrorTag is the argument type to Error.HasTag(). type ErrorTag = edgedb.ErrorTag +*type* Executor +--------------- + +Executor is a common interface between Client and Tx, +that can run queries on an EdgeDB database. + + +.. code-block:: go + + type Executor = edgedb.Executor + + *type* IsolationLevel ---------------------