database

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2025 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package database provides cross-database query building utilities

Package database provides performance tracking for database operations

Index

Constants

View Source
const (
	PostgreSQL = "postgresql"
	Oracle     = "oracle"
)

Database type constants

Variables

This section is empty.

Functions

func GetSupportedDatabaseTypes

func GetSupportedDatabaseTypes() []string

GetSupportedDatabaseTypes returns a list of supported database types

func ValidateDatabaseType

func ValidateDatabaseType(dbType string) error

ValidateDatabaseType checks if the database type is supported

Types

type Interface

type Interface = database.Interface

Interface defines the common database operations supported by the framework

func NewConnection

func NewConnection(cfg *config.DatabaseConfig, log logger.Logger) (Interface, error)

NewConnection creates a new database connection based on the configuration

type QueryBuilder

type QueryBuilder struct {
	// contains filtered or unexported fields
}

QueryBuilder provides vendor-specific SQL query building

func NewQueryBuilder

func NewQueryBuilder(vendor string) *QueryBuilder

NewQueryBuilder creates a new query builder for the specified database vendor

func (*QueryBuilder) BuildBooleanValue

func (qb *QueryBuilder) BuildBooleanValue(value bool) interface{}

BuildBooleanValue converts Go boolean to vendor-specific boolean representation

func (*QueryBuilder) BuildCaseInsensitiveLike

func (qb *QueryBuilder) BuildCaseInsensitiveLike(column, value string) squirrel.Sqlizer

BuildCaseInsensitiveLike creates a case-insensitive LIKE condition based on vendor

func (*QueryBuilder) BuildCurrentTimestamp

func (qb *QueryBuilder) BuildCurrentTimestamp() string

BuildCurrentTimestamp returns the current timestamp function for the vendor

func (*QueryBuilder) BuildLimitOffset

func (qb *QueryBuilder) BuildLimitOffset(query squirrel.SelectBuilder, limit, offset int) squirrel.SelectBuilder

BuildLimitOffset creates LIMIT/OFFSET clause based on vendor

func (*QueryBuilder) BuildUUIDGeneration

func (qb *QueryBuilder) BuildUUIDGeneration() string

BuildUUIDGeneration returns the UUID generation function for the vendor

func (*QueryBuilder) BuildUpsert

func (qb *QueryBuilder) BuildUpsert(table string, conflictColumns []string, insertColumns, updateColumns map[string]interface{}) (query string, args []interface{}, err error)

BuildUpsert creates an UPSERT/MERGE query based on vendor

func (*QueryBuilder) Delete

func (qb *QueryBuilder) Delete(table string) squirrel.DeleteBuilder

Delete creates a new DELETE query builder

func (*QueryBuilder) EscapeIdentifier

func (qb *QueryBuilder) EscapeIdentifier(identifier string) string

EscapeIdentifier escapes database identifiers (table names, column names) for the vendor

func (*QueryBuilder) Insert

func (qb *QueryBuilder) Insert(table string) squirrel.InsertBuilder

Insert creates a new INSERT query builder

func (*QueryBuilder) Select

func (qb *QueryBuilder) Select(columns ...string) squirrel.SelectBuilder

Select creates a new SELECT query builder

func (*QueryBuilder) Update

func (qb *QueryBuilder) Update(table string) squirrel.UpdateBuilder

Update creates a new UPDATE query builder

func (*QueryBuilder) Vendor

func (qb *QueryBuilder) Vendor() string

Vendor returns the database vendor

type TrackedDB

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

TrackedDB wraps sql.DB to provide request-scoped performance tracking

func NewTrackedDB

func NewTrackedDB(db *sql.DB, log logger.Logger, vendor string) *TrackedDB

NewTrackedDB creates a new tracked database connection

func (*TrackedDB) ExecContext

func (db *TrackedDB) ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)

ExecContext executes a query without returning rows and tracks performance

func (*TrackedDB) PrepareContext

func (db *TrackedDB) PrepareContext(ctx context.Context, query string) (*TrackedStmt, error)

PrepareContext prepares a statement with context and tracks performance

func (*TrackedDB) QueryContext

func (db *TrackedDB) QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error)

QueryContext executes a query with context and tracks performance

func (*TrackedDB) QueryRowContext

func (db *TrackedDB) QueryRowContext(ctx context.Context, query string, args ...interface{}) *sql.Row

QueryRowContext executes a single row query with context and tracks performance

type TrackedStmt

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

TrackedStmt wraps sql.Stmt to provide performance tracking for prepared statements

func (*TrackedStmt) ExecContext

func (s *TrackedStmt) ExecContext(ctx context.Context, args ...interface{}) (sql.Result, error)

ExecContext executes a prepared statement with context and tracks performance

func (*TrackedStmt) QueryContext

func (s *TrackedStmt) QueryContext(ctx context.Context, args ...interface{}) (*sql.Rows, error)

QueryContext executes a prepared query with context and tracks performance

func (*TrackedStmt) QueryRowContext

func (s *TrackedStmt) QueryRowContext(ctx context.Context, args ...interface{}) *sql.Row

QueryRowContext executes a prepared single row query with context and tracks performance

type TrackedTx

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

TrackedTx wraps sql.Tx to provide performance tracking for transactions

func (*TrackedTx) ExecContext

func (tx *TrackedTx) ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)

ExecContext executes a query within a transaction and tracks performance

func (*TrackedTx) QueryContext

func (tx *TrackedTx) QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error)

QueryContext executes a query within a transaction with context and tracks performance

func (*TrackedTx) QueryRowContext

func (tx *TrackedTx) QueryRowContext(ctx context.Context, query string, args ...interface{}) *sql.Row

QueryRowContext executes a single row query within a transaction and tracks performance

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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