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.
type ArgumentCondition ¶
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 ¶
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.
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 ¶
func (*ColumnCondition) String ¶
func (x *ColumnCondition) String() string
String returns the string representation of the Condition for use in SQL queries.
type CompositeCondition ¶
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 ¶
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 ¶
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 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.
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 ¶
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) GetNonPrimaryKeyColumns ¶
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 ¶
GetNonUniqueIndexes retrieves all non-unique indexes from the table.
func (*Table) GetUniqueKeys ¶
GetUniqueKeys retrieves all unique keys (primary key and unique indexes) from the table.