Skip to content

Commit

Permalink
feat(internal/query/conn): stmts
Browse files Browse the repository at this point in the history
  • Loading branch information
vladDotH committed Nov 15, 2024
1 parent daa6a68 commit ff26c0b
Showing 1 changed file with 82 additions and 0 deletions.
82 changes: 82 additions & 0 deletions internal/query/conn/stmt.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package conn

import (
"context"
"database/sql/driver"

"github.com/ydb-platform/ydb-go-sdk/v3/internal/stack"
"github.com/ydb-platform/ydb-go-sdk/v3/internal/table/conn/badconn"
"github.com/ydb-platform/ydb-go-sdk/v3/internal/xerrors"
"github.com/ydb-platform/ydb-go-sdk/v3/trace"
)

type stmt struct {
conn *Conn
processor interface {
driver.ExecerContext
driver.QueryerContext
}
query string
ctx context.Context //nolint:containedctx
}

var (
_ driver.Stmt = &stmt{}
_ driver.StmtQueryContext = &stmt{}
_ driver.StmtExecContext = &stmt{}
)

func (stmt *stmt) QueryContext(ctx context.Context, args []driver.NamedValue) (_ driver.Rows, finalErr error) {
onDone := trace.DatabaseSQLOnStmtQuery(stmt.conn.parent.Trace(), &ctx,
stack.FunctionID("github.com/ydb-platform/ydb-go-sdk/v3/internal/query/conn.(*stmt).QueryContext"),
stmt.ctx, stmt.query,
)
defer func() {
onDone(finalErr)
}()
if !stmt.conn.isReady() {
return nil, badconn.Map(xerrors.WithStackTrace(errNotReadyConn))
}

return stmt.processor.QueryContext(ctx, stmt.query, args)
}

func (stmt *stmt) ExecContext(ctx context.Context, args []driver.NamedValue) (_ driver.Result, finalErr error) {
onDone := trace.DatabaseSQLOnStmtExec(stmt.conn.parent.Trace(), &ctx,
stack.FunctionID("github.com/ydb-platform/ydb-go-sdk/v3/internal/query/conn.(*stmt).ExecContext"),
stmt.ctx, stmt.query,
)
defer func() {
onDone(finalErr)
}()
if !stmt.conn.isReady() {
return nil, badconn.Map(xerrors.WithStackTrace(errNotReadyConn))
}
return stmt.processor.ExecContext(ctx, stmt.query, args)
}

func (stmt *stmt) NumInput() int {
return -1
}

func (stmt *stmt) Close() (finalErr error) {
var (
ctx = stmt.ctx
onDone = trace.DatabaseSQLOnStmtClose(stmt.conn.parent.Trace(), &ctx,
stack.FunctionID("github.com/ydb-platform/ydb-go-sdk/v3/internal/query/conn.(*stmt).Close"),
)
)
defer func() {
onDone(finalErr)
}()

return nil
}

func (stmt *stmt) Exec([]driver.Value) (driver.Result, error) {
return nil, errDeprecated
}

func (stmt *stmt) Query([]driver.Value) (driver.Rows, error) {
return nil, errDeprecated
}

0 comments on commit ff26c0b

Please sign in to comment.