Documentation ¶
Index ¶
- func GetPgTypeFromType(v ValueType) string
- func ParentIdResolver(_ context.Context, _ ClientMeta, r *Resource, c Column) error
- type ClientMeta
- type Column
- type ColumnCreationOptions
- type ColumnResolver
- type Database
- type ExecutionData
- type IgnoreErrorFunc
- type PgDatabase
- func (p PgDatabase) Delete(ctx context.Context, t *Table, args []interface{}) error
- func (p PgDatabase) Exec(ctx context.Context, query string, args ...interface{}) error
- func (p PgDatabase) Insert(ctx context.Context, t *Table, resources []*Resource) 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
- type Resource
- type RowResolver
- type Table
- type TableResolver
- type ValueType
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetPgTypeFromType ¶
func ParentIdResolver ¶
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 // Creation options allow to modify how column is defined when table is created CreationOptions ColumnCreationOptions }
Column definition for Table
func (Column) ValidateType ¶
type ColumnCreationOptions ¶
ColumnCreationOptions allow to modify how column is defined when table is created
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 bieng called. resource holds the current row we are resolving the column for.
func PathResolver ¶
func PathResolver(path string) ColumnResolver
type Database ¶
type Database interface { Insert(ctx context.Context, t *Table, instance []*Resource) error Exec(ctx context.Context, query string, args ...interface{}) error Delete(ctx context.Context, t *Table, args []interface{}) error Query(ctx context.Context, query string, args ...interface{}) (pgx.Rows, error) }
type ExecutionData ¶
type ExecutionData struct { // The table this execution is associated with Table *Table // Database connection to insert data into Db Database // Logger associated with this execution Logger hclog.Logger // Column is set if execution is passed to ColumnResolver Column *Column }
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) ExecutionData
NewExecutionData Create a new execution data
func (ExecutionData) ResolveTable ¶
func (e ExecutionData) ResolveTable(ctx context.Context, meta ClientMeta, parent *Resource) 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 PgDatabase ¶
type PgDatabase struct {
// contains filtered or unexported fields
}
func NewPgDatabase ¶
func NewPgDatabase(dsn string) (*PgDatabase, error)
func (PgDatabase) Delete ¶
func (p PgDatabase) Delete(ctx context.Context, t *Table, args []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.
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 ¶
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) []interface{} // Post resource resolver is called after all columns have been resolved, and before resource is inserted to database. PostResourceResolver RowResolver }
func (Table) ColumnNames ¶
ColumnNames returns all collected columns name of table (including all inner embedded columns)
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