db

package
v0.3.0-beta Latest Latest
Warning

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

Go to latest
Published: Mar 3, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExtractPrimaryTableFromJoin

func ExtractPrimaryTableFromJoin(sqlQuery string) string

func ExtractTableNameFromSQL

func ExtractTableNameFromSQL(sqlQuery string) string

func FormatTableData

func FormatTableData(rows *sql.Rows) (columns []string, data [][]string, err error)

func FormatTableDataWithTypes

func FormatTableDataWithTypes(rows *sql.Rows) (columns []string, columnTypes []string, data [][]string, err error)

func GetNextQueryId

func GetNextQueryId(queries map[string]Query) (id int)

func GetSupportedDBTypes

func GetSupportedDBTypes() []string

GetSupportedDBTypes returns a list of all supported database types.

func HasJoinClause

func HasJoinClause(sqlQuery string) bool

func InferDBType

func InferDBType(connString string) string

InferDBType attempts to infer the database type from a connection string. Returns the detected type or empty string if unable to infer.

Types

type BaseConnection

type BaseConnection struct {
	Name       string
	DbType     string
	ConnString string
	Schema     string
	Queries    map[string]Query
	LastQuery  Query
}

func (*BaseConnection) ApplyRowLimit

func (b *BaseConnection) ApplyRowLimit(sql string, limit int) string

func (*BaseConnection) BuildDeleteStatement

func (b *BaseConnection) BuildDeleteStatement(tableName, primaryKeyCol, pkValue string) string

func (*BaseConnection) BuildUpdateStatement

func (b *BaseConnection) BuildUpdateStatement(
	tableName, columnName, currentValue, pkColumn, pkValue string,
) string

func (*BaseConnection) Close

func (b *BaseConnection) Close() error

func (*BaseConnection) Exec

func (b *BaseConnection) Exec(sql string, args ...any) error

func (*BaseConnection) ExecQuery

func (b *BaseConnection) ExecQuery(sql string, args ...any) (*sql.Rows, error)

func (*BaseConnection) GetConnString

func (b *BaseConnection) GetConnString() string

func (*BaseConnection) GetDbType

func (b *BaseConnection) GetDbType() string

func (*BaseConnection) GetForeignKeys

func (b *BaseConnection) GetForeignKeys(tableName string) ([]ForeignKey, error)

func (*BaseConnection) GetForeignKeysReferencingTable

func (b *BaseConnection) GetForeignKeysReferencingTable(tableName string) ([]ForeignKey, error)

func (*BaseConnection) GetInfoSQL

func (b *BaseConnection) GetInfoSQL(infoType string) string

func (*BaseConnection) GetLastQuery

func (b *BaseConnection) GetLastQuery() Query

func (*BaseConnection) GetName

func (b *BaseConnection) GetName() string

func (*BaseConnection) GetPlaceholder

func (b *BaseConnection) GetPlaceholder(paramIndex int) string

func (*BaseConnection) GetQueries

func (b *BaseConnection) GetQueries() map[string]Query

func (*BaseConnection) GetSchema

func (b *BaseConnection) GetSchema() string

func (*BaseConnection) GetTableMetadata

func (b *BaseConnection) GetTableMetadata(
	tableName string,
) (*TableMetadata, error)

func (*BaseConnection) GetTables

func (b *BaseConnection) GetTables() ([]string, error)

func (*BaseConnection) GetViews

func (b *BaseConnection) GetViews() ([]string, error)

func (*BaseConnection) Open

func (b *BaseConnection) Open() error

func (*BaseConnection) Ping

func (b *BaseConnection) Ping() error

func (*BaseConnection) Query

func (b *BaseConnection) Query(name string, args ...any) (any, error)

func (*BaseConnection) SetLastQuery

func (b *BaseConnection) SetLastQuery(
	query Query,
)

func (*BaseConnection) SetQueries

func (b *BaseConnection) SetQueries(
	queries map[string]Query,
)

func (*BaseConnection) SetSchema

func (b *BaseConnection) SetSchema(
	schema string,
)

type ClickHouseConnection

type ClickHouseConnection struct {
	*BaseConnection
	// contains filtered or unexported fields
}

func NewClickHouseConnection

func NewClickHouseConnection(name, connStr string) (*ClickHouseConnection, error)

func (*ClickHouseConnection) ApplyRowLimit

func (c *ClickHouseConnection) ApplyRowLimit(sql string, limit int) string

func (*ClickHouseConnection) BuildDeleteStatement

func (c *ClickHouseConnection) BuildDeleteStatement(tableName, primaryKeyCol, pkValue string) string

func (*ClickHouseConnection) BuildUpdateStatement

func (c *ClickHouseConnection) BuildUpdateStatement(tableName, columnName, currentValue, pkColumn, pkValue string) string

func (*ClickHouseConnection) Close

func (c *ClickHouseConnection) Close() error

func (*ClickHouseConnection) Exec

func (c *ClickHouseConnection) Exec(sql string, args ...any) error

func (*ClickHouseConnection) ExecQuery

func (c *ClickHouseConnection) ExecQuery(sql string, args ...any) (*sql.Rows, error)

func (*ClickHouseConnection) GetForeignKeys

func (c *ClickHouseConnection) GetForeignKeys(tableName string) ([]ForeignKey, error)

func (*ClickHouseConnection) GetForeignKeysReferencingTable

func (c *ClickHouseConnection) GetForeignKeysReferencingTable(tableName string) ([]ForeignKey, error)

func (*ClickHouseConnection) GetInfoSQL

func (c *ClickHouseConnection) GetInfoSQL(infoType string) string

func (*ClickHouseConnection) GetPlaceholder

func (c *ClickHouseConnection) GetPlaceholder(paramIndex int) string

func (*ClickHouseConnection) GetTableMetadata

func (c *ClickHouseConnection) GetTableMetadata(tableName string) (*TableMetadata, error)

func (*ClickHouseConnection) GetTables

func (c *ClickHouseConnection) GetTables() ([]string, error)

func (*ClickHouseConnection) GetUniqueConstraints

func (c *ClickHouseConnection) GetUniqueConstraints(tableName string) ([]string, error)

func (*ClickHouseConnection) GetViews

func (c *ClickHouseConnection) GetViews() ([]string, error)

func (*ClickHouseConnection) Open

func (c *ClickHouseConnection) Open() error

func (*ClickHouseConnection) Ping

func (c *ClickHouseConnection) Ping() error

func (*ClickHouseConnection) Query

func (c *ClickHouseConnection) Query(queryName string, args ...any) (any, error)

type Connection

type Connection struct {
	Name       string
	DBType     string
	ConnString string
	Username   string
	Password   string
	DB         *sql.DB
	Queries    map[string]Query
}

func NewConnection

func NewConnection(name, dbType, connStr, user, pass string) *Connection

func (*Connection) Close

func (c *Connection) Close() error

func (*Connection) Open

func (c *Connection) Open() error

func (*Connection) Query

func (c *Connection) Query(queryName string, args ...any) ([]string, [][]string, error)

type DatabaseConnection

type DatabaseConnection interface {
	Open() error
	Ping() error
	Close() error
	Query(queryName string, args ...any) (any, error)
	ExecQuery(sql string, args ...any) (*sql.Rows, error)
	Exec(sql string, args ...any) error
	GetInfoSQL(infoType string) string
	GetTables() ([]string, error)
	GetViews() ([]string, error)
	GetTableMetadata(tableName string) (*TableMetadata, error)
	GetForeignKeys(tableName string) ([]ForeignKey, error)
	GetForeignKeysReferencingTable(tableName string) ([]ForeignKey, error)
	GetUniqueConstraints(tableName string) ([]string, error)
	BuildUpdateStatement(
		tableName, columnName, currentValue, pkColumn, pkValue string,
	) string
	BuildDeleteStatement(tableName, primaryKeyCol, pkValue string) string
	ApplyRowLimit(sql string, limit int) string
	GetPlaceholder(paramIndex int) string

	GetName() string
	GetDbType() string
	GetConnString() string
	GetSchema() string
	GetQueries() map[string]Query
	GetLastQuery() Query

	SetSchema(string)
	SetLastQuery(Query)
	SetQueries(map[string]Query)
}

func CreateConnection

func CreateConnection(name, dbType, connString string) (DatabaseConnection, error)

type FirebirdConnection

type FirebirdConnection struct {
	*BaseConnection
	// contains filtered or unexported fields
}

func NewFirebirdConnection

func NewFirebirdConnection(name, connStr string) (*FirebirdConnection, error)

func (*FirebirdConnection) ApplyRowLimit

func (f *FirebirdConnection) ApplyRowLimit(sqlStr string, limit int) string

func (*FirebirdConnection) BuildDeleteStatement

func (f *FirebirdConnection) BuildDeleteStatement(tableName, primaryKeyCol, pkValue string) string

func (*FirebirdConnection) Close

func (f *FirebirdConnection) Close() error

func (*FirebirdConnection) Exec

func (f *FirebirdConnection) Exec(sqlStr string, args ...any) error

func (*FirebirdConnection) ExecQuery

func (f *FirebirdConnection) ExecQuery(sqlStr string, args ...any) (*sql.Rows, error)

func (*FirebirdConnection) GetForeignKeys

func (f *FirebirdConnection) GetForeignKeys(tableName string) ([]ForeignKey, error)

func (*FirebirdConnection) GetForeignKeysReferencingTable

func (f *FirebirdConnection) GetForeignKeysReferencingTable(tableName string) ([]ForeignKey, error)

func (*FirebirdConnection) GetInfoSQL

func (f *FirebirdConnection) GetInfoSQL(infoType string) string

func (*FirebirdConnection) GetPlaceholder

func (f *FirebirdConnection) GetPlaceholder(paramIndex int) string

func (*FirebirdConnection) GetTableMetadata

func (f *FirebirdConnection) GetTableMetadata(tableName string) (*TableMetadata, error)

func (*FirebirdConnection) GetTables

func (f *FirebirdConnection) GetTables() ([]string, error)

func (*FirebirdConnection) GetUniqueConstraints

func (f *FirebirdConnection) GetUniqueConstraints(tableName string) ([]string, error)

func (*FirebirdConnection) GetViews

func (f *FirebirdConnection) GetViews() ([]string, error)

func (*FirebirdConnection) Open

func (f *FirebirdConnection) Open() error

func (*FirebirdConnection) Ping

func (f *FirebirdConnection) Ping() error

func (*FirebirdConnection) Query

func (f *FirebirdConnection) Query(queryName string, args ...any) (any, error)

func (*FirebirdConnection) SetSchema

func (f *FirebirdConnection) SetSchema(schema string)

type ForeignKey

type ForeignKey struct {
	Column           string
	ReferencedTable  string
	ReferencedColumn string
}

type MySQLConnection

type MySQLConnection struct {
	*BaseConnection
	// contains filtered or unexported fields
}

func NewMySQLConnection

func NewMySQLConnection(name, connStr string) (*MySQLConnection, error)

func (*MySQLConnection) BuildDeleteStatement

func (m *MySQLConnection) BuildDeleteStatement(
	tableName, primaryKeyCol, pkValue string,
) string

func (*MySQLConnection) BuildUpdateStatement

func (m *MySQLConnection) BuildUpdateStatement(
	tableName, columnName, currentValue, pkColumn, pkValue string,
) string

func (*MySQLConnection) Close

func (m *MySQLConnection) Close() error

func (*MySQLConnection) Exec

func (m *MySQLConnection) Exec(sql string, args ...any) error

func (*MySQLConnection) ExecQuery

func (m *MySQLConnection) ExecQuery(
	sql string,
	args ...any,
) (*sql.Rows, error)

func (*MySQLConnection) GetForeignKeys

func (m *MySQLConnection) GetForeignKeys(tableName string) ([]ForeignKey, error)

func (*MySQLConnection) GetForeignKeysReferencingTable

func (m *MySQLConnection) GetForeignKeysReferencingTable(tableName string) ([]ForeignKey, error)

func (*MySQLConnection) GetInfoSQL

func (m *MySQLConnection) GetInfoSQL(infoType string) string

func (*MySQLConnection) GetPlaceholder

func (m *MySQLConnection) GetPlaceholder(paramIndex int) string

func (*MySQLConnection) GetTableMetadata

func (m *MySQLConnection) GetTableMetadata(
	tableName string,
) (*TableMetadata, error)

func (*MySQLConnection) GetTables

func (m *MySQLConnection) GetTables() ([]string, error)

func (*MySQLConnection) GetUniqueConstraints

func (m *MySQLConnection) GetUniqueConstraints(tableName string) ([]string, error)

func (*MySQLConnection) GetViews

func (m *MySQLConnection) GetViews() ([]string, error)

func (*MySQLConnection) Open

func (m *MySQLConnection) Open() error

func (*MySQLConnection) Ping

func (m *MySQLConnection) Ping() error

func (*MySQLConnection) Query

func (m *MySQLConnection) Query(queryName string, args ...any) (any, error)

type OracleConnection

type OracleConnection struct {
	*BaseConnection
	// contains filtered or unexported fields
}

func NewOracleConnection

func NewOracleConnection(name, connStr string) (*OracleConnection, error)

func (*OracleConnection) ApplyRowLimit

func (oc *OracleConnection) ApplyRowLimit(sql string, limit int) string

func (*OracleConnection) BuildDeleteStatement

func (oc *OracleConnection) BuildDeleteStatement(tableName, primaryKeyCol, pkValue string) string

func (*OracleConnection) BuildUpdateStatement

func (oc *OracleConnection) BuildUpdateStatement(tableName, columnName, currentValue, pkColumn, pkValue string) string

func (*OracleConnection) Close

func (oc *OracleConnection) Close() error

func (*OracleConnection) Exec

func (oc *OracleConnection) Exec(sql string, args ...any) error

func (*OracleConnection) ExecQuery

func (oc *OracleConnection) ExecQuery(sql string, args ...any) (*sql.Rows, error)

func (*OracleConnection) GetForeignKeys

func (oc *OracleConnection) GetForeignKeys(tableName string) ([]ForeignKey, error)

func (*OracleConnection) GetForeignKeysReferencingTable

func (oc *OracleConnection) GetForeignKeysReferencingTable(tableName string) ([]ForeignKey, error)

func (*OracleConnection) GetInfoSQL

func (oc *OracleConnection) GetInfoSQL(infoType string) string

func (*OracleConnection) GetPlaceholder

func (oc *OracleConnection) GetPlaceholder(paramIndex int) string

func (*OracleConnection) GetTableMetadata

func (oc *OracleConnection) GetTableMetadata(tableName string) (*TableMetadata, error)

func (*OracleConnection) GetTables

func (oc *OracleConnection) GetTables() ([]string, error)

func (*OracleConnection) GetUniqueConstraints

func (oc *OracleConnection) GetUniqueConstraints(tableName string) ([]string, error)

func (*OracleConnection) GetViews

func (oc *OracleConnection) GetViews() ([]string, error)

func (*OracleConnection) Open

func (oc *OracleConnection) Open() error

func (*OracleConnection) Ping

func (oc *OracleConnection) Ping() error

func (*OracleConnection) Query

func (oc *OracleConnection) Query(queryName string, args ...any) (any, error)

type PostgresConnection

type PostgresConnection struct {
	*BaseConnection
	// contains filtered or unexported fields
}

func NewPostgresConnection

func NewPostgresConnection(name, connStr string) (*PostgresConnection, error)

func (*PostgresConnection) BuildDeleteStatement

func (c *PostgresConnection) BuildDeleteStatement(
	tableName, primaryKeyCol, pkValue string,
) string

func (*PostgresConnection) BuildUpdateStatement

func (p *PostgresConnection) BuildUpdateStatement(
	tableName, columnName, currentValue, pkColumn, pkValue string,
) string

func (*PostgresConnection) Close

func (p *PostgresConnection) Close() error

func (*PostgresConnection) Exec

func (p *PostgresConnection) Exec(sql string, args ...any) error

func (*PostgresConnection) ExecQuery

func (p *PostgresConnection) ExecQuery(
	sql string,
	args ...any,
) (*sql.Rows, error)

func (*PostgresConnection) GetForeignKeys

func (p *PostgresConnection) GetForeignKeys(tableName string) ([]ForeignKey, error)

func (*PostgresConnection) GetForeignKeysReferencingTable

func (p *PostgresConnection) GetForeignKeysReferencingTable(tableName string) ([]ForeignKey, error)

func (*PostgresConnection) GetInfoSQL

func (p *PostgresConnection) GetInfoSQL(infoType string) string

func (*PostgresConnection) GetPlaceholder

func (p *PostgresConnection) GetPlaceholder(paramIndex int) string

func (*PostgresConnection) GetTableMetadata

func (p *PostgresConnection) GetTableMetadata(
	tableName string,
) (*TableMetadata, error)

func (*PostgresConnection) GetTables

func (p *PostgresConnection) GetTables() ([]string, error)

func (*PostgresConnection) GetUniqueConstraints

func (p *PostgresConnection) GetUniqueConstraints(tableName string) ([]string, error)

func (*PostgresConnection) GetViews

func (p *PostgresConnection) GetViews() ([]string, error)

func (*PostgresConnection) Open

func (p *PostgresConnection) Open() error

func (*PostgresConnection) Ping

func (oc *PostgresConnection) Ping() error

func (*PostgresConnection) Query

func (p *PostgresConnection) Query(queryName string, args ...any) (any, error)

type Query

type Query struct {
	Name        string            `yaml:"name"`
	Id          int               `yaml:"id"`
	SQL         string            `yaml:"sql"`
	TableName   string            `yaml:"table_name,omitempty"`
	PrimaryKeys []string          `yaml:"primary_keys,omitempty"`
	Metadata    map[string]string `yaml:"metadata,omitempty"`
}

func FindQueryWithSelector

func FindQueryWithSelector(queries map[string]Query, selector string) (Query, bool)

type SQLServerConnection

type SQLServerConnection struct {
	*BaseConnection
	// contains filtered or unexported fields
}

func NewSQLServerConnection

func NewSQLServerConnection(name, connStr string) (*SQLServerConnection, error)

func (*SQLServerConnection) ApplyRowLimit

func (s *SQLServerConnection) ApplyRowLimit(sql string, limit int) string

func (*SQLServerConnection) BuildDeleteStatement

func (s *SQLServerConnection) BuildDeleteStatement(tableName, primaryKeyCol, pkValue string) string

func (*SQLServerConnection) BuildUpdateStatement

func (s *SQLServerConnection) BuildUpdateStatement(tableName, columnName, currentValue, pkColumn, pkValue string) string

func (*SQLServerConnection) Close

func (s *SQLServerConnection) Close() error

func (*SQLServerConnection) Exec

func (s *SQLServerConnection) Exec(sql string, args ...any) error

func (*SQLServerConnection) ExecQuery

func (s *SQLServerConnection) ExecQuery(sql string, args ...any) (*sql.Rows, error)

func (*SQLServerConnection) GetForeignKeys

func (s *SQLServerConnection) GetForeignKeys(tableName string) ([]ForeignKey, error)

func (*SQLServerConnection) GetForeignKeysReferencingTable

func (s *SQLServerConnection) GetForeignKeysReferencingTable(tableName string) ([]ForeignKey, error)

func (*SQLServerConnection) GetInfoSQL

func (s *SQLServerConnection) GetInfoSQL(infoType string) string

func (*SQLServerConnection) GetPlaceholder

func (s *SQLServerConnection) GetPlaceholder(paramIndex int) string

func (*SQLServerConnection) GetTableMetadata

func (s *SQLServerConnection) GetTableMetadata(tableName string) (*TableMetadata, error)

func (*SQLServerConnection) GetTables

func (s *SQLServerConnection) GetTables() ([]string, error)

func (*SQLServerConnection) GetUniqueConstraints

func (s *SQLServerConnection) GetUniqueConstraints(tableName string) ([]string, error)

func (*SQLServerConnection) GetViews

func (s *SQLServerConnection) GetViews() ([]string, error)

func (*SQLServerConnection) Open

func (s *SQLServerConnection) Open() error

func (*SQLServerConnection) Ping

func (s *SQLServerConnection) Ping() error

func (*SQLServerConnection) Query

func (s *SQLServerConnection) Query(queryName string, args ...any) (any, error)

type SQLiteConnection

type SQLiteConnection struct {
	*BaseConnection
	// contains filtered or unexported fields
}

func NewSQLiteConnection

func NewSQLiteConnection(name, connStr string) (*SQLiteConnection, error)

func (*SQLiteConnection) BuildDeleteStatement

func (s *SQLiteConnection) BuildDeleteStatement(
	tableName, primaryKeyCol, pkValue string,
) string

func (*SQLiteConnection) BuildUpdateStatement

func (s *SQLiteConnection) BuildUpdateStatement(
	tableName, columnName, currentValue, pkColumn, pkValue string,
) string

func (*SQLiteConnection) Close

func (s *SQLiteConnection) Close() error

func (*SQLiteConnection) Exec

func (s *SQLiteConnection) Exec(sql string, args ...any) error

func (*SQLiteConnection) ExecQuery

func (s *SQLiteConnection) ExecQuery(
	sql string,
	args ...any,
) (*sql.Rows, error)

func (*SQLiteConnection) GetForeignKeys

func (s *SQLiteConnection) GetForeignKeys(tableName string) ([]ForeignKey, error)

func (*SQLiteConnection) GetForeignKeysReferencingTable

func (s *SQLiteConnection) GetForeignKeysReferencingTable(tableName string) ([]ForeignKey, error)

func (*SQLiteConnection) GetInfoSQL

func (s *SQLiteConnection) GetInfoSQL(infoType string) string

func (*SQLiteConnection) GetPlaceholder

func (s *SQLiteConnection) GetPlaceholder(paramIndex int) string

func (*SQLiteConnection) GetTableMetadata

func (s *SQLiteConnection) GetTableMetadata(
	tableName string,
) (*TableMetadata, error)

func (*SQLiteConnection) GetTables

func (s *SQLiteConnection) GetTables() ([]string, error)

func (*SQLiteConnection) GetUniqueConstraints

func (s *SQLiteConnection) GetUniqueConstraints(tableName string) ([]string, error)

func (*SQLiteConnection) GetViews

func (s *SQLiteConnection) GetViews() ([]string, error)

func (*SQLiteConnection) Open

func (s *SQLiteConnection) Open() error

func (*SQLiteConnection) Ping

func (s *SQLiteConnection) Ping() error

func (*SQLiteConnection) Query

func (s *SQLiteConnection) Query(queryName string, args ...any) (any, error)

type TableMetadata

type TableMetadata struct {
	TableName         string
	PrimaryKeys       []string
	ColumnTypes       []string
	Columns           []string
	ForeignKeys       []ForeignKey
	UniqueConstraints []string
}

func InferTableMetadata

func InferTableMetadata(conn DatabaseConnection, query Query) (*TableMetadata, error)

InferTableMetadata attempts to infer table metadata from a query

Jump to

Keyboard shortcuts

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