Documentation ¶
Index ¶
- func DeleteParentIdFilter(id string) func(meta ClientMeta, parent *Resource) []interface{}
- func GetPgTypeFromType(v ValueType) string
- func ParentIdResolver(_ context.Context, _ ClientMeta, r *Resource, c Column) error
- func TruncateTableConstraint(name string) string
- func ValidateTable(t *Table) error
- type ClientMeta
- type Column
- type ColumnCreationOptions
- type ColumnMeta
- type ColumnResolver
- func DateResolver(path string, rfcs ...string) ColumnResolver
- func DateUTCResolver(path string, rfcs ...string) ColumnResolver
- func IPAddressResolver(path string) ColumnResolver
- func IPNetResolver(path string) ColumnResolver
- func IntResolver(path string) ColumnResolver
- func MACAddressResolver(path string) ColumnResolver
- func ParentPathResolver(path string) ColumnResolver
- func ParentResourceFieldResolver(name string) ColumnResolver
- func PathResolver(path string) ColumnResolver
- func StringResolver(path string) ColumnResolver
- func UUIDResolver(path string) ColumnResolver
- type Database
- type ExecutionData
- type IgnoreErrorFunc
- type LengthTableValidator
- type PgDatabase
- func (p PgDatabase) Close()
- func (p PgDatabase) CopyFrom(ctx context.Context, resources Resources, shouldCascade bool, ...) error
- func (p PgDatabase) Delete(ctx context.Context, t *Table, kvFilters []interface{}) error
- func (p PgDatabase) Exec(ctx context.Context, query string, args ...interface{}) error
- func (p PgDatabase) Insert(ctx context.Context, t *Table, resources Resources) error
- func (p PgDatabase) Query(ctx context.Context, query string, args ...interface{}) (pgx.Rows, error)
- func (p PgDatabase) QueryOne(ctx context.Context, query string, args ...interface{}) pgx.Row
- func (p PgDatabase) RemoveStaleData(ctx context.Context, t *Table, executionStart time.Time, ...) error
- type ResolverMeta
- type Resource
- type ResourceFetchError
- type Resources
- type RowResolver
- type Table
- type TableCreationOptions
- type TableResolver
- type TableValidator
- type ValueType
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DeleteParentIdFilter ¶ added in v0.3.0
func DeleteParentIdFilter(id string) func(meta ClientMeta, parent *Resource) []interface{}
DeleteParentIdFilter is mostly used for table relations to delete table data based on parent's cq_id
func GetPgTypeFromType ¶
func ParentIdResolver ¶
ParentIdResolver resolves the cq_id from the parent if you want to reference the parent's primary keys use ParentResourceFieldResolver as required.
func TruncateTableConstraint ¶ added in v0.3.0
func ValidateTable ¶ added in v0.2.0
Types ¶
type ClientMeta ¶
type ClientMeta interface {
Logger() hclog.Logger
}
type Column ¶
type Column struct { // Name of column Name string // Value Type of column i.e String, UUID etc' Type ValueType // Description about column, this description is added as a comment in the database Description string // Default value if the resolver/default getting gets a nil value Default interface{} // Column Resolver allows to set you own data based on resolving this can be an API call or setting multiple embedded values etc' Resolver ColumnResolver // Ignore errors checks if returned error from column resolver should be ignored. IgnoreError IgnoreErrorFunc // Creation options allow modifying how column is defined when table is created CreationOptions ColumnCreationOptions // contains filtered or unexported fields }
Column definition for Table
func GetDefaultSDKColumns ¶ added in v0.3.0
func GetDefaultSDKColumns() []Column
GetDefaultSDKColumns Default columns of the SDK, these columns are added to each table by default
func SetColumnMeta ¶ added in v0.5.1
func SetColumnMeta(c Column, m *ColumnMeta) Column
func (Column) Meta ¶ added in v0.5.1
func (c Column) Meta() *ColumnMeta
func (Column) ValidateType ¶
type ColumnCreationOptions ¶
ColumnCreationOptions allow modification of how column is defined when table is created
type ColumnMeta ¶ added in v0.5.1
type ColumnMeta struct { Resolver *ResolverMeta IgnoreExists bool }
type ColumnResolver ¶
ColumnResolver 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.
func DateResolver ¶ added in v0.3.2
func DateResolver(path string, rfcs ...string) ColumnResolver
DateResolver resolves the different date formats (ISODate - 2011-10-05T14:48:00.000Z is default) into *time.Time
Examples: DateResolver("Date") - resolves using RFC.RFC3339 as default DateResolver("InnerStruct.Field", time.RFC822) - resolves using time.RFC822 DateResolver("InnerStruct.Field", time.RFC822, "2011-10-05") - resolves using a few resolvers one by one
func DateUTCResolver ¶ added in v0.3.2
func DateUTCResolver(path string, rfcs ...string) ColumnResolver
DateUTCResolver resolves the different date formats (ISODate - 2011-10-05T14:48:00.000Z is default) into *time.Time and converts the date to utc timezone
Examples: DateUTCResolver("Date") - resolves using RFC.RFC3339 as default DateUTCResolver("InnerStruct.Field", time.RFC822) - resolves using time.RFC822 DateUTCResolver("InnerStruct.Field", time.RFC822, "2011-10-05") - resolves using a few resolvers one by one
func IPAddressResolver ¶ added in v0.3.2
func IPAddressResolver(path string) ColumnResolver
IPAddressResolver resolves the ip string value and returns net.IP
Examples: IPAddressResolver("IP")
func IPNetResolver ¶ added in v0.3.2
func IPNetResolver(path string) ColumnResolver
IPNetResolver resolves the network string value and returns net.IPNet
Examples: IPNetResolver("Network")
func IntResolver ¶ added in v0.3.2
func IntResolver(path string) ColumnResolver
IntResolver tries to cast value into int
Examples: IntResolver("Id")
func MACAddressResolver ¶ added in v0.3.2
func MACAddressResolver(path string) ColumnResolver
MACAddressResolver resolves the mac string value and returns net.HardwareAddr
Examples: MACAddressResolver("MAC")
func ParentPathResolver ¶ added in v0.3.0
func ParentPathResolver(path string) ColumnResolver
ParentPathResolver resolves a field from the parent
func ParentResourceFieldResolver ¶ added in v0.3.0
func ParentResourceFieldResolver(name string) ColumnResolver
ParentResourceFieldResolver resolves a field from the parent's resource, the value is expected to be set if name isn't set the field will be set to null
func PathResolver ¶
func PathResolver(path string) ColumnResolver
PathResolver resolves a field in the Resource.Item
Examples: PathResolver("Field") PathResolver("InnerStruct.Field") PathResolver("InnerStruct.InnerInnerStruct.Field")
func StringResolver ¶ added in v0.3.2
func StringResolver(path string) ColumnResolver
StringResolver tries to cast value into string
Examples: StringResolver("Id")
func UUIDResolver ¶ added in v0.3.2
func UUIDResolver(path string) ColumnResolver
UUIDResolver resolves the uuid string value and returns uuid.UUID
Examples: UUIDResolver("Resource.UUID")
type Database ¶
type Database interface { Insert(ctx context.Context, t *Table, instance Resources) error Exec(ctx context.Context, query string, args ...interface{}) error Delete(ctx context.Context, t *Table, kvFilters []interface{}) error Query(ctx context.Context, query string, args ...interface{}) (pgx.Rows, error) RemoveStaleData(ctx context.Context, t *Table, executionStart time.Time, kvFilters []interface{}) error CopyFrom(ctx context.Context, resources Resources, shouldCascade bool, CascadeDeleteFilters map[string]interface{}) error Close() }
type ExecutionData ¶
type ExecutionData struct { // ResourceName name of top-level resource associated with table ResourceName string // Table this execution is associated with Table *Table // Database connection to insert data into Db Database // Logger associated with this execution Logger hclog.Logger // PartialFetchFailureResult is a map of resources where the fetch process failed PartialFetchFailureResult []ResourceFetchError // contains filtered or unexported fields }
ExecutionData marks all the related execution info passed to TableResolver and ColumnResolver giving access to the Runner's meta
func NewExecutionData ¶
func NewExecutionData(db Database, logger hclog.Logger, table *Table, disableDelete bool, extraFields map[string]interface{}, partialFetch bool) ExecutionData
NewExecutionData Create a new execution data
func (*ExecutionData) ResolveTable ¶
func (e *ExecutionData) ResolveTable(ctx context.Context, meta ClientMeta, parent *Resource) (uint64, error)
func (*ExecutionData) WithTable ¶
func (e *ExecutionData) WithTable(t *Table) *ExecutionData
type IgnoreErrorFunc ¶
IgnoreErrorFunc checks if returned error from table resolver should be ignored.
type LengthTableValidator ¶ added in v0.2.0
type LengthTableValidator struct{}
func (LengthTableValidator) Validate ¶ added in v0.2.0
func (tv LengthTableValidator) Validate(t *Table) error
type PgDatabase ¶
type PgDatabase struct {
// contains filtered or unexported fields
}
func NewPgDatabase ¶
func NewPgDatabase(ctx context.Context, logger hclog.Logger, dsn string) (*PgDatabase, error)
func (PgDatabase) Close ¶ added in v0.4.0
func (p PgDatabase) Close()
func (PgDatabase) CopyFrom ¶ added in v0.3.0
func (p PgDatabase) CopyFrom(ctx context.Context, resources Resources, shouldCascade bool, cascadeDeleteFilters map[string]interface{}) error
CopyFrom copies all resources from []*Resource
func (PgDatabase) Delete ¶
func (p PgDatabase) Delete(ctx context.Context, t *Table, kvFilters []interface{}) error
func (PgDatabase) Exec ¶
func (p PgDatabase) Exec(ctx context.Context, query string, args ...interface{}) error
Exec allows executions of postgres queries with given args returning error of execution
func (PgDatabase) Insert ¶
Insert inserts all resources to given table, table and resources are assumed from same table.
func (PgDatabase) Query ¶
func (p PgDatabase) Query(ctx context.Context, query string, args ...interface{}) (pgx.Rows, error)
Query allows execution of postgres queries with given args returning data result
func (PgDatabase) QueryOne ¶
func (p PgDatabase) QueryOne(ctx context.Context, query string, args ...interface{}) pgx.Row
QueryOne allows execution of postgres queries with given args returning data result
func (PgDatabase) RemoveStaleData ¶ added in v0.4.7
type ResolverMeta ¶ added in v0.5.1
type Resource ¶
type Resource struct { // Original resource item that wa from prior resolve Item interface{} // Set if this is an embedded table Parent *Resource // contains filtered or unexported fields }
Resource 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
func NewResourceData ¶
func (*Resource) GenerateCQId ¶ added in v0.3.0
type ResourceFetchError ¶ added in v0.5.0
type ResourceFetchError struct { // table name of the failed resource fetch TableName string // root/parent table name RootTableName string // root/parent primary key values RootPrimaryKeyValues []string // error message for this resource fetch failure Err error }
ResourceFetchError represents a single partial fetch failed resource
func (ResourceFetchError) Error ¶ added in v0.5.0
func (p ResourceFetchError) Error() string
type Resources ¶ added in v0.3.0
type Resources []*Resource
func (Resources) ColumnNames ¶ added in v0.3.0
type RowResolver ¶
type RowResolver func(ctx context.Context, meta ClientMeta, resource *Resource) error
type Table ¶
type Table struct { // Name of table Name string // table description Description string // Columns are the set of fields that are part of this table Columns []Column // Relations are a set of related tables defines Relations []*Table // Resolver is the main entry point to fetching table data and Resolver TableResolver // Ignore errors checks if returned error from table resolver should be ignored. IgnoreError IgnoreErrorFunc // Multiplex returns re-purposed meta clients. The sdk will execute the table with each of them Multiplex func(meta ClientMeta) []ClientMeta // DeleteFilter returns a list of key/value pairs to add when truncating this table's data from the database. DeleteFilter func(meta ClientMeta, parent *Resource) []interface{} // Post resource resolver is called after all columns have been resolved, and before resource is inserted to database. PostResourceResolver RowResolver // Options allow modification of how the table is defined when created Options TableCreationOptions // AlwaysDelete will always delete table data on fetch regardless if delete is disabled on run, // use this only in specific cases, if you are unsure contact the CloudQuery Team. AlwaysDelete bool }
func (Table) ColumnNames ¶
ColumnNames returns all collected columns name of table (including all inner embedded columns)
func (Table) PrimaryKeys ¶ added in v0.3.0
type TableCreationOptions ¶ added in v0.3.0
type TableCreationOptions struct { // List of columns to set as primary keys, if HashPrimaryKeys is true the column values will be used to generate an ID // and an "id" column will be created for the table. If this nil a random unique ID is generated. PrimaryKeys []string }
TableCreationOptions allow modifying how table is created such as defining primary keys, indices, foreign keys and constraints.
type TableResolver ¶
type TableResolver func(ctx context.Context, meta ClientMeta, parent *Resource, res chan interface{}) error
TableResolver is the main entry point when a table fetch is called.
Table 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 interface{}): is a channel to pass results fetched by the TableResolver