database

package
v0.4.2 Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	StartTag = "<gemini>"
	EndTag   = "</gemini>"
)

Variables

This section is empty.

Functions

func GenerateMetadataCommentString

func GenerateMetadataCommentString(data *CommentData, enrichments map[string]bool, formattedExamples string) string

generateMetadataCommentString constructs the metadata portion of the column comment. It takes the pre-formatted example string as input.

func GenerateTableMetadataCommentString

func GenerateTableMetadataCommentString(data *TableCommentData, enrichments map[string]bool) string

generateTableMetadataCommentString constructs the metadata portion of the table comment.

func MergeComments

func MergeComments(existingComment string, newMetadataComment string, updateExistingMode string) string

mergeComments combines an existing comment with new metadata, handling tags.

func RegisterDialectHandler

func RegisterDialectHandler(dialect string, handler DialectHandler)

Types

type ColumnInfo

type ColumnInfo struct {
	Name     string
	DataType string
}

ColumnInfo holds basic information about a database column.

type CommentData

type CommentData struct {
	TableName      string
	ColumnName     string
	ColumnDataType string
	ExampleValues  []string
	DistinctCount  int64
	NullCount      int64
	Description    string
	ForeignKeys    []ForeignKeyReference
}

CommentData holds information needed to generate a column comment.

type DB

type DB struct {
	Pool    *sql.DB
	Handler DialectHandler
	Config  config.DatabaseConfig
}

DB holds the database connection pool and dialect handler.

func New

func New(cfg config.DatabaseConfig) (*DB, error)

func (*DB) Close

func (db *DB) Close() error

func (*DB) ExecuteSQLStatements

func (db *DB) ExecuteSQLStatements(ctx context.Context, sqlStatements []string) error

func (*DB) GenerateCommentSQL

func (db *DB) GenerateCommentSQL(data *CommentData, enrichments map[string]bool) (string, error)

func (*DB) GenerateDeleteCommentSQL

func (db *DB) GenerateDeleteCommentSQL(ctx context.Context, tableName string, columnName string) (string, error)

func (*DB) GenerateDeleteTableCommentSQL

func (db *DB) GenerateDeleteTableCommentSQL(ctx context.Context, tableName string) (string, error)

func (*DB) GenerateTableCommentSQL

func (db *DB) GenerateTableCommentSQL(data *TableCommentData, enrichments map[string]bool) (string, error)

func (*DB) GetColumnComment

func (db *DB) GetColumnComment(ctx context.Context, tableName string, columnName string) (string, error)

func (*DB) GetColumnMetadata

func (db *DB) GetColumnMetadata(tableName string, columnName string) (map[string]interface{}, error)

func (*DB) GetConfig

func (db *DB) GetConfig() config.DatabaseConfig

func (*DB) GetForeignKeys

func (db *DB) GetForeignKeys(tableName, columnName string) ([]ForeignKeyReference, error)

GetForeignKeys retrieves foreign key references for a specific column.

func (*DB) GetTableComment

func (db *DB) GetTableComment(ctx context.Context, tableName string) (string, error)

func (*DB) ListColumns

func (db *DB) ListColumns(tableName string) ([]ColumnInfo, error)

func (*DB) ListTables

func (db *DB) ListTables() ([]string, error)

func (*DB) Ping

func (db *DB) Ping(ctx context.Context) error

type DBAdapter

type DBAdapter interface {
	ListTables() ([]string, error)
	ListColumns(tableName string) ([]ColumnInfo, error)
	GetColumnMetadata(tableName string, columnName string) (map[string]interface{}, error)
	GetColumnComment(ctx context.Context, tableName string, columnName string) (string, error)
	GetTableComment(ctx context.Context, tableName string) (string, error)
	GenerateCommentSQL(data *CommentData, enrichments map[string]bool) (string, error)
	GenerateTableCommentSQL(data *TableCommentData, enrichments map[string]bool) (string, error)
	GenerateDeleteCommentSQL(ctx context.Context, tableName string, columnName string) (string, error)
	GenerateDeleteTableCommentSQL(ctx context.Context, tableName string) (string, error)
	ExecuteSQLStatements(ctx context.Context, sqlStatements []string) error
	Ping(ctx context.Context) error
	Close() error
	GetConfig() config.DatabaseConfig
	GetForeignKeys(tableName, columnName string) ([]ForeignKeyReference, error)
}

DBAdapter defines the interface for database operations needed by the enricher.

type DialectHandler

type DialectHandler interface {
	CreateCloudSQLPool(cfg config.DatabaseConfig) (*sql.DB, error)
	CreateStandardPool(cfg config.DatabaseConfig) (*sql.DB, error)
	QuoteIdentifier(name string) string
	ListTables(db *DB) ([]string, error)
	ListColumns(db *DB, tableName string) ([]ColumnInfo, error)
	GetForeignKeys(db *DB, tableName string, columnName string) ([]ForeignKeyReference, error)
	GetColumnMetadata(db *DB, tableName string, columnName string) (map[string]interface{}, error)
	GetColumnComment(ctx context.Context, db *DB, tableName string, columnName string) (string, error)
	GetTableComment(ctx context.Context, db *DB, tableName string) (string, error)
	GenerateCommentSQL(db *DB, data *CommentData, enrichments map[string]bool) (string, error)
	GenerateTableCommentSQL(db *DB, data *TableCommentData, enrichments map[string]bool) (string, error)
	GenerateDeleteCommentSQL(ctx context.Context, db *DB, tableName string, columnName string) (string, error)
	GenerateDeleteTableCommentSQL(ctx context.Context, db *DB, tableName string) (string, error)
}

DialectHandler interface remains the same

func GetDialectHandler

func GetDialectHandler(dialect string) (DialectHandler, error)

type ForeignKeyReference

type ForeignKeyReference struct {
	ReferencedTable  string
	ReferencedColumn string
	ConstraintName   string
}

ForeignKeyReference holds information about a foreign key relationship.

type TableCommentData

type TableCommentData struct {
	TableName   string
	Description string
}

TableCommentData holds information needed to generate a table comment.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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