Documentation
¶
Index ¶
- Variables
- type Custom
- type Enum
- type EnumValue
- type Field
- func (f *Field) Embed() option.Embed
- func (f *Field) GoName() string
- func (f *Field) Name() string
- func (f *Field) Nilable() bool
- func (f *Field) OnWrite() option.OnWrite
- func (f *Field) PKey() bool
- func (f *Field) Parent() (internal.Reference, internal.Field, internal.Message)
- func (f *Field) SQLName() (string, error)
- func (f *Field) Type() any
- func (f *Field) TypeRef() string
- type FieldOption
- type FieldSource
- type Message
- func (m *Message) CRUD() bool
- func (m *Message) CRUDStorer() string
- func (m *Message) Fields(parent internal.Field, ref internal.Reference) iter.Seq[internal.Field]
- func (m *Message) GoName() string
- func (m *Message) Name() string
- func (m *Message) Nilable() bool
- func (m *Message) Relation() (nsp, name string)
- func (m *Message) ValueType() option.MsgValueType
- type Relation
- type Source
- type SourceEnum
- type SourceEnumValue
- type SourceField
- type SourceMessage
Constants ¶
This section is empty.
Variables ¶
var ErrNotMapped = errors.New("field has no SQL mapping")
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 (*Custom) Docs ¶
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.
type Enum ¶
type Enum struct {
// contains filtered or unexported fields
}
func NewEnum ¶
func NewEnum(e SourceEnum) *Enum
func (*Enum) ValueType ¶
func (e *Enum) ValueType() option.EnumValueType
type EnumValue ¶
type EnumValue struct {
// contains filtered or unexported fields
}
func NewEnumValue ¶
func NewEnumValue(v SourceEnumValue, dflt option.EnumValueType) *EnumValue
type Field ¶
type Field struct {
// contains filtered or unexported fields
}
func NewField ¶
func NewField(cst FieldSource, opts ...FieldOption) (*Field, error)
func (*Field) 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) Name ¶
Name returns the field name in the source, as it would be referenced in a query template.
func (*Field) 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 ¶
PKey returns whether or not this field is part of the mapped table's primary key.
func (*Field) SQLName ¶
SQLName returns the mapped column name for this field. If there is no mapped column, this will error.
type FieldOption ¶
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 ¶
func FromField ¶
func FromField(sf SourceField) 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) CRUDStorer ¶
func (*Message) Fields ¶
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) ValueType ¶
func (m *Message) ValueType() option.MsgValueType
type SourceEnum ¶
type SourceEnum interface {
Name() string
GoName() string
ValueType() option.EnumValueType
Values() iter.Seq[SourceEnumValue]
}
type SourceEnumValue ¶
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).