Documentation
¶
Index ¶
- Constants
- func PyQuote(value string) string
- type CodeWriter
- func (w *CodeWriter) Bytes() []byte
- func (w *CodeWriter) DocstringsEnabled() bool
- func (w *CodeWriter) FitsLine(indent int, txt string) bool
- func (w *CodeWriter) NNewLine(n int)
- func (w *CodeWriter) NewLine()
- func (w *CodeWriter) String() string
- func (w *CodeWriter) WriteAll(items []string)
- func (w *CodeWriter) WriteEnumClassDocstring(name string)
- func (w *CodeWriter) WriteEnumsFileModuleDocstring()
- func (w *CodeWriter) WriteFutureImport()
- func (w *CodeWriter) WriteIndentedLine(level int, txt string)
- func (w *CodeWriter) WriteIndentedString(level int, txt string)
- func (w *CodeWriter) WriteInitFileModuleDocstring()
- func (w *CodeWriter) WriteLine(txt string)
- func (w *CodeWriter) WriteModelClassDocstring(table *model.Table)
- func (w *CodeWriter) WriteModelFileModuleDocstring()
- func (w *CodeWriter) WriteQueryClassConnDocstring(connType string)
- func (w *CodeWriter) WriteQueryClassDocstring(sourceName, connType string)
- func (w *CodeWriter) WriteQueryClassInitDocstring(lvl int, connType string)
- func (w *CodeWriter) WriteQueryFileModuleDocstring(sourceName string)
- func (w *CodeWriter) WriteQueryFunctionDocstring(lvl int, query *model.Query, connType string, args []DocArg, retType string)
- func (w *CodeWriter) WriteQueryResultsClassDocstring(connType, resultType string, namedParams bool)
- func (w *CodeWriter) WriteQueryResultsFetchDocstring(async bool)
- func (w *CodeWriter) WriteQueryResultsInitDocstring(connType, resultType string, namedParams bool)
- func (w *CodeWriter) WriteQueryResultsIterDocstring(async bool)
- func (w *CodeWriter) WriteQueryResultsNextDocstring(cursorPhrase string, async bool)
- func (w *CodeWriter) WriteSqlcHeader(query *model.Query)
- func (w *CodeWriter) WriteString(txt string)
- func (w *CodeWriter) WriteWrappedCall(indent int, head string, args []string, tail string)
- type DocArg
- type QueryResultsWriter
- func (w *QueryResultsWriter) WriteQueryResultsAwaitFunction(wrapperLines []string)
- func (w *QueryResultsWriter) WriteQueryResultsCallFunction(wrapperLines []string)
- func (w *QueryResultsWriter) WriteQueryResultsClassHeader(connType string, initFields []string, driverReturnType string, async bool)
- func (w *QueryResultsWriter) WriteQueryResultsClassHeaderNamedParams(connType string, initFields []string, driverReturnType string, async bool)
- func (w *QueryResultsWriter) WriteQueryResultsClassHeaderNoIterator(connType string, initFields []string, driverReturnType string, async bool)
Constants ¶
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 ¶
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) 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.
func (*QueryResultsWriter) WriteQueryResultsClassHeaderNoIterator ¶ added in v0.8.0
func (w *QueryResultsWriter) WriteQueryResultsClassHeaderNoIterator( connType string, initFields []string, driverReturnType string, async bool, )
WriteQueryResultsClassHeaderNoIterator writes the header variant for drivers whose cursor is consumed directly (no separate iterator object): the _iterator slot is dropped and only initFields declare cursor state.