Documentation
¶
Index ¶
- Constants
- func NewDriver(drv dialect.Driver, options ...Option) dialect.Driver
- func NewDriverVersionTagger() driverVersionTagger
- func NewStaticTagger(tags Tags) staticTagger
- func Skip(ctx context.Context) context.Context
- func WithTag(ctx context.Context, key, val string) context.Context
- type CommentCarrier
- type Driver
- func (d *Driver) BeginTx(ctx context.Context, opts *sql.TxOptions) (dialect.Tx, error)
- func (d *Driver) Exec(ctx context.Context, query string, args, v interface{}) error
- func (d *Driver) ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
- func (d *Driver) Query(ctx context.Context, query string, args, v interface{}) error
- func (d *Driver) QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error)
- func (d *Driver) Tx(ctx context.Context) (dialect.Tx, error)
- type OCTagger
- type OTELTagger
- type Option
- type Tagger
- type Tags
- type Tx
- func (d *Tx) Commit() error
- func (d *Tx) Exec(ctx context.Context, query string, args, v interface{}) error
- func (d *Tx) ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
- func (d *Tx) Query(ctx context.Context, query string, args, v interface{}) error
- func (d *Tx) QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error)
- func (d *Tx) Rollback() error
Constants ¶
const ( KeyDBDriver = "db_driver" KeyFramework = "framework" KeyApplication = "application" KeyRoute = "route" KeyController = "controller" KeyAction = "action" )
Variables ¶
This section is empty.
Functions ¶
func NewDriverVersionTagger ¶
func NewDriverVersionTagger() driverVersionTagger
func NewStaticTagger ¶
func NewStaticTagger(tags Tags) staticTagger
NewStaticTagger returns an Tagger which adds tags to every SQL comment.
func Skip ¶
Skip returns a new Context that tells the Driver to skip the commenting on Query.
client.T.Query().All(sqlcomment.Skip(ctx))
func WithTag ¶
WithTag stores the key and val pair on the context. for example, if you want to add `route` tag to your SQL comment, put the url path on request context:
middleware := func(next http.Handler) http.Handler { fn := func(w http.ResponseWriter, r *http.Request) { ctx := sqlcomment.WithTag(r.Context(), "route", r.URL.Path) next.ServeHTTP(w, r.WithContext(ctx)) } return http.HandlerFunc(fn) }
Types ¶
type CommentCarrier ¶
type CommentCarrier Tags
CommentCarrier implements propagation.TextMapCarrier in order to retrieve trace information from OTEL.
func NewCommentCarrier ¶
func NewCommentCarrier() CommentCarrier
func (CommentCarrier) Get ¶
func (c CommentCarrier) Get(key string) string
Get returns the value associated with the passed key.
func (CommentCarrier) Keys ¶
func (c CommentCarrier) Keys() []string
Keys lists the keys stored in this carrier.
func (CommentCarrier) Set ¶
func (c CommentCarrier) Set(key string, value string)
Set stores the key-value pair.
type Driver ¶
type Driver struct { dialect.Driver // underlying driver. // contains filtered or unexported fields }
Driver is a driver that adds an SQL comment. See: https://google.github.io/sqlcommenter.
func (*Driver) BeginTx ¶
BeginTx wraps the underlying transaction with commenter and calls the underlying driver BeginTx command if it's supported.
func (*Driver) Exec ¶
Exec adds an SQL comment to the original query and calls the underlying driver Exec method.
func (*Driver) ExecContext ¶
func (d *Driver) ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
ExecContext calls ExecContext of the underlying driver, or fails if it is not supported.
func (*Driver) Query ¶
Query adds an SQL comment to the original query and calls the underlying driver Query method.
type OCTagger ¶
type OCTagger struct {
// contains filtered or unexported fields
}
OCTagger is a Tagger that adds `traceparent` and `tracestate` tags to the SQL comment.
type OTELTagger ¶
type OTELTagger struct{}
OTELTagger is a Tagger that adds `traceparent` and `tracestate` tags to the SQL comment.
func NewOTELTagger ¶
func NewOTELTagger() OTELTagger
NewOTELTagger adds OTEL trace information as SQL tags.
type Option ¶
type Option func(*options)
func WithDriverVerTag ¶
func WithDriverVerTag() Option
WithDriverVerTag adds `db_driver` tag with the current version of ent.
func WithTagger ¶
WithTagger sets the taggers to be used to populate the SQL comment.
type Tags ¶
Tags represents key value pairs which can be serialized into SQL comment. see https://google.github.io/sqlcommenter/spec/
func FromContext ¶
FromContext returns the tags stored in ctx, if any.
func (Tags) Marshal ¶
Marshal returns the sqlcomment encoding of t following the spec (see https://google.github.io/sqlcommenter/).
type Tx ¶
Tx is a transaction implementation that adds an SQL comment.
func (*Tx) ExecContext ¶
func (d *Tx) ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
ExecContext logs its params and calls the underlying transaction ExecContext method if it is supported.