From 1ade20825fe81fa5fd0010ebe399d209f6d3a482 Mon Sep 17 00:00:00 2001 From: Lz Date: Fri, 26 Apr 2024 09:57:06 +0800 Subject: [PATCH] fix(connector): added `Connector` interface (#43) --- connector.go | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 connector.go diff --git a/connector.go b/connector.go new file mode 100644 index 0000000..cc6107c --- /dev/null +++ b/connector.go @@ -0,0 +1,55 @@ +package sqle + +import ( + "context" + "database/sql" +) + +// Connector represents a database connector that provides methods for executing queries and commands. +// Context and Tx both implement this interface. +type Connector interface { + // Query executes a query that returns multiple rows. + // It takes a query string and optional arguments. + // It returns a pointer to a Rows object and an error, if any. + Query(query string, args ...any) (*Rows, error) + + // QueryBuilder executes a query using a Builder object. + // It takes a context and a Builder object. + // It returns a pointer to a Rows object and an error, if any. + QueryBuilder(ctx context.Context, b *Builder) (*Rows, error) + + // QueryContext executes a query that returns multiple rows using a context. + // It takes a context, a query string, and optional arguments. + // It returns a pointer to a Rows object and an error, if any. + QueryContext(ctx context.Context, query string, args ...any) (*Rows, error) + + // QueryRow executes a query that returns a single row. + // It takes a query string and optional arguments. + // It returns a pointer to a Row object. + QueryRow(query string, args ...any) *Row + + // QueryRowBuilder executes a query that returns a single row using a Builder object. + // It takes a context and a Builder object. + // It returns a pointer to a Row object. + QueryRowBuilder(ctx context.Context, b *Builder) *Row + + // QueryRowContext executes a query that returns a single row using a context. + // It takes a context, a query string, and optional arguments. + // It returns a pointer to a Row object. + QueryRowContext(ctx context.Context, query string, args ...any) *Row + + // Exec executes a query that doesn't return any rows. + // It takes a query string and optional arguments. + // It returns a sql.Result object and an error, if any. + Exec(query string, args ...any) (sql.Result, error) + + // ExecContext executes a query that doesn't return any rows using a context. + // It takes a context, a query string, and optional arguments. + // It returns a sql.Result object and an error, if any. + ExecContext(ctx context.Context, query string, args ...any) (sql.Result, error) + + // ExecBuilder executes a query that doesn't return any rows using a Builder object. + // It takes a context and a Builder object. + // It returns a sql.Result object and an error, if any. + ExecBuilder(ctx context.Context, b *Builder) (sql.Result, error) +}