codegen

package
v1.23.0 Latest Latest
Warning

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

Go to latest
Published: Jan 9, 2023 License: MPL-2.0 Imports: 12 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 DefaultResolverTransformer added in v0.8.1

func DefaultResolverTransformer(_ reflect.StructField, path string) (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 ResolverTransformer added in v0.8.1

type ResolverTransformer func(field reflect.StructField, path string) (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 any, opts ...TableOption) (*TableDefinition, error)

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

func (*TableDefinition) Check added in v1.2.0

func (t *TableDefinition) Check() error

Check that the resulting TableDefinition is correct (e.g., no overlapping column names).

func (*TableDefinition) GenerateTemplate

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

type TableOption added in v0.8.0

type TableOption func(*TableDefinition)

func WithExtraColumns

func WithExtraColumns(columns ColumnDefinitions) TableOption

WithExtraColumns allows passing additional ColumnDefinitions

func WithLogger added in v0.7.12

func WithLogger(logger zerolog.Logger) TableOption

WithLogger allows passing custom logger

func WithNameTransformer

func WithNameTransformer(transformer NameTransformer) TableOption

WithNameTransformer overrides how column name will be determined. DefaultNameTransformer is used as the default.

func WithPKColumns added in v1.3.0

func WithPKColumns(columnNames ...string) TableOption

WithPKColumns allows to specify what columns should be considered PKs without need for WithExtraColumns + WithSkipFields

func WithResolverTransformer added in v0.8.1

func WithResolverTransformer(transformer ResolverTransformer) TableOption

WithResolverTransformer sets a function that can override the resolver for a field. DefaultResolverTransformer is used as the default. If the transformer provided returns error, gen will fail. To fallback onto the default resolver return "", nil.

func WithSkipFields

func WithSkipFields(fields []string) TableOption

WithSkipFields allows to specify what struct fields should be skipped.

func WithTypeTransformer added in v0.7.12

func WithTypeTransformer(transformer TypeTransformer) TableOption

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

func WithUnwrapAllEmbeddedStructs added in v0.6.1

func WithUnwrapAllEmbeddedStructs() TableOption

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

func WithUnwrapStructFields added in v0.8.0

func WithUnwrapStructFields(fields []string) TableOption

WithUnwrapStructFields 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