Documentation
¶
Index ¶
- Variables
- func GetRelName(colName string) string
- func ParseClusteringKey(expr string) []string
- type ColPair
- type CompositeFKInfo
- type CrossDBRel
- type DBColumn
- type DBFuncParam
- type DBFunction
- type DBInfo
- func GetDBInfo(ctx context.Context, db *sql.DB, dbType string, blockList []string) (*DBInfo, error)
- func GetTestDBInfo() *DBInfo
- func GetTestDBInfoWithDatabase() *DBInfo
- func GetTestPartitionedDBInfo() *DBInfo
- func GetTestPartitionedWarnOnlyDBInfo() *DBInfo
- func GetTestSnowflakeDBInfo() *DBInfo
- func NewDBInfo(dbType string, dbVersion int, dbSchema string, dbName string, cols []DBColumn, ...) *DBInfo
- type DBRel
- type DBRelLeft
- type DBRelRight
- type DBSchema
- func (s *DBSchema) DBName() string
- func (s *DBSchema) DBSchema() string
- func (s *DBSchema) DBType() string
- func (s *DBSchema) DBVersion() int
- func (s *DBSchema) Find(schema, name string) (DBTable, error)
- func (s *DBSchema) FindCrossDBPath(childName, parentName string) (TPath, bool)
- func (s *DBSchema) FindPath(from, to, through string) ([]TPath, error)
- func (s *DBSchema) FindPathByColumn(from, to, col string) ([]TPath, error)
- func (s *DBSchema) GetAliases() map[string]DBTable
- func (s *DBSchema) GetCrossDBRels() []CrossDBRel
- func (s *DBSchema) GetFirstDegree(t DBTable) (items []RelNode, err error)
- func (s *DBSchema) GetFunctions() map[string]DBFunction
- func (s *DBSchema) GetSecondDegree(t DBTable) (items []RelNode, err error)
- func (s *DBSchema) GetTables() []DBTable
- func (s *DBSchema) IsAlias(name string) bool
- func (s *DBSchema) PrintEdgeInfo(e edgeInfo)
- func (s *DBSchema) PrintLines(lines []util.Edge)
- type DBTable
- func (ti *DBTable) ColumnExists(name string) (DBColumn, bool)
- func (ti *DBTable) GetColumn(name string) (DBColumn, error)
- func (t *DBTable) GetColumnIndex(name string) (int, bool)
- func (t *DBTable) HasCompositePK() bool
- func (t *DBTable) IsPKCol(name string) bool
- func (t *DBTable) PKColNames() []string
- func (ti *DBTable) String() string
- type RelNode
- type RelType
- type TEdge
- type TPath
- type VirtualTable
Constants ¶
This section is empty.
Variables ¶
Functions ¶
func ParseClusteringKey ¶ added in v3.15.0
ParseClusteringKey parses Snowflake's clustering key expression into a list of normalized column names. Snowflake returns expressions like:
LINEAR(CREATED_AT, USER_ID) LINEAR(CREATED_AT) (CREATED_AT, USER_ID)
Returns nil for empty or unparseable expressions.
Types ¶
type ColPair ¶ added in v3.15.1
ColPair represents a column pair in a composite foreign key relationship.
type CompositeFKInfo ¶ added in v3.15.1
type CompositeFKInfo struct {
Schema string
Table string
ConstraintName string
LocalCols []string
FKeySchema string
FKeyTable string
FKeyCols []string
}
CompositeFKInfo holds metadata about a composite (multi-column) foreign key constraint.
func DiscoverCompositeFKs ¶ added in v3.15.1
func DiscoverCompositeFKs(ctx context.Context, db *sql.DB, dbtype string) ([]CompositeFKInfo, error)
DiscoverCompositeFKs returns metadata about composite (multi-column) foreign key constraints for the given database type.
Composite FK discovery is a best-effort enrichment: if the query errors or times out, we return (nil, nil) and let the rest of the schema load normally. Single-column FKs (the overwhelmingly common case) come from DiscoverColumns and are unaffected. This prevents a slow/broken data-dictionary query from failing the whole NewGraphJin init.
type CrossDBRel ¶ added in v3.15.0
type CrossDBRel struct {
SourceTable DBTable // local table containing the FK column
SourceCol DBColumn // local FK column
TargetDB string // remote database name
TargetSchema string // remote schema
TargetTable string // remote table name
TargetCol string // remote column name
IsOneToOne bool // true if target col is PK/unique
}
CrossDBRel represents a cross-database foreign key relationship. These are stored separately from the graph because they connect tables across different databases — the target table doesn't exist in this schema's graph. Resolution happens at runtime via database_join.go.
type DBColumn ¶
type DBColumn struct {
Comment string
ID int32
Name string
OrigName string // Original name before normalization (e.g., PascalCase for MSSQL)
Type string
Array bool
NotNull bool
PrimaryKey bool
UniqueKey bool
FullText bool
FKRecursive bool
FKeyDatabase string // Target database for cross-database FKs (empty = same db)
FKeySchema string
FKeyTable string
FKeyCol string
FKeyIsUnique bool // True if FK target column is PK/unique (for correct rel type)
Blocked bool
Table string
Schema string
Database string
Default string
Index bool
IndexName string
FKOnDelete string
FKOnUpdate string
// Original names before normalization (used to build dialect name maps for MSSQL)
OrigTable string
OrigSchema string
OrigFKeyTable string
OrigFKeySchema string
OrigFKeyCol string
}
DBColumn returns the column as a string
type DBFuncParam ¶
DBFuncParam holds the database function parameter information
type DBFunction ¶
type DBFunction struct {
Comment string
Schema string
Name string
Type string
Agg bool
Inputs []DBFuncParam
Outputs []DBFuncParam
}
DBFunction holds the database function information
func DiscoverFunctions ¶
func DiscoverFunctions(ctx context.Context, db *sql.DB, dbtype string, blockList []string) ([]DBFunction, error)
DiscoverFunctions returns the functions of a database
func (*DBFunction) GetInput ¶
func (fn *DBFunction) GetInput(name string) (ret DBFuncParam, err error)
GetInput returns the input of a function
func (DBFunction) String ¶
func (fn DBFunction) String() string
String returns a string representation of the DBFunction
type DBInfo ¶
type DBInfo struct {
Type string
Version int
Schema string
Name string
Tables []DBTable
Functions []DBFunction
VTables []VirtualTable `json:"-"`
CompositeFKs []CompositeFKInfo `json:"-"`
// contains filtered or unexported fields
}
DBInfo holds the database schema information
func GetDBInfo ¶
func GetDBInfo( ctx context.Context, db *sql.DB, dbType string, blockList []string, ) (*DBInfo, error)
GetDBInfo returns the database schema information.
The context bounds the full discovery run (all queries + retries). Callers that don't have a context can use context.Background(); an internal per-query timeout (introspectionQueryTimeout) still applies on top so a hung driver read can't block forever.
func GetTestDBInfo ¶
func GetTestDBInfo() *DBInfo
func GetTestDBInfoWithDatabase ¶ added in v3.2.0
func GetTestDBInfoWithDatabase() *DBInfo
GetTestDBInfoWithDatabase returns a DBInfo with tables that have Database field set for testing multi-database support with @database directive
func GetTestPartitionedDBInfo ¶ added in v3.15.0
func GetTestPartitionedDBInfo() *DBInfo
GetTestPartitionedDBInfo returns a DBInfo with partition keys set on the products table for testing partition filter injection.
func GetTestPartitionedWarnOnlyDBInfo ¶ added in v3.15.0
func GetTestPartitionedWarnOnlyDBInfo() *DBInfo
GetTestPartitionedWarnOnlyDBInfo returns a DBInfo with partition key but no default range (warn-only mode).
func GetTestSnowflakeDBInfo ¶ added in v3.15.0
func GetTestSnowflakeDBInfo() *DBInfo
GetTestSnowflakeDBInfo returns a Snowflake DBInfo with clustering keys set on the products table for testing clustering-aware cursor pagination.
func NewDBInfo ¶
func NewDBInfo( dbType string, dbVersion int, dbSchema string, dbName string, cols []DBColumn, funcs []DBFunction, blockList []string, ) *DBInfo
NewDBInfo returns a new DBInfo object
type DBRel ¶
type DBRel struct {
Type RelType
Left DBRelLeft
Right DBRelRight
ExtraPairs []ColPair // Additional column pairs for composite FKs
}
DBRel represents a database relationship
func (*DBRel) IsCrossDatabase ¶ added in v3.2.0
IsCrossDatabase returns true if this relationship crosses database boundaries. This is used to determine if a join needs to be executed as a database join rather than a SQL join.
type DBRelRight ¶
DBRelRight represents a database relationship
type DBSchema ¶
type DBSchema struct {
// contains filtered or unexported fields
}
func GetTestPartitionedSchema ¶ added in v3.15.0
GetTestPartitionedSchema returns a DBSchema with partition config for testing.
func GetTestPartitionedWarnOnlySchema ¶ added in v3.15.0
GetTestPartitionedWarnOnlySchema returns a DBSchema with warn-only partition config.
func GetTestSchema ¶
func GetTestSnowflakeSchema ¶ added in v3.15.0
GetTestSnowflakeSchema returns a DBSchema backed by Snowflake test data with clustering keys.
func NewDBSchema ¶
NewDBSchema creates a new database schema
func (*DBSchema) Find ¶
Find returns a table by schema and name. If an exact schema:name match is not found, it falls back to searching across all discovered schemas. When multiple schemas contain the same table name, the default schema is preferred. If the table exists in multiple non-default schemas, an error listing the available schemas is returned.
func (*DBSchema) FindCrossDBPath ¶ added in v3.15.0
FindCrossDBPath checks cross-database FK metadata for a relationship between two tables identified by their unqualified names (as used in GraphQL queries). Returns a synthetic TPath if found, without requiring the target table to be a node in the graph.
func (*DBSchema) FindPathByColumn ¶ added in v3.18.3
FindPathByColumn returns a path between two tables, disambiguating by the FK column name when the two tables have multiple foreign keys between them.
func (*DBSchema) GetAliases ¶
GetAliases returns a map of table aliases
func (*DBSchema) GetCrossDBRels ¶ added in v3.15.0
func (s *DBSchema) GetCrossDBRels() []CrossDBRel
GetCrossDBRels returns all cross-database relationships in the schema.
func (*DBSchema) GetFirstDegree ¶
GetFirstDegree returns the first degree relationships of a table
func (*DBSchema) GetFunctions ¶
func (s *DBSchema) GetFunctions() map[string]DBFunction
GetFunction returns a function from the schema
func (*DBSchema) GetSecondDegree ¶
GetSecondDegree returns the second degree relationships of a table
func (*DBSchema) PrintEdgeInfo ¶
func (s *DBSchema) PrintEdgeInfo(e edgeInfo)
PrintEdgeInfo prints edge info
func (*DBSchema) PrintLines ¶
PrintLines prints the graph lines
type DBTable ¶
type DBTable struct {
Comment string
Schema string
Name string
OrigName string // Original name before normalization (e.g., PascalCase for MSSQL)
OrigSchema string // Original schema before normalization
Type string
// Database is the name of the database this table belongs to (for multi-database support).
// Empty string means the default database.
Database string
Columns []DBColumn
PrimaryCols []DBColumn
PrimaryCol DBColumn // backward compat: alias for PrimaryCols[0]
SecondaryCol DBColumn
FullText []DBColumn
Blocked bool
Func DBFunction
ClusteringKeys []string // Snowflake clustering key columns (normalized to snake_case)
PartitionKey string // Partition column name (from config, e.g., "created_at")
PartitionRangeDays int // Default range in days for auto-injected partition filter (0 = warn only)
PartitionNone bool
ImplicitPartitionKey string
// contains filtered or unexported fields
}
DBTable holds the database table information
func NewDBTable ¶
NewDBTable returns a new DBTable object
func (*DBTable) ColumnExists ¶
ColumnExists returns true if a column exists in a table
func (*DBTable) GetColumnIndex ¶ added in v3.15.0
GetColumnIndex returns the index of a column in the table by name, and whether it was found.
func (*DBTable) HasCompositePK ¶ added in v3.15.1
HasCompositePK returns true if the table has a multi-column primary key.
func (*DBTable) IsPKCol ¶ added in v3.15.1
IsPKCol returns true if the named column is part of the primary key.
func (*DBTable) PKColNames ¶ added in v3.15.1
PKColNames returns the names of all primary key columns.
type TEdge ¶
type TEdge struct {
From, To, Weight int32
Type RelType
LT, RT DBTable
L, R DBColumn
CName string
ExtraPairs []ColPair // Additional column pairs for composite FKs
// contains filtered or unexported fields
}
TEdge represents a table edge for the graph