option

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2023 License: MPL-2.0 Imports: 5 Imported by: 0

README

protoql options

The option package includes options that may be used to manipulate query generation. The .proto file with the option(s) you want to use (or a copy of it) must be imported into your proto files in order to use the options. As an example:

syntax = "proto3";

import "path/to/protoql_options.proto"

message Account {
  option (protoql.gen) = true;

  int64 id = 1 [(protoql.primary_key) = true]; 
}

Check the .proto files in this package for the options that are available. Documentation about the options is in doc comments in the .proto files themselves in order to keep the docs close to the code.

Documentation

Overview

Package option contains the generated go code for protoql options.

Index

Constants

This section is empty.

Variables

View Source
var (
	ScanType_name = map[int32]string{
		0: "DIRECT",
		1: "COMPOSITE",
		2: "JSON",
	}
	ScanType_value = map[string]int32{
		"DIRECT":    0,
		"COMPOSITE": 1,
		"JSON":      2,
	}
)

Enum value maps for ScanType.

View Source
var (
	// primary_key tells protoc-gen-go-queries that the field is a primary key and
	// may be used to identify rows. If multiple fields are marked as a primary
	// key, they will be treated as a multi-column primary key.
	//
	// optional bool primary_key = 3000;
	E_PrimaryKey = &file_protoql_options_proto_extTypes[0]
	// skip allows you to skip individual fields. Setting this to true will skip a
	// field.
	//
	// optional bool skip = 3001;
	E_Skip = &file_protoql_options_proto_extTypes[1]
	// flatten tells protoql to treat sub-fields of this field as if they were
	// part of the parent message type.
	//
	// Example:
	//
	//	message Account {
	//	  string email = 1 [(protoql.primary_key) = 1];
	//	}
	//
	//	message AccountPass {
	//	  option (protoql.rel) = {namespace="public",name="account"};
	//	  Account account = 1 [(protoql.flatten) = true];
	//	  string passhash = 2;
	//	}
	//
	// optional bool flatten = 3002;
	E_Flatten = &file_protoql_options_proto_extTypes[2]
	// column may be used to explicitly define the column name rather than relying
	// on autogenerated column names.
	//
	// optional string column = 3003;
	E_Column = &file_protoql_options_proto_extTypes[3]
	// generated may be used to tell protoql that the value of this field is
	// generated in the database and should not be included in query arguments
	// (e.g. autogenerated `Create` methods or uses of `varFields` in custom
	// queries). It will still be scanned in result sets.
	//
	// optional bool generated = 3004;
	E_Generated = &file_protoql_options_proto_extTypes[4]
)

Extension fields to descriptorpb.FieldOptions.

View Source
var (
	// gen_crud may be used to tell protoql to auto-generate
	// create/read/update/delete query methods. If this message type does not
	// have any primary key(s) defined (see FieldOptions extensions), then only
	// a create method will be generated, since protoql does not know how to
	// look up the row related to a message.
	//
	// optional bool gen_crud = 3000;
	E_GenCrud = &file_protoql_options_proto_extTypes[5]
	// rel may be used to explicitly define a relation that this message is
	// associated with. Messages that are associated with more than one relation
	// should be configured either on fields or in a config file.
	//
	// Most of the time, this refers to a table. However, for composite types,
	// this may be used to reference the custom type.
	//
	// optional protoql.Relation rel = 3001;
	E_Rel = &file_protoql_options_proto_extTypes[6]
	// scan_type tells protoql the type of marshal/unmarshal it should use to
	// implement driver.Valuer and sql.Scanner types.
	//
	// optional protoql.ScanType scan_type = 3002;
	E_ScanType = &file_protoql_options_proto_extTypes[7]
)

Extension fields to descriptorpb.MessageOptions.

View Source
var (
	// message_gen_crud sets the default gen_crud value on all messages in a file. This
	// may be overridden on individual message types within the file.
	//
	// optional bool message_gen_crud = 3000;
	E_MessageGenCrud = &file_protoql_options_proto_extTypes[10]
	// query allows for defining custom queries. Since this is a repeated option,
	// it may be declared multiple times and will result in multiple custom
	// queries.
	//
	// repeated protoql.Query query = 3001;
	E_Query = &file_protoql_options_proto_extTypes[11]
	// message_scan_type sets the default scan_type value on all messages in a
	// file. This may be overridden on individual message types within the file.
	//
	// optional protoql.ScanType message_scan_type = 3002;
	E_MessageScanType = &file_protoql_options_proto_extTypes[12]
)

Extension fields to descriptorpb.FileOptions.

View Source
var (
	// json tells protoql to also make the enum type implement json.Marshaler and
	// json.Unmarshaler. The json values will match the value used in the database
	// (see the sql_value option).
	//
	// optional bool json = 3000;
	E_Json = &file_protoql_options_proto_extTypes[8]
)

Extension fields to descriptorpb.EnumOptions.

View Source
var (
	// sql_value sets the database value of an enum value.  This will be used
	// instead of the default when translating to/from values in the database.
	//
	// optional string sql_value = 3000;
	E_SqlValue = &file_protoql_options_proto_extTypes[9]
)

Extension fields to descriptorpb.EnumValueOptions.

View Source
var File_protoql_options_proto protoreflect.FileDescriptor

Functions

This section is empty.

Types

type Query

type Query struct {

	// name is a unique name to identify this query by. The generated method name
	// will match the exported camel-case version of this name.
	//
	// For example, `name: "FooBar"` and `name: "foo_bar"` will both result in a
	// method named FooBar.
	Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"`
	// query is the SQL that will be run. Parameters and results may be referenced
	// in this query using golang text/template syntax in order to ensure that
	// query variables and scan order is what you expect.
	//
	// See the `git.sr.ht/~nelsam/protoql/gen/custom` package docs for details
	// about the template functions and variables that are available.
	Query string `protobuf:"bytes,2,opt,name=query,proto3" json:"query,omitempty"`
	// typ is the type of this query and contains param/result types.
	//
	// Types that are assignable to Typ:
	//
	//	*Query_Write
	//	*Query_ReadOne
	//	*Query_Read
	Typ isQuery_Typ `protobuf_oneof:"typ"`
	// contains filtered or unexported fields
}

Query represents a single custom query that will generate a custom query method on the wrapper struct.

func (*Query) Descriptor deprecated

func (*Query) Descriptor() ([]byte, []int)

Deprecated: Use Query.ProtoReflect.Descriptor instead.

func (*Query) GetName

func (x *Query) GetName() string

func (*Query) GetQuery

func (x *Query) GetQuery() string

func (*Query) GetRead

func (x *Query) GetRead() *Read

func (*Query) GetReadOne

func (x *Query) GetReadOne() *ReadOne

func (*Query) GetTyp

func (m *Query) GetTyp() isQuery_Typ

func (*Query) GetWrite

func (x *Query) GetWrite() *Write

func (*Query) ProtoMessage

func (*Query) ProtoMessage()

func (*Query) ProtoReflect

func (x *Query) ProtoReflect() protoreflect.Message

func (*Query) Reset

func (x *Query) Reset()

func (*Query) String

func (x *Query) String() string

type Query_Read

type Query_Read struct {
	Read *Read `protobuf:"bytes,5,opt,name=read,proto3,oneof"`
}

type Query_ReadOne

type Query_ReadOne struct {
	ReadOne *ReadOne `protobuf:"bytes,4,opt,name=read_one,json=readOne,proto3,oneof"`
}

type Query_Write

type Query_Write struct {
	Write *Write `protobuf:"bytes,3,opt,name=write,proto3,oneof"`
}

type Read

type Read struct {
	Params  []*Variable `protobuf:"bytes,1,rep,name=params,proto3" json:"params,omitempty"`
	Results []*Variable `protobuf:"bytes,2,rep,name=results,proto3" json:"results,omitempty"`
	// contains filtered or unexported fields
}

Read represents a query that will read zero or more tuples. The generated code will return an iterator that will scan and return tuples on demand.

func (*Read) Descriptor deprecated

func (*Read) Descriptor() ([]byte, []int)

Deprecated: Use Read.ProtoReflect.Descriptor instead.

func (*Read) GetParams

func (x *Read) GetParams() []*Variable

func (*Read) GetResults

func (x *Read) GetResults() []*Variable

func (*Read) ProtoMessage

func (*Read) ProtoMessage()

func (*Read) ProtoReflect

func (x *Read) ProtoReflect() protoreflect.Message

func (*Read) Reset

func (x *Read) Reset()

func (*Read) String

func (x *Read) String() string

type ReadOne

type ReadOne struct {
	Params  []*Variable `protobuf:"bytes,1,rep,name=params,proto3" json:"params,omitempty"`
	Results []*Variable `protobuf:"bytes,2,rep,name=results,proto3" json:"results,omitempty"`
	// contains filtered or unexported fields
}

ReadOne represents a query that will read a single tuple from the database. The generated code will automatically scan the tuple and return it.

func (*ReadOne) Descriptor deprecated

func (*ReadOne) Descriptor() ([]byte, []int)

Deprecated: Use ReadOne.ProtoReflect.Descriptor instead.

func (*ReadOne) GetParams

func (x *ReadOne) GetParams() []*Variable

func (*ReadOne) GetResults

func (x *ReadOne) GetResults() []*Variable

func (*ReadOne) ProtoMessage

func (*ReadOne) ProtoMessage()

func (*ReadOne) ProtoReflect

func (x *ReadOne) ProtoReflect() protoreflect.Message

func (*ReadOne) Reset

func (x *ReadOne) Reset()

func (*ReadOne) String

func (x *ReadOne) String() string

type Relation

type Relation struct {
	Name      string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"`
	Namespace string `protobuf:"bytes,2,opt,name=namespace,proto3" json:"namespace,omitempty"`
	// contains filtered or unexported fields
}

Relation is an SQL relation - for exaample, a table. For the purposes of protoql, a relation has a namespace (usually a schema) and a name.

func (*Relation) Descriptor deprecated

func (*Relation) Descriptor() ([]byte, []int)

Deprecated: Use Relation.ProtoReflect.Descriptor instead.

func (*Relation) GetName

func (x *Relation) GetName() string

func (*Relation) GetNamespace

func (x *Relation) GetNamespace() string

func (*Relation) ProtoMessage

func (*Relation) ProtoMessage()

func (*Relation) ProtoReflect

func (x *Relation) ProtoReflect() protoreflect.Message

func (*Relation) Reset

func (x *Relation) Reset()

func (*Relation) String

func (x *Relation) String() string

type ScanType

type ScanType int32

ScanType represents the method that should be used to scan a value from the database into a field of this type.

const (
	// DIRECT represents normal, direct scanning, for values like strings that can
	// rely on default behavior.
	ScanType_DIRECT ScanType = 0
	// COMPOSITE represents database-level custom composite types.
	ScanType_COMPOSITE ScanType = 1
	// JSON represents json(b) columns that should implement json
	// marshal/unmarshal methods in the database.
	ScanType_JSON ScanType = 2
)

func (ScanType) Descriptor

func (ScanType) Descriptor() protoreflect.EnumDescriptor

func (ScanType) Enum

func (x ScanType) Enum() *ScanType

func (ScanType) EnumDescriptor deprecated

func (ScanType) EnumDescriptor() ([]byte, []int)

Deprecated: Use ScanType.Descriptor instead.

func (ScanType) Number

func (x ScanType) Number() protoreflect.EnumNumber

func (ScanType) String

func (x ScanType) String() string

func (ScanType) Type

type Variable

type Variable struct {

	// name is a unique identifier for the scope of a custom query, used as the
	// parameter or result name in the generated go code and for referencing
	// parameters or results in custom query templates.
	Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"`
	// type_name must match either a built-in type or the name of a custom type
	// (enum, message, etc). If the type is imported and the import specifies a
	// package namespace, type_name should include the namespace. The file in
	// question *must* be imported, even if the import is not otherwise used.
	//
	// For example, to use an Account message type imported from a
	// 'user'-namespaced file, type_name should be "user.Account".
	//
	// Note: it would be much cleaner to literally reference the imported type,
	// but we have thus far been unable to do so. We are still capable of erroring
	// out if the import cannot be found, but since protoc doesn't realize that
	// the import is being used, we get an ugly warning about unused imports.
	TypeName string `protobuf:"bytes,2,opt,name=type_name,json=typeName,proto3" json:"type_name,omitempty"`
	// contains filtered or unexported fields
}

Variable represents any variable, parameter, or return value.

func (*Variable) Descriptor deprecated

func (*Variable) Descriptor() ([]byte, []int)

Deprecated: Use Variable.ProtoReflect.Descriptor instead.

func (*Variable) GetName

func (x *Variable) GetName() string

func (*Variable) GetTypeName

func (x *Variable) GetTypeName() string

func (*Variable) ProtoMessage

func (*Variable) ProtoMessage()

func (*Variable) ProtoReflect

func (x *Variable) ProtoReflect() protoreflect.Message

func (*Variable) Reset

func (x *Variable) Reset()

func (*Variable) String

func (x *Variable) String() string

type Write

type Write struct {
	Params []*Variable `protobuf:"bytes,1,rep,name=params,proto3" json:"params,omitempty"`
	// contains filtered or unexported fields
}

Write represents a write-only query.

func (*Write) Descriptor deprecated

func (*Write) Descriptor() ([]byte, []int)

Deprecated: Use Write.ProtoReflect.Descriptor instead.

func (*Write) GetParams

func (x *Write) GetParams() []*Variable

func (*Write) ProtoMessage

func (*Write) ProtoMessage()

func (*Write) ProtoReflect

func (x *Write) ProtoReflect() protoreflect.Message

func (*Write) Reset

func (x *Write) Reset()

func (*Write) String

func (x *Write) String() string

Jump to

Keyboard shortcuts

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