schema

package
v0.2.2 Latest Latest
Warning

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

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

Documentation

Overview

Package schema provides types for representing SQLite database schemas.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func QuoteIdentifier added in v0.2.0

func QuoteIdentifier(name string) string

QuoteIdentifier renders a SQLite identifier (table, column, index, ...) as a double-quoted identifier. Embedded double quotes are escaped by doubling them, as SQLite requires. Note that Go's %q verb cannot be used here: it produces backslash escapes such as "q\"t", which SQLite misparses.

Types

type Column

type Column struct {
	Name       string
	Type       string
	NotNull    bool
	Default    *string
	PrimaryKey int // 0 = not PK, 1+ = PK position
	Hidden     int // 0 = normal, 2 = virtual/generated, 3 = stored
}

Column represents a table column (from PRAGMA table_info).

type Database

type Database struct {
	Tables   map[string]*Table
	Indexes  map[string]*Index
	Views    map[string]*View
	Triggers map[string]*Trigger
}

Database represents a complete SQLite database schema.

func NewDatabase

func NewDatabase() *Database

NewDatabase creates a new empty database schema.

type Index

type Index struct {
	Name  string
	Table string
	SQL   string
}

Index represents a SQLite index.

type Table

type Table struct {
	Name    string
	Columns []Column
	SQL     string // Original CREATE TABLE statement
	// UniqueColumns lists columns that participate in a UNIQUE table
	// constraint. SQLite does not expose this through PRAGMA table_info.
	UniqueColumns []string
	// ForeignKeyColumns lists columns that are the referencing side of a
	// foreign key (column-level or table-level).
	ForeignKeyColumns []string
}

Table represents a SQLite table.

func (*Table) ColumnNames

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

ColumnNames returns the column names for a table.

func (*Table) GetColumn

func (t *Table) GetColumn(name string) *Column

GetColumn returns a column by name, or nil if not found.

func (*Table) HasColumn

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

HasColumn checks if a table has a column by name.

type Trigger

type Trigger struct {
	Name  string
	Table string
	SQL   string
}

Trigger represents a SQLite trigger.

type View

type View struct {
	Name string
	SQL  string
}

View represents a SQLite view.

Jump to

Keyboard shortcuts

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