schema

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2026 License: MIT Imports: 8 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package schema reads table and column metadata from a SQLite-compatible database.

Index

Constants

This section is empty.

Variables

View Source
var ErrTableNotFound = errors.New("table not found")

Functions

This section is empty.

Types

type Affinity

type Affinity int
const (
	AffinityBlob Affinity = iota
	AffinityText
	AffinityNumeric
	AffinityInteger
	AffinityReal
)

type Column

type Column struct {
	Name         string
	Type         string
	NotNull      bool
	DefaultValue sql.NullString
	PKIndex      int
}

func (Column) Affinity

func (c Column) Affinity() Affinity

Affinity applies SQLite's rules to the declared type, in SQLite's order: https://www.sqlite.org/datatype3.html#determination_of_column_affinity

func (Column) IsPrimaryKey

func (c Column) IsPrimaryKey() bool

func (Column) Nullable

func (c Column) Nullable() bool

Nullable treats primary key columns as non-null. pragma_table_info reports notnull=0 for an INTEGER PRIMARY KEY even though it can never hold NULL.

type Introspector

type Introspector interface {
	Tables(ctx context.Context) ([]Table, error)
	Table(ctx context.Context, name string) (*Table, error)
}

type Querier

type Querier interface {
	QueryContext(ctx context.Context, query string, args ...any) (*sql.Rows, error)
}

type SQLIntrospector

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

func NewSQLIntrospector

func NewSQLIntrospector(db Querier) *SQLIntrospector

func (*SQLIntrospector) Table

func (s *SQLIntrospector) Table(ctx context.Context, name string) (*Table, error)

func (*SQLIntrospector) Tables

func (s *SQLIntrospector) Tables(ctx context.Context) ([]Table, error)

type Table

type Table struct {
	Name    string
	Type    string
	Columns []Column
}

func (*Table) Column

func (t *Table) Column(name string) (Column, bool)

func (*Table) ColumnNames

func (t *Table) ColumnNames() []string

func (*Table) HasColumn

func (t *Table) HasColumn(name string) bool

func (*Table) IsView

func (t *Table) IsView() bool

func (*Table) PrimaryKey

func (t *Table) PrimaryKey() []Column

func (*Table) RowKey

func (t *Table) RowKey() (Column, bool)

RowKey returns the primary key column when the key is a single column. Views report no primary key, so they have no row key either.

Jump to

Keyboard shortcuts

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