sqlc

package
v0.0.0-...-b68f470 Latest Latest
Warning

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

Go to latest
Published: Jan 19, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package sqlc provides data structures for working with sqlc catalog files.

The catalog represents the database schema metadata generated by sqlc, including schemas, tables, columns, indexes, and foreign key relationships.

Package sqlc provides functionality for parsing and working with sqlc configuration files.

This package handles reading sqlc.yaml configuration files and extracting SQL generation settings including schema paths, query paths, and database engines.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Argument

type Argument struct {
	Column *Column
}

Argument represents SQL argument corresponding to a column.

func (*Argument) String

func (x *Argument) String() string

String returns the string representation of the Argument for use in SQL queries.

type ArgumentCondition

type ArgumentCondition struct {
	Column   *Column
	Argument *Argument
}

ArgumentCondition represents a simple equality condition between a column and an argument.

func (*ArgumentCondition) String

func (x *ArgumentCondition) String() string

String returns the string representation of the Condition for use in SQL queries.

type Attributes

type Attributes struct {
	Comment string `json:"comment,omitempty"`
	Charset string `json:"charset,omitempty"`
	Collate string `json:"collate,omitempty"`
}

Attributes represents common attributes that can be applied to schemas, tables, and columns. These are typically dialect-specific metadata.

type Catalog

type Catalog struct {
	Schemas []Schema `json:"schemas,omitempty"`
}

Catalog represents the root structure of a sqlc catalog file. It contains all schemas and their associated database objects.

func LoadCatalog

func LoadCatalog(path string) (*Catalog, error)

LoadCatalog loads a sqlc catalog file from the specified path and returns a Catalog struct. The catalog file is expected to be in JSON format as generated by sqlc.

func (*Catalog) GetTable

func (x *Catalog) GetTable(name string) *Table

GetTable retrieves a table by name from the catalog. It searches through all schemas.

type Column

type Column struct {
	Name string `json:"name"`
	Type string `json:"type,omitempty"`
	Null bool   `json:"null,omitempty"`
	// Inherit common attributes
	Attributes
}

Column represents a table column with its name, data type, and nullability.

type ColumnCondition

type ColumnCondition struct {
	Left  *ColumnRef
	Right *ColumnRef
}

func (*ColumnCondition) String

func (x *ColumnCondition) String() string

String returns the string representation of the Condition for use in SQL queries.

type ColumnRef

type ColumnRef struct {
	Name  string
	Table *Table
}

ColumnRef represents a reference to a specific column within a table.

func (*ColumnRef) String

func (x *ColumnRef) String() string

String returns the string representation of the ColumnRef for use in SQL queries.

type CompositeCondition

type CompositeCondition struct {
	Operator   string
	Conditions []fmt.Stringer
}

CompositeCondition represents a combination of multiple conditions using a logical operator (e.g., AND, OR).

func (*CompositeCondition) AddColumn

func (x *CompositeCondition) AddColumn(column *Column)

AddColumn adds a new condition for the specified column to the CompositeCondition.

func (*CompositeCondition) AddColumnRef

func (x *CompositeCondition) AddColumnRef(left, right *ColumnRef)

AddColumnRef adds a new condition comparing two columns to the CompositeCondition.

func (*CompositeCondition) String

func (x *CompositeCondition) String() string

String returns the string representation of the CompositeCondition for use in SQL queries.

type Config

type Config struct {
	Version string `yaml:"version"`
	SQL     []SQL  `yaml:"sql"`
}

Config represents the root structure of a sqlc.yaml configuration file. This file controls how sqlc generates Go code from SQL schemas and queries.

func LoadConfig

func LoadConfig(path string) (*Config, error)

LoadConfig loads a sqlc.yaml configuration file from the specified path and returns a Config struct. The file is expected to be in YAML format.

type ForeignKey

type ForeignKey struct {
	Name       string   `json:"name"`
	Columns    []string `json:"columns,omitempty"`
	References struct {
		Table   string   `json:"table"`
		Columns []string `json:"columns,omitempty"`
	} `json:"references"`
}

ForeignKey represents a foreign key constraint linking columns in this table to columns in a referenced table.

type Generator

type Generator struct {
	Config  *Config
	Catalog *Catalog
}

Generator generates an SQL queries

func (*Generator) Generate

func (x *Generator) Generate() error

Generate generates the queries based on the configuration.

type Index

type Index struct {
	Name   string      `json:"name,omitempty"`
	Unique bool        `json:"unique,omitempty"`
	Parts  []IndexPart `json:"parts,omitempty"`
}

Index represents a database index on one or more columns or expressions.

func (*Index) HasExpr

func (x *Index) HasExpr() bool

HasExpr checks if the index contains any expression-based parts.

type IndexPart

type IndexPart struct {
	Desc   bool   `json:"desc,omitempty"`
	Column string `json:"column,omitempty"`
	Expr   string `json:"expr,omitempty"`
}

IndexPart represents a single part of an index, which can be either a column or an expression.

type SQL

type SQL struct {
	Schema      string   `yaml:"schema"`
	Engine      string   `yaml:"engine"`
	Queries     string   `yaml:"queries"`
	SkipQueries []string `yaml:"skip_queries,omitempty"`
}

SQL represents a single SQL configuration block within the sqlc.yaml file. Each SQL block defines the schema files, query files, and database engine for a specific code generation target.

func (*SQL) GetSkipQueriesSet

func (s *SQL) GetSkipQueriesSet() map[string]bool

GetSkipQueriesSet returns a set of query names to skip for efficient lookup. The returned map allows O(1) lookup to check if a query should be skipped.

type Schema

type Schema struct {
	Name   string  `json:"name"`
	Tables []Table `json:"tables,omitempty"`
	// Inherit common attributes
	Attributes
}

Schema represents a database schema containing tables and other database objects.

type Table

type Table struct {
	Name        string       `json:"name"`
	Columns     []Column     `json:"columns,omitempty"`
	Indexes     []Index      `json:"indexes,omitempty"`
	PrimaryKey  *Index       `json:"primary_key,omitempty"`
	ForeignKeys []ForeignKey `json:"foreign_keys,omitempty"`
	// Inherit common attributes
	Attributes
}

Table represents a database table with its columns, indexes, and constraints.

func (*Table) GetColumn

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

GetColumn retrieves a column by name from the table.

func (*Table) GetNonPrimaryKeyColumns

func (x *Table) GetNonPrimaryKeyColumns() []Column

GetNonPrimaryKeyColumns retrieves all columns from the table except the primary key columns. This is useful for generating UPDATE statements where primary keys should not be modified.

func (*Table) GetNonUniqueIndexes

func (x *Table) GetNonUniqueIndexes() []*Index

GetNonUniqueIndexes retrieves all non-unique indexes from the table.

func (*Table) GetUniqueKeys

func (x *Table) GetUniqueKeys() []*Index

GetUniqueKeys retrieves all unique keys (primary key and unique indexes) from the table.

Directories

Path Synopsis
Package template provides embedded SQL templates for code generation.
Package template provides embedded SQL templates for code generation.

Jump to

Keyboard shortcuts

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