writer

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const MaxLineLength = 320

MaxLineLength is the ruff line-length limit (ruff's maximum allowed value). Statements the generator would render longer than this are exploded with magic trailing commas so that ruff format leaves them untouched.

Variables

This section is empty.

Functions

func PyQuote

func PyQuote(value string) string

PyQuote returns a complete Python string literal. Go's Quote escaping is a compatible subset of Python's; outer quotes flip to single when that avoids escaping inner double quotes (ruff Q003).

Types

type CodeWriter

type CodeWriter struct {
	QueryResults *QueryResultsWriter
	// contains filtered or unexported fields
}

func NewCodeWriter

func NewCodeWriter(
	config *config.Config,
) *CodeWriter

func (*CodeWriter) Bytes

func (w *CodeWriter) Bytes() []byte

func (*CodeWriter) DocstringsEnabled

func (w *CodeWriter) DocstringsEnabled() bool

DocstringsEnabled reports whether docstring generation is active. Emitters use this to add the blank line ruff format requires between a docstring and a following nested function definition.

func (*CodeWriter) FitsLine

func (w *CodeWriter) FitsLine(indent int, txt string) bool

FitsLine reports whether txt fits within MaxLineLength at the indent level.

func (*CodeWriter) NNewLine

func (w *CodeWriter) NNewLine(n int)

NNewLine writes n newlines.

func (*CodeWriter) NewLine

func (w *CodeWriter) NewLine()

NewLine writes a single newline.

func (*CodeWriter) String

func (w *CodeWriter) String() string

func (*CodeWriter) WriteAll

func (w *CodeWriter) WriteAll(items []string)

func (*CodeWriter) WriteEnumClassDocstring

func (w *CodeWriter) WriteEnumClassDocstring(name string)

WriteEnumClassDocstring writes a one-line enum class docstring.

func (*CodeWriter) WriteEnumsFileModuleDocstring

func (w *CodeWriter) WriteEnumsFileModuleDocstring()

WriteEnumsFileModuleDocstring writes the enums.py module docstring.

func (*CodeWriter) WriteFutureImport

func (w *CodeWriter) WriteFutureImport()

WriteFutureImport writes the future-annotations import that follows the header (and module docstring, if any).

func (*CodeWriter) WriteIndentedLine

func (w *CodeWriter) WriteIndentedLine(level int, txt string)

WriteIndentedLine writes indented text followed by a newline.

func (*CodeWriter) WriteIndentedString

func (w *CodeWriter) WriteIndentedString(level int, txt string)

WriteIndentedString writes indented text without a trailing newline.

func (*CodeWriter) WriteInitFileModuleDocstring

func (w *CodeWriter) WriteInitFileModuleDocstring()

WriteInitFileModuleDocstring writes the __init__.py module docstring.

func (*CodeWriter) WriteLine

func (w *CodeWriter) WriteLine(txt string)

WriteLine writes text followed by a newline.

func (*CodeWriter) WriteModelClassDocstring

func (w *CodeWriter) WriteModelClassDocstring(table *model.Table)

WriteModelClassDocstring writes a model/row/params class docstring with an attribute list, followed by a blank line.

func (*CodeWriter) WriteModelFileModuleDocstring

func (w *CodeWriter) WriteModelFileModuleDocstring()

WriteModelFileModuleDocstring writes the models.py module docstring.

func (*CodeWriter) WriteQueryClassConnDocstring

func (w *CodeWriter) WriteQueryClassConnDocstring(connType string)

WriteQueryClassConnDocstring writes the Querier conn property docstring.

func (*CodeWriter) WriteQueryClassDocstring

func (w *CodeWriter) WriteQueryClassDocstring(sourceName, connType string)

WriteQueryClassDocstring writes the Querier class docstring.

func (*CodeWriter) WriteQueryClassInitDocstring

func (w *CodeWriter) WriteQueryClassInitDocstring(lvl int, connType string)

WriteQueryClassInitDocstring writes the Querier __init__ docstring.

func (*CodeWriter) WriteQueryFileModuleDocstring

func (w *CodeWriter) WriteQueryFileModuleDocstring(sourceName string)

WriteQueryFileModuleDocstring writes a query module docstring.

func (*CodeWriter) WriteQueryFunctionDocstring

func (w *CodeWriter) WriteQueryFunctionDocstring(lvl int, query *model.Query, connType string, args []DocArg, retType string)

WriteQueryFunctionDocstring writes the docstring for a generated query function. retType is the return type used in the Returns section; its exact value is driver-specific for some commands (e.g. :execresult).

func (*CodeWriter) WriteQueryResultsClassDocstring

func (w *CodeWriter) WriteQueryResultsClassDocstring(connType, resultType string, namedParams bool)

WriteQueryResultsClassDocstring writes the QueryResults class docstring. namedParams switches the argument documentation from *args to params.

func (*CodeWriter) WriteQueryResultsFetchDocstring

func (w *CodeWriter) WriteQueryResultsFetchDocstring(async bool)

WriteQueryResultsFetchDocstring writes the __await__/__call__ docstring.

func (*CodeWriter) WriteQueryResultsInitDocstring

func (w *CodeWriter) WriteQueryResultsInitDocstring(connType, resultType string, namedParams bool)

WriteQueryResultsInitDocstring writes the QueryResults __init__ docstring. namedParams switches the argument documentation from *args to params.

func (*CodeWriter) WriteQueryResultsIterDocstring

func (w *CodeWriter) WriteQueryResultsIterDocstring(async bool)

WriteQueryResultsIterDocstring writes the __iter__/__aiter__ docstring.

func (*CodeWriter) WriteQueryResultsNextDocstring

func (w *CodeWriter) WriteQueryResultsNextDocstring(cursorPhrase string, async bool)

WriteQueryResultsNextDocstring writes the __next__/__anext__ docstring. cursorPhrase is e.g. "an asyncpg cursor" or "a sqlite3 cursor".

func (*CodeWriter) WriteSqlcHeader

func (w *CodeWriter) WriteSqlcHeader(query *model.Query)

WriteSqlcHeader writes the "generated by sqlc" comment block.

func (*CodeWriter) WriteString

func (w *CodeWriter) WriteString(txt string)

func (*CodeWriter) WriteWrappedCall

func (w *CodeWriter) WriteWrappedCall(indent int, head string, args []string, tail string)

WriteWrappedCall writes head+args+tail on a single line when it fits, otherwise one argument per line with trailing commas. head must end with the opening parenthesis, tail must start with the closing one.

type DocArg

type DocArg struct {
	Name  string
	Type  string
	Extra string // optional extra description line (used by :copyfrom)
}

DocArg describes one function argument in a docstring.

type QueryResultsWriter

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

func NewQueryResultsWriter

func NewQueryResultsWriter(writer *CodeWriter) *QueryResultsWriter

func (*QueryResultsWriter) WriteQueryResultsAwaitFunction

func (w *QueryResultsWriter) WriteQueryResultsAwaitFunction(wrapperLines []string)

WriteQueryResultsAwaitFunction writes the async __await__ method.

func (*QueryResultsWriter) WriteQueryResultsCallFunction

func (w *QueryResultsWriter) WriteQueryResultsCallFunction(wrapperLines []string)

WriteQueryResultsCallFunction writes the synchronous __call__ method.

func (*QueryResultsWriter) WriteQueryResultsClassHeader

func (w *QueryResultsWriter) WriteQueryResultsClassHeader(
	connType string,
	initFields []string,
	driverReturnType string,
	async bool,
)

func (*QueryResultsWriter) WriteQueryResultsClassHeaderNamedParams added in v0.7.0

func (w *QueryResultsWriter) WriteQueryResultsClassHeaderNamedParams(
	connType string,
	initFields []string,
	driverReturnType string,
	async bool,
)

WriteQueryResultsClassHeaderNamedParams writes the header variant for drivers that bind parameters by name: a params dict replaces *args.

Jump to

Keyboard shortcuts

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