typ

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Jan 14, 2026 License: MPL-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNotMapped = errors.New("field has no SQL mapping")
View Source
var ErrUnmatchedReference = errors.New("typ: parent names do not match child primary keys")

Functions

This section is empty.

Types

type Custom

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

func CRUD

func CRUD(s Source, m internal.Message) ([]*Custom, error)

func NewCustom

func NewCustom(t Source, query *option.Query) (*Custom, error)

func (*Custom) Docs

func (c *Custom) Docs() string

Docs returns the documentation of this query. If no documentation was provided or if the documentation does not start with the query name, then Docs will generate generic documentation about the query type and what it returns.

The return value of Docs will prefix each line with `// ` unless it is already prefixed.

func (*Custom) Name

func (c *Custom) Name() string

Name returns the name of this query.

func (*Custom) Params

func (c *Custom) Params() []gen.Field

Params returns the parameters defined for this query function.

func (*Custom) Results

func (c *Custom) Results() []gen.Field

Results returns the results defined for this query function.

func (*Custom) Storer

func (c *Custom) Storer() string

Storer returns the name of the receiver of this query method.

func (*Custom) Template

func (c *Custom) Template() string

Template returns the template string defined for this query function.

func (*Custom) Type

func (c *Custom) Type() gen.QueryType

Type returns the type of this query.

type Enum

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

func NewEnum

func NewEnum(e SourceEnum) *Enum

func (*Enum) GoName

func (e *Enum) GoName() string

func (*Enum) Name

func (e *Enum) Name() string

func (*Enum) ValueType

func (e *Enum) ValueType() option.EnumValueType

func (*Enum) Values

func (e *Enum) Values() iter.Seq[internal.EnumValue]

type EnumValue

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

func NewEnumValue

func NewEnumValue(v SourceEnumValue, dflt option.EnumValueType) *EnumValue

func (*EnumValue) GoRef

func (v *EnumValue) GoRef() string

func (*EnumValue) Name

func (v *EnumValue) Name() string

func (*EnumValue) SQLValue

func (v *EnumValue) SQLValue() string

type Field

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

func NewField

func NewField(cst FieldSource, opts ...FieldOption) (*Field, error)

func (*Field) Embed

func (f *Field) Embed() option.Embed

Embed returns how this Field is embedded in its parent. Returns option.Embed_NONE if it has no parent (i.e. it is a variable). Can also return option.Embed_NONE if it is a message field that is not mapped to a database column.

func (*Field) GoName

func (f *Field) GoName() string

GoName returns the go field name for this field.

func (*Field) Name

func (f *Field) Name() string

Name returns the field name in the source, as it would be referenced in a query template.

func (*Field) Nilable

func (f *Field) Nilable() bool

Nilable returns true if this field can be nil.

func (*Field) OnWrite

func (f *Field) OnWrite() option.OnWrite

OnWrite returns how this field should be used in write queries. We handle FIELD_DEFAULT here, returning IGNORE for primary keys and SAVE otherwise.

func (*Field) PKey

func (f *Field) PKey() bool

PKey returns whether or not this field is part of the mapped table's primary key.

func (*Field) Parent

Parent returns the message that this field is a part of, if any.

func (*Field) SQLName

func (f *Field) SQLName() (string, error)

SQLName returns the mapped column name for this field. If there is no mapped column, this will error.

func (*Field) Type

func (f *Field) Type() any

Type returns the underlying type of f. For scalars, this will be identical to TypeRef(). For messages and enums, it will be a Message or Enum (respectively).

func (*Field) TypeRef

func (f *Field) TypeRef() string

TypeRef returns a reference to this field's go type. For example, an int64 field returns "int64", while a custom message named Foo from an import named foo returns "*foo.Foo".

type FieldOption

type FieldOption func(Field) Field

func WithParent

func WithParent(pField internal.Field, ref internal.Reference, pM *Message, kind option.Embed) FieldOption

WithParent returns an option that tells a Field about its parent Message type (pM) and the field that references it.

func WithSQLName

func WithSQLName(name string, err error) FieldOption

WithNameFmt takes a name formatter to translate a field's name. format must include exactly one string formatting verb.

type FieldSource

type FieldSource func(Field) (Field, error)

func FromField

func FromField(sf SourceField) FieldSource

func FromVar

func FromVar(s Source, v *option.Variable) FieldSource

type Message

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

Message represents a message structure that protoql can generate database code for.

func NewMessage

func NewMessage(m SourceMessage) (*Message, error)

NewMessage wraps up a SourceMessage in a common structure.

func (*Message) CRUD

func (m *Message) CRUD() bool

func (*Message) CRUDStorer

func (m *Message) CRUDStorer() string

func (*Message) Fields

func (m *Message) Fields(parent internal.Field, ref internal.Reference) iter.Seq[internal.Field]

Fields returns an iterator of fields on m. The parent field sets our parent field, while ref tells us how the parent was referenced.

func (*Message) GoName

func (m *Message) GoName() string

func (*Message) Name

func (m *Message) Name() string

func (*Message) Nilable

func (m *Message) Nilable() bool

func (*Message) Relation

func (m *Message) Relation() (nsp, name string)

func (*Message) ValueType

func (m *Message) ValueType() option.MsgValueType

type Relation

type Relation struct {
	Namespace string
	Name      string
}

Relation is a database relation, referenced by a namespace and a name.

type Source

type Source interface {
	// Storer returns the default receiver name for query methods from this
	// source.
	Storer() string

	// GoType returns the go type of a type reference.
	GoType(string) (ref string, typ any, nilable bool, _ error)
}

type SourceEnum

type SourceEnum interface {
	Name() string
	GoName() string
	ValueType() option.EnumValueType
	Values() iter.Seq[SourceEnumValue]
}

type SourceEnumValue

type SourceEnumValue interface {
	Name() string
	GoName() string
	SQLValue() string
}

type SourceField

type SourceField interface {
	// Name returns the name of the field in the source protocol.
	Name() string

	// GoName returns the name of the field in generated go code.
	GoName() string

	// SQLName returns the name of the SQL column this field references. If it
	// returns an empty string, the name will be inferred from Name().
	//
	// If this field does not map to an SQL column, SQLName() should return "-".
	SQLName() string

	// TypeRef returns a string representation referencing this field's type.
	TypeRef() string

	// Type returns the underlying type, whether or not the type is nilable, and
	// any errors encountered looking up the type.
	Type() (_ any, nilable bool, _ error)

	// Embed returns how this field is embedded in its parent.
	Embed() option.Embed

	// PKey returns true if the field's mapped column is part of a primary key
	// in the database.
	PKey() bool

	// OnWrite returns the behavior that write queries should follow.
	OnWrite() option.OnWrite
}

SourceField is a field (or variable) from a source protocol.

type SourceMessage

type SourceMessage interface {
	// Name is the name of this message in the source protocol.
	Name() string

	// GoName is the name of this message in generated go code.
	GoName() string

	// Nilable returns true if the go type is nilable (i.e. if it's typically
	// used as a pointer).
	Nilable() bool

	// CRUD returns true if protoql should generate automatic create, read,
	// update, and delete queries for this message type. We skip any queries
	// that we don't have enough information to generate.
	CRUD() bool

	// CRUDStorer returns the name of the receiver type to generate CRUD methods
	// on for this message type.
	CRUDStorer() string

	// ValueType returns how this message type is used as a value in the
	// database. It's safe to return option.ValueType_CUSTOM if this message is
	// not used as a database value.
	ValueType() option.MsgValueType

	// Relation returns the Relation that this message is associated with, if
	// any. Returning nil signals that protoql should use the default name
	// if/when it is needed.
	Relation() *Relation

	// Fields returns an iterator over the message's fields. If an error occurs
	// converting a field to a SourceField, the iterator should pass the error
	// to the yield function.
	Fields() iter.Seq2[SourceField, error]
}

SourceMessage represents a message type in source protocol code (e.g. a protobuf message type).

Jump to

Keyboard shortcuts

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