block

package
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package block handles the parsing of SQL query blocks.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Block

type Block struct {
	Path        string
	Name        string
	Command     Command
	SQL         string
	Doc         string
	Line        int
	Column      int
	StartOffset int
	EndOffset   int
	Suffix      string
	ParamTypes  []ParamTypeOverride  // Explicit type overrides from @param comments
	ReturnTypes []ReturnTypeOverride // Explicit type overrides from @returns comments
	Cache       *cache.Annotation    // Cache annotation if present
	// OrderBy holds the allow-list of column names from an `-- @orderby col, col2`
	// annotation, in source order. It is only set when the query uses the dynamic
	// ORDER BY feature (a `@orderby` placeholder in the ORDER BY position). Nil for
	// every query that does not use the annotation, keeping output unchanged.
	OrderBy []string
	// Optional holds the names of optional equality-filter params from an
	// `-- @optional p1, p2` annotation, in source order. It is only set when the
	// query uses the optional-filters feature (each param wrapped in a
	// `(@p IS NULL OR <expr> <op> @p)` clause). Nil for every query that does not
	// use the annotation, keeping output unchanged.
	Optional []string
}

Block represents a parsed SQL query block.

func Slice

func Slice(path string, src []byte) ([]Block, error)

Slice extracts query blocks from a SQL file.

type Command

type Command int

Command represents the type of query (one, many, exec, etc.).

const (
	// CommandUnknown indicates an unrecognized command.
	CommandUnknown Command = iota
	// CommandOne indicates a query returning a single row.
	CommandOne
	// CommandMany indicates a query returning multiple rows.
	CommandMany
	// CommandExec indicates a query that executes without returning rows.
	CommandExec
	// CommandExecResult indicates a query that returns execution result (rows affected, etc.).
	CommandExecResult
	// CommandExecRows indicates a query that returns the number of affected rows.
	CommandExecRows
	// CommandExecLastID indicates a query that returns the last insert ID.
	CommandExecLastID
	// CommandCopyFrom indicates a bulk insert that takes a slice of param structs and inserts all rows in one statement.
	CommandCopyFrom
	// CommandBatchExec indicates a batch that runs the statement once per param set, returning only error.
	CommandBatchExec
	// CommandBatchMany indicates a batch that runs a query once per param set, returning a slice of row slices ([][]Row).
	CommandBatchMany
	// CommandBatchOne indicates a batch that runs a query once per param set, returning one row per set ([]Row).
	CommandBatchOne
)

func ParseCommand

func ParseCommand(tag string) (Command, bool)

ParseCommand parses a command tag (e.g., ":one") into a Command.

func (Command) String

func (c Command) String() string

type ParamTypeOverride added in v0.5.0

type ParamTypeOverride struct {
	ParamName string
	GoType    string
}

ParamTypeOverride represents an explicit type override for a parameter.

type ReturnTypeOverride added in v0.11.0

type ReturnTypeOverride struct {
	ColumnName string
	GoType     string
}

ReturnTypeOverride represents an explicit type override for a result column.

Jump to

Keyboard shortcuts

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