Skip to content

Commit

Permalink
feat(internal/query/conn/tx): ExecContext, PrepareContext impls
Browse files Browse the repository at this point in the history
  • Loading branch information
vladDotH committed Nov 15, 2024
1 parent ff26c0b commit 29d44eb
Showing 1 changed file with 42 additions and 2 deletions.
44 changes: 42 additions & 2 deletions internal/query/conn/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ func beginTx(ctx context.Context, c *Conn, txOptions driver.TxOptions) (currentT
return nil, xerrors.WithStackTrace(err)
}

if txc == nil {
return nil, nil
}

nativeTx, err := c.session.Begin(ctx, query.TxSettings(txc))
if err != nil {
return nil, badconn.Map(xerrors.WithStackTrace(err))
Expand Down Expand Up @@ -145,9 +149,45 @@ func (tx *transaction) QueryContext(ctx context.Context, query string, args []dr
func (tx *transaction) ExecContext(ctx context.Context, query string, args []driver.NamedValue) (
_ driver.Result, finalErr error,
) {
panic("not implemented")
onDone := trace.DatabaseSQLOnTxExec(tx.conn.parent.Trace(), &ctx,
stack.FunctionID("github.com/ydb-platform/ydb-go-sdk/v3/internal/query/conn.(*transaction).ExecContext"),
tx.ctx, tx, query,
)
defer func() {
onDone(finalErr)
}()

query, parameters, err := tx.conn.normalize(query, args...)
if err != nil {
return nil, xerrors.WithStackTrace(err)
}
err = tx.tx.Exec(ctx,
query, options.WithParameters(&parameters),
)

if err != nil {
return nil, badconn.Map(xerrors.WithStackTrace(err))
}

return resultNoRows{}, nil
}

func (tx *transaction) PrepareContext(ctx context.Context, query string) (_ driver.Stmt, finalErr error) {
panic("not implemented")
onDone := trace.DatabaseSQLOnTxPrepare(tx.conn.parent.Trace(), &ctx,
stack.FunctionID("github.com/ydb-platform/ydb-go-sdk/v3/internal/query/conn.(*transaction).PrepareContext"),
tx.ctx, tx, query,
)
defer func() {
onDone(finalErr)
}()
if !tx.conn.isReady() {
return nil, badconn.Map(xerrors.WithStackTrace(errNotReadyConn))
}

return &stmt{
conn: tx.conn,
processor: tx,
ctx: ctx,
query: query,
}, nil
}

0 comments on commit 29d44eb

Please sign in to comment.