codegen

package
v0.7.13 Latest Latest
Warning

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

Go to latest
Published: Sep 21, 2022 License: MPL-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package codegen helps autogenerate tables for CloudQuery source plugins from Go structs (of relevant SDKs).

Index

Constants

This section is empty.

Variables

View Source
var TemplatesFS embed.FS

Functions

func DefaultNameTransformer added in v0.7.13

func DefaultNameTransformer(field reflect.StructField) (string, error)

func DefaultTypeTransformer added in v0.7.12

func DefaultTypeTransformer(v reflect.StructField) (schema.ValueType, error)

Types

type ColumnDefinition

type ColumnDefinition struct {
	Name          string
	Type          schema.ValueType
	Resolver      string
	Description   string
	IgnoreInTests bool
	Options       schema.ColumnCreationOptions
}

type ColumnDefinitions

type ColumnDefinitions []ColumnDefinition

func (ColumnDefinitions) GetByName

func (c ColumnDefinitions) GetByName(name string) *ColumnDefinition

type NameTransformer added in v0.7.12

type NameTransformer func(reflect.StructField) (string, error)

type ResourceDefinition

type ResourceDefinition struct {
	Name  string
	Table *TableDefinition
}

type TableDefinition

type TableDefinition struct {
	Name        string
	Columns     ColumnDefinitions
	Description string
	Relations   []string

	Resolver             string
	IgnoreError          string
	Multiplex            string
	PostResourceResolver string
	PreResourceResolver  string
	// contains filtered or unexported fields
}

func NewTableFromStruct

func NewTableFromStruct(name string, obj interface{}, opts ...TableOptions) (*TableDefinition, error)

NewTableFromStruct creates a new TableDefinition from a struct by inspecting its fields

func (*TableDefinition) GenerateTemplate

func (t *TableDefinition) GenerateTemplate(wr io.Writer) error

type TableOptions

type TableOptions func(*TableDefinition)

func WithExtraColumns

func WithExtraColumns(columns ColumnDefinitions) TableOptions

WithExtraColumns allows passing additional ColumnDefinitions

func WithLogger added in v0.7.12

func WithLogger(logger zerolog.Logger) TableOptions

WithLogger allows passing custom logger

func WithNameTransformer

func WithNameTransformer(transformer NameTransformer) TableOptions

WithNameTransformer overrides how column name will be determined.

func WithSkipFields

func WithSkipFields(fields []string) TableOptions

WithSkipFields allows to specify what struct fields should be skipped.

func WithTypeTransformer added in v0.7.12

func WithTypeTransformer(transformer TypeTransformer) TableOptions

WithTypeTransformer sets a function that can override the schema type for specific fields. Return `schema.TypeInvalid` to fall back to default behavior.

func WithUnwrapAllEmbeddedStructs added in v0.6.1

func WithUnwrapAllEmbeddedStructs() TableOptions

WithUnwrapAllEmbeddedStructs instructs codegen to unwrap all embedded fields (1 level deep only)

func WithUnwrapFieldsStructs added in v0.6.1

func WithUnwrapFieldsStructs(fields []string) TableOptions

WithUnwrapFieldsStructs allows to unwrap specific struct fields (1 level deep only)

type TypeTransformer added in v0.7.12

type TypeTransformer func(reflect.StructField) (schema.ValueType, error)

Jump to

Keyboard shortcuts

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