infer

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package infer finds relationships between tables that the schema does not declare, and checks them against sampled values.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Verify

func Verify(ctx context.Context, q Querier, ids *IDValues, schema *model.Schema, rels []model.Relationship, timeout time.Duration) ([]model.Relationship, []string)

Verify looks the sampled child values up in the parent table and grades every unverified relationship: confirmed when at least 90% exist, likely from 50%, weak below. Weak naming guesses are dropped.

Types

type IDValues

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

IDValues keeps a few distinct sampled values of the columns that may point at other tables.

func NewIDValues

func NewIDValues() *IDValues

NewIDValues returns an empty store.

func (*IDValues) Collect

func (v *IDValues) Collect(t *model.Table, s *sample.Sample)

Collect keeps candidate key values from one table's sample: integer and short text columns other than a single-column primary key, and polymorphic (x_type, x_id) pairs.

func (*IDValues) Get

func (v *IDValues) Get(table, column string) []string

Get returns the kept values of a column.

type Inferrer

type Inferrer struct {
	Schema   *model.Schema
	IDs      *IDValues
	Prefixes []string             // table prefixes such as "wp_"
	Known    []model.Relationship // from presets
}

Inferrer proposes relationships for one schema.

func (*Inferrer) Relationships

func (in *Inferrer) Relationships() []model.Relationship

Relationships returns the declared foreign keys, the preset relationships and those guessed from naming. Only declared ones are marked as such; the rest still need Verify.

type Querier

type Querier interface {
	QueryRowContext(ctx context.Context, query string, args ...any) *sql.Row
}

Querier is the part of *sql.DB Verify needs.

Jump to

Keyboard shortcuts

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