sql

package module
v0.0.1-beta Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 30, 2022 License: Apache-2.0 Imports: 5 Imported by: 4

README

go-sql-driver [In development]

SQLcommenter is a plugin/middleware/wrapper to augment application related information/tags with SQL Statements that can be used later to correlate user code with SQL statements.

Installation

Install from source
  • Clone the source
  • In terminal go inside the client folder location where we need to import sqlcommenter go-sql module and enter the below commands
go mod edit -replace google.com/sqlcommenter=path/to/google/sqlcommenter/go-sql

go mod tiny

go get google.com/sqlcommenter/gosql
Install from github [To be added]

Usage

Please use the sqlcommenter's default go-sql database driver to execute statements. Due to inherent nature of Go, the safer way to pass information from framework to database driver is via context. So, it is recommended to use the context based methods of DB interface like QueryContext, ExecContext and PrepareContext.

db, err := gosql.Open("<driver>", "<connectionString>", sqlcommenter.CommenterOptions{<tag>:<bool>})
Configuration

Users are given control over what tags they want to append by using core.CommenterOptions struct.

type CommenterOptions struct {
	EnableDBDriver    bool
	EnableTraceparent bool  // OpenTelemetry trace information
	EnableRoute       bool  // applicable for web frameworks
	EnableFramework   bool  // applicable for web frameworks
	EnableController  bool  // applicable for web frameworks
	EnableAction      bool  // applicable for web frameworks
	}
Framework Supported

Options

With Go SqlCommenter, we have configuration to choose which tags to be appended to the comment.

Options Included by default? go-sql-driver
DBDriver go-sql-driver

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DB

type DB struct {
	*sql.DB
	// contains filtered or unexported fields
}

func Open

func Open(driverName string, dataSourceName string, options core.CommenterOptions) (*DB, error)

func (*DB) Exec

func (db *DB) Exec(query string, args ...any) (sql.Result, error)

func (*DB) ExecContext

func (db *DB) ExecContext(ctx context.Context, query string, args ...any) (sql.Result, error)

func (*DB) Prepare

func (db *DB) Prepare(query string) (*sql.Stmt, error)

func (*DB) PrepareContext

func (db *DB) PrepareContext(ctx context.Context, query string) (*sql.Stmt, error)

func (*DB) Query

func (db *DB) Query(query string, args ...any) (*sql.Rows, error)

func (*DB) QueryContext

func (db *DB) QueryContext(ctx context.Context, query string, args ...any) (*sql.Rows, error)

func (*DB) QueryRow

func (db *DB) QueryRow(query string, args ...interface{}) *sql.Row

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL