Copyright 2021 The Go 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 database

import (
	
	
	
	

	
)
RegisterOCWrapper registers a driver that wraps the OpenCensus driver, which in turn wraps the driver named as the first argument.
Get the driver to wrap.
	,  := sql.Open(, "")
	if  != nil {
		return "", 
	}
	 := .Driver()
	if  := .Close();  != nil {
		return "", 
	}
	 := "ocWrapper-" + 
	sql.Register(, &wrapOCDriver{, })
	return , nil
}

type wrapOCDriver struct {
	underlying driver.Driver
	opts       []ocsql.TraceOption
}
Open implements database/sql/driver.Driver.
func ( *wrapOCDriver) ( string) (driver.Conn, error) {
	,  := .underlying.Open()
	if  != nil {
		return nil, 
	}
	 := ocsql.WrapConn(, .opts...)
	return &wrapConn{, .(iconn)}, nil
}

type iconn interface {
	driver.Pinger
	driver.ExecerContext
	driver.QueryerContext
	driver.Conn
	driver.ConnPrepareContext
	driver.ConnBeginTx
}
A wrapConn knows about both the underlying Conn, and the OpenCensus Conn that wraps it. It delegates all calls to the OpenCensus Conn, but the underlying conn is available to this package.
Ping and all the following methods implement driver.Conn and related interfaces, listed in the iconn interface above.
func ( *wrapConn) ( context.Context) error { return .oc.Ping() }

func ( *wrapConn) ( string) (driver.Stmt, error) { return .oc.Prepare() }
func ( *wrapConn) () error                              { return .oc.Close() }
func ( *wrapConn) () (driver.Tx, error)                 { return nil, errors.New("unimplmented") }

func ( *wrapConn) ( context.Context,  string,  []driver.NamedValue) (driver.Result, error) {
	return .oc.ExecContext(, , )
}

func ( *wrapConn) ( context.Context,  string,  []driver.NamedValue) (driver.Rows, error) {
	return .oc.QueryContext(, , )
}

func ( *wrapConn) ( context.Context,  string) (driver.Stmt, error) {
	return .oc.PrepareContext(, )
}

func ( *wrapConn) ( context.Context,  driver.TxOptions) (driver.Tx, error) {
	return .oc.BeginTx(, )