{"modulePath":"github.com/cloudquery/plugin-sdk/v3","version":"v3.10.6","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package schema\n\nPackage schema defines types supported by tables in source plugins\n\n## Constants\n\n```go\nconst (\n\tMetadataUnique         = \"cq:extension:unique\"\n\tMetadataPrimaryKey     = \"cq:extension:primary_key\"\n\tMetadataConstraintName = \"cq:extension:constraint_name\"\n\tMetadataIncremental    = \"cq:extension:incremental\"\n\n\tMetadataTrue             = \"true\"\n\tMetadataFalse            = \"false\"\n\tMetadataTableName        = \"cq:table_name\"\n\tMetadataTableDescription = \"cq:table_description\"\n)\n```\n\n## Variables\n\n```go\nvar CqIDColumn = Column{\n\tName:        \"_cq_id\",\n\tType:        types.ExtensionTypes.UUID,\n\tDescription: \"Internal CQ ID of the row\",\n\tNotNull:     true,\n\tUnique:      true,\n}\n```\nThese columns are managed and populated by the source plugins\n\n```go\nvar CqParentIDColumn = Column{\n\tName:          \"_cq_parent_id\",\n\tType:          types.ExtensionTypes.UUID,\n\tDescription:   \"Internal CQ ID of the parent row\",\n\tResolver:      parentCqUUIDResolver(),\n\tIgnoreInTests: true,\n}\n```\n\n```go\nvar CqSourceNameColumn = Column{\n\tName:        \"_cq_source_name\",\n\tType:        arrow.BinaryTypes.String,\n\tDescription: \"Internal CQ row that references the source plugin name data was retrieved\",\n}\n```\n\n```go\nvar CqSyncTimeColumn = Column{\n\tName:        \"_cq_sync_time\",\n\tType:        arrow.FixedWidthTypes.Timestamp_us,\n\tDescription: \"Internal CQ row of when sync was started (this will be the same for all rows in a single fetch)\",\n}\n```\nThese columns are managed and populated by the destination plugin.\n\n## Functions\n\n```go\nfunc GenTestData(table *Table, opts GenTestDataOptions) []arrow.Record\n```\nGenTestData generates a slice of arrow.Records with the given schema and options.\n\n```go\nfunc ValidColumnName(name string) bool\n```\n\n```go\nfunc ValidateTable(t *Table) error\n```\n\n## Types\n\n```go\ntype ClientMeta interface {\n\tID() string\n}\n```\n\n```go\ntype Column struct {\n\t// Name of column\n\tName string\n\t// Value Type of column i.e String, UUID etc'\n\tType arrow.DataType\n\t// Description about column, this description is added as a comment in the database\n\tDescription string\n\t// Column Resolver allows to set your own data for a column; this can be an API call, setting multiple embedded values, etc\n\tResolver ColumnResolver\n\n\t// IgnoreInTests is used to skip verifying the column is non-nil in integration tests.\n\t// By default, integration tests perform a fetch for all resources in cloudquery's test account, and\n\t// verify all columns are non-nil.\n\t// If IgnoreInTests is true, verification is skipped for this column.\n\t// Used when it is hard to create a reproducible environment with this column being non-nil (e.g. various error columns).\n\tIgnoreInTests bool\n\n\t// PrimaryKey requires the destinations supporting this to include this column into the primary key\n\tPrimaryKey bool\n\t// NotNull requires the destinations supporting this to mark this column as non-nullable\n\tNotNull bool\n\t// IncrementalKey is a flag that indicates if the column is used as part of an incremental key.\n\t// It is mainly used for documentation purposes, but may also be used as part of ensuring that\n\t// migrations are done correctly.\n\tIncrementalKey bool\n\t// Unique requires the destinations supporting this to mark this column as unique\n\tUnique bool\n}\n```\nColumn definition for Table\n\n```go\nfunc NewColumnFromArrowField(f arrow.Field) Column\n```\nNewColumnFromArrowField creates a new Column from an arrow.Field arrow.Field is a low-level representation of a CloudQuery column that can be sent over the wire in a cross-language way.\n\n```go\nfunc TestSourceColumns(testOpts TestSourceOptions) []Column\n```\nTestSourceColumns returns columns for all Arrow types and composites thereof. TestSourceOptions controls which types are included.\n\n```go\nfunc (c Column) String() string\n```\n\n```go\nfunc (c Column) ToArrowField() arrow.Field\n```\n\n```go\ntype ColumnList []Column\n```\n\n```go\nfunc (c ColumnList) Get(name string) *Column\n```\n\n```go\nfunc (c ColumnList) Index(col string) int\n```\n\n```go\nfunc (c ColumnList) Names() []string\n```\n\n```go\nfunc (c ColumnList) String() string\n```\n\n```go\ntype ColumnResolver func(ctx context.Context, meta ClientMeta, resource *Resource, c Column) error\n```\nColumnResolver is called for each row received in TableResolver's data fetch. execution holds all relevant information regarding execution as well as the Column called. resource holds the current row we are resolving the column for.\n\n```go\nfunc ParentColumnResolver(name string) ColumnResolver\n```\nParentColumnResolver resolves a column from the parent's table data, if name isn't set the column will be set to null\n\n```go\nfunc PathResolver(path string) ColumnResolver\n```\nPathResolver resolves a field in the Resource.Item\n\nExamples: PathResolver(\"Field\") PathResolver(\"InnerStruct.Field\") PathResolver(\"InnerStruct.InnerInnerStruct.Field\")\n\n```go\ntype GenTestDataOptions struct {\n\t// SourceName is the name of the source to set in the source_name column.\n\tSourceName string\n\t// SyncTime is the time to set in the sync_time column.\n\tSyncTime time.Time\n\t// MaxRows is the number of rows to generate.\n\t// Rows alternate between not containing null values and containing only null values.\n\t// (Only columns that are nullable according to the schema will be null)\n\tMaxRows int\n\t// StableUUID is the UUID to use for all rows. If set to uuid.Nil, a new UUID will be generated\n\tStableUUID uuid.UUID\n\t// StableTime is the time to use for all rows other than sync time. If set to time.Time{}, a new time will be generated\n\tStableTime    time.Time\n\tTimePrecision time.Duration\n\tSeed          int64\n}\n```\nGenTestDataOptions are options for generating test data\n\n```go\ntype LengthTableValidator struct{}\n```\n\n```go\nfunc (LengthTableValidator) Validate(t *Table) error\n```\n\n```go\ntype Multiplexer func(meta ClientMeta) []ClientMeta\n```\n\n```go\ntype Resource struct {\n\t// Original resource item that wa from prior resolve\n\tItem any\n\t// Set if this is an embedded table\n\tParent *Resource\n\t// internal fields\n\tTable *Table\n\t// contains filtered or unexported fields\n}\n```\nResource represents a row in it's associated table, it carries a reference to the original item, and automatically generates an Id based on Table's Columns. Resource data can be accessed by the Get and Set methods\n\n```go\nfunc NewResourceData(t *Table, parent *Resource, item any) *Resource\n```\n\n```go\nfunc (r *Resource) CalculateCQID(deterministicCQID bool) error\n```\n\n```go\nfunc (r *Resource) Get(columnName string) scalar.Scalar\n```\n\n```go\nfunc (r *Resource) GetItem() any\n```\n\n```go\nfunc (r *Resource) GetValues() scalar.Vector\n```\n\n```go\nfunc (r *Resource) Set(columnName string, value any) error\n```\nSet sets a column with value. This does validation and conversion to one of concrete  it returns an error just for backward compatibility and panics in case it fails\n\n```go\nfunc (r *Resource) SetItem(item any)\n```\nOverride original item (this is useful for apis that follow list/details pattern)\n\n```go\nfunc (r *Resource) Validate() error\n```\nValidates that all primary keys have values.\n\n```go\ntype Resources []*Resource\n```\n\n```go\nfunc (rr Resources) ColumnNames() []string\n```\n\n```go\nfunc (rr Resources) TableName() string\n```\n\n```go\ntype RowResolver func(ctx context.Context, meta ClientMeta, resource *Resource) error\n```\n\n```go\ntype Schemas []*arrow.Schema\n```\n\n```go\nfunc NewSchemasFromBytes(b [][]byte) (Schemas, error)\n```\n\n```go\nfunc (s Schemas) Encode() ([][]byte, error)\n```\n\n```go\nfunc (s Schemas) Len() int\n```\n\n```go\nfunc (s Schemas) SchemaByName(name string) *arrow.Schema\n```\n\n```go\ntype SyncSummary struct {\n\tResources uint64\n\tErrors    uint64\n\tPanics    uint64\n}\n```\nThis is deprecated\n\n```go\ntype Table struct {\n\t// Name of table\n\tName string\n\t// Title to be used in documentation (optional: will be generated from name if not set)\n\tTitle string\n\t// table description\n\tDescription string\n\t// Columns are the set of fields that are part of this table\n\tColumns ColumnList\n\t// Relations are a set of related tables defines\n\tRelations Tables\n\t// Transform\n\tTransform Transform\n\t// Resolver is the main entry point to fetching table data and\n\tResolver TableResolver\n\t// Multiplex returns re-purposed meta clients. The sdk will execute the table with each of them\n\tMultiplex Multiplexer\n\t// PostResourceResolver is called after all columns have been resolved, but before the Resource is sent to be inserted. The ordering of resolvers is:\n\t//  (Table) Resolver → PreResourceResolver → ColumnResolvers → PostResourceResolver\n\tPostResourceResolver RowResolver\n\t// PreResourceResolver is called before all columns are resolved but after Resource is created. The ordering of resolvers is:\n\t//  (Table) Resolver → PreResourceResolver → ColumnResolvers → PostResourceResolver\n\tPreResourceResolver RowResolver\n\t// IsIncremental is a flag that indicates if the table is incremental or not. This flag mainly affects how the table is\n\t// documented.\n\tIsIncremental bool\n\n\t// IgnoreInTests is used to exclude a table from integration tests.\n\t// By default, integration tests fetch all resources from cloudquery's test account, and verify all tables\n\t// have at least one row.\n\t// When IgnoreInTests is true, integration tests won't fetch from this table.\n\t// Used when it is hard to create a reproducible environment with a row in this table.\n\tIgnoreInTests bool\n\n\t// Parent is the parent table in case this table is called via parent table (i.e. relation)\n\tParent *Table\n\n\tPkConstraintName string\n}\n```\n\n```go\nfunc NewTableFromArrowSchema(sc *arrow.Schema) (*Table, error)\n```\nCreate a CloudQuery Table abstraction from an arrow schema arrow schema is a low level representation of a table that can be sent over the wire in a cross-language way\n\n```go\nfunc TestTable(name string, testOpts TestSourceOptions) *Table\n```\nTestTable returns a table with columns of all types. Useful for destination testing purposes\n\n```go\nfunc (t *Table) Column(name string) *Column\n```\n\n```go\nfunc (t *Table) Copy(parent *Table) *Table\n```\n\n```go\nfunc (t *Table) GetChanges(old *Table) []TableColumnChange\n```\nGet Changes returns changes between two tables when t is the new one and old is the old one.\n\n```go\nfunc (t *Table) IncrementalKeys() []string\n```\n\n```go\nfunc (t *Table) OverwriteOrAddColumn(column *Column)\n```\nIf the column with the same name exists, overwrites it. Otherwise, adds the column to the beginning of the table.\n\n```go\nfunc (t *Table) PrimaryKeys() []string\n```\n\n```go\nfunc (t *Table) PrimaryKeysIndexes() []int\n```\n\n```go\nfunc (t *Table) TableNames() []string\n```\n\n```go\nfunc (t *Table) ToArrowSchema() *arrow.Schema\n```\n\n```go\nfunc (t *Table) ValidateColumnNames() error\n```\n\n```go\nfunc (t *Table) ValidateDuplicateColumns() error\n```\n\n```go\nfunc (t *Table) ValidateName() error\n```\n\n```go\ntype TableColumnChange struct {\n\tType       TableColumnChangeType\n\tColumnName string\n\tCurrent    Column\n\tPrevious   Column\n}\n```\n\n```go\nfunc (t TableColumnChange) String() string\n```\n\n```go\ntype TableColumnChangeType int\n```\n\n```go\nconst (\n\tTableColumnChangeTypeUnknown TableColumnChangeType = iota\n\tTableColumnChangeTypeAdd\n\tTableColumnChangeTypeUpdate\n\tTableColumnChangeTypeRemove\n)\n```\n\n```go\nfunc (t TableColumnChangeType) String() string\n```\n\n```go\ntype TableResolver func(ctx context.Context, meta ClientMeta, parent *Resource, res chan\u003c- any) error\n```\nTableResolver is the main entry point when a table is sync is called.\n\nTable resolver has 3 main arguments: - meta(ClientMeta): is the client returned by the plugin.Provider Configure call - parent(Resource): resource is the parent resource in case this table is called via parent table (i.e. relation) - res(chan any): is a channel to pass results fetched by the TableResolver\n\n```go\ntype TableValidator interface {\n\tValidate(t *Table) error\n}\n```\n\n```go\ntype Tables []*Table\n```\n\n```go\nfunc NewTablesFromArrowSchemas(schemas []*arrow.Schema) (Tables, error)\n```\n\n```go\nfunc NewTablesFromBytes(b [][]byte) (Tables, error)\n```\n\n```go\nfunc (tt Tables) FilterDfs(tables, skipTables []string, skipDependentTables bool) (Tables, error)\n```\n\n```go\nfunc (tt Tables) FilterDfsFunc(include, exclude func(*Table) bool, skipDependentTables bool) Tables\n```\n\n```go\nfunc (tt Tables) FlattenTables() Tables\n```\n\n```go\nfunc (tt Tables) Get(name string) *Table\n```\nGet returns a table by name. Returns top-level tables and relations.\n\n```go\nfunc (tt Tables) GetTopLevel(name string) *Table\n```\nGetTopLevel returns a table by name. Only returns the table if it is in top-level list.\n\n```go\nfunc (tt Tables) TableNames() []string\n```\n\n```go\nfunc (tt Tables) ToArrowSchemas() Schemas\n```\n\n```go\nfunc (tt Tables) ValidateColumnNames() error\n```\n\n```go\nfunc (tt Tables) ValidateDuplicateColumns() error\n```\n\n```go\nfunc (tt Tables) ValidateDuplicateTables() error\n```\n\n```go\nfunc (tt Tables) ValidateTableNames() error\n```\n\n```go\ntype TestSourceOptions struct {\n\tSkipDates      bool\n\tSkipDecimals   bool\n\tSkipDurations  bool\n\tSkipIntervals  bool\n\tSkipLargeTypes bool // e.g. large binary, large string\n\tSkipLists      bool // lists of all primitive types. Lists that were supported by CQTypes are always included.\n\tSkipMaps       bool\n\tSkipStructs    bool\n\tSkipTimes      bool // time of day types\n\tSkipTimestamps bool // timestamp types. Microsecond timestamp is always be included, regardless of this setting.\n\tTimePrecision  time.Duration\n}\n```\nTestSourceOptions controls which types are included by TestSourceColumns.\n\n```go\ntype Transform func(table *Table) error\n```\n\n```go\ntype ValidationError struct {\n\tErr   error\n\tMsg   string\n\tType  arrow.DataType\n\tValue any\n}\n```\n\n```go\nfunc (e *ValidationError) Error() string\n```\n\n```go\nfunc (e *ValidationError) MaskedError() string\n```\nthis prints the error without the value\n\n```go\nfunc (e *ValidationError) Unwrap() error\n```\n\n","path":"github.com/cloudquery/plugin-sdk/v3/schema","name":"schema","synopsis":"Package schema defines types supported by tables in source plugins","isRedistributable":true}
