pkg

package
v0.1.36 Latest Latest
Warning

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

Go to latest
Published: Apr 21, 2023 License: MIT Imports: 26 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewSqlHelpersParameterLayer added in v0.1.5

func NewSqlHelpersParameterLayer() (*layers.ParameterLayerImpl, error)

func OpenDatabaseFromSqletonConnectionLayer added in v0.1.8

func OpenDatabaseFromSqletonConnectionLayer(parsedLayers map[string]*layers.ParsedParameterLayer) (*sqlx.DB, error)

func RunNamedQueryIntoGlaze

func RunNamedQueryIntoGlaze(
	dbContext context.Context,
	db *sqlx.DB,
	query string,
	parameters map[string]interface{},
	gp cmds.Processor) error

func RunQueryIntoGlaze

func RunQueryIntoGlaze(
	dbContext context.Context,
	db *sqlx.DB,
	query string,
	parameters []interface{},
	gp cmds.Processor) error

Types

type ConnectionParameterLayer added in v0.1.5

type ConnectionParameterLayer struct {
	layers.ParameterLayerImpl
}

func NewSqlConnectionParameterLayer added in v0.1.5

func NewSqlConnectionParameterLayer(
	options ...layers.ParameterLayerOptions,
) (*ConnectionParameterLayer, error)

func (*ConnectionParameterLayer) ParseFlagsFromCobraCommand added in v0.1.5

func (cp *ConnectionParameterLayer) ParseFlagsFromCobraCommand(cmd *cobra.Command) (map[string]interface{}, error)

type DBConnectionFactory added in v0.1.5

type DBConnectionFactory func(parsedLayers map[string]*layers.ParsedParameterLayer) (*sqlx.DB, error)

type DatabaseConfig

type DatabaseConfig struct {
	Host            string `glazed.parameter:"host"`
	Database        string `glazed.parameter:"database"`
	User            string `glazed.parameter:"user"`
	Password        string `glazed.parameter:"password"`
	Port            int    `glazed.parameter:"port"`
	Schema          string `glazed.parameter:"schema"`
	Type            string `glazed.parameter:"db-type"`
	DSN             string `glazed.parameter:"dsn"`
	Driver          string `glazed.parameter:"driver"`
	DbtProfilesPath string `glazed.parameter:"dbt-profiles-path"`
	DbtProfile      string `glazed.parameter:"dbt-profile"`
	UseDbtProfiles  bool   `glazed.parameter:"use-dbt-profiles"`
}

func NewConfigFromParsedLayers added in v0.1.8

func NewConfigFromParsedLayers(parsedLayers map[string]*layers.ParsedParameterLayer) (*DatabaseConfig, error)

func (*DatabaseConfig) Connect

func (c *DatabaseConfig) Connect() (*sqlx.DB, error)

func (*DatabaseConfig) GetSource

func (c *DatabaseConfig) GetSource() (*Source, error)

func (*DatabaseConfig) LogVerbose

func (c *DatabaseConfig) LogVerbose()

LogVerbose just outputs information about the database config to the debug logging level.

func (*DatabaseConfig) ToString

func (c *DatabaseConfig) ToString() string

type DbtParameterLayer added in v0.1.5

type DbtParameterLayer struct {
	layers.ParameterLayerImpl
}

func NewDbtParameterLayer added in v0.1.5

func NewDbtParameterLayer() (*DbtParameterLayer, error)

func (*DbtParameterLayer) ParseFlagsFromCobraCommand added in v0.1.5

func (d *DbtParameterLayer) ParseFlagsFromCobraCommand(cmd *cobra.Command) (map[string]interface{}, error)

type Source

type Source struct {
	Name     string
	Type     string `yaml:"type"`
	Hostname string `yaml:"server"`
	Port     int    `yaml:"port"`
	Username string `yaml:"username"`
	Password string `yaml:"password"`
	Schema   string `yaml:"schema"`
	Database string `yaml:"database"`
}

Source is the generic structure we use to represent a database connection string

func ParseDbtProfiles

func ParseDbtProfiles(profilesPath string) ([]*Source, error)

ParseDbtProfiles parses a dbt profiles.yml file and returns a map of sources

func (*Source) ToConnectionString

func (s *Source) ToConnectionString() string

type SqlCommand

type SqlCommand struct {
	Query      string
	SubQueries map[string]string
	// contains filtered or unexported fields
}

SqlCommand describes a command line command that runs a query

func NewSqlCommand

func NewSqlCommand(
	description *cmds.CommandDescription,
	options ...SqlCommandOption,
) (*SqlCommand, error)

func (*SqlCommand) Description

func (s *SqlCommand) Description() *cmds.CommandDescription

func (*SqlCommand) IsValid

func (s *SqlCommand) IsValid() bool

func (*SqlCommand) RenderQuery

func (s *SqlCommand) RenderQuery(
	ctx context.Context,
	ps map[string]interface{},
	db *sqlx.DB,
) (string, error)

func (*SqlCommand) Run

func (s *SqlCommand) Run(
	ctx context.Context,
	parsedLayers map[string]*layers.ParsedParameterLayer,
	ps map[string]interface{},
	gp cmds.Processor,
) error

func (*SqlCommand) RunQueryIntoGlaze

func (s *SqlCommand) RunQueryIntoGlaze(
	ctx context.Context,
	db *sqlx.DB,
	ps map[string]interface{},
	gp cmds.Processor) error

func (*SqlCommand) String

func (s *SqlCommand) String() string

type SqlCommandDescription

type SqlCommandDescription struct {
	Name      string                            `yaml:"name"`
	Short     string                            `yaml:"short"`
	Long      string                            `yaml:"long,omitempty"`
	Layout    []*layout.Section                 `yaml:"layout,omitempty"`
	Flags     []*parameters.ParameterDefinition `yaml:"flags,omitempty"`
	Arguments []*parameters.ParameterDefinition `yaml:"arguments,omitempty"`
	Layers    []layers.ParameterLayer           `yaml:"layers,omitempty"`

	SubQueries map[string]string `yaml:"subqueries,omitempty"`
	Query      string            `yaml:"query"`
}

type SqlCommandLoader

type SqlCommandLoader struct {
	DBConnectionFactory DBConnectionFactory
}

func (*SqlCommandLoader) LoadCommandAliasFromYAML

func (scl *SqlCommandLoader) LoadCommandAliasFromYAML(s io.Reader, options ...alias.Option) ([]*alias.CommandAlias, error)

func (*SqlCommandLoader) LoadCommandFromYAML

func (scl *SqlCommandLoader) LoadCommandFromYAML(
	s io.Reader,
	options ...cmds.CommandDescriptionOption,
) ([]cmds.Command, error)

type SqlCommandOption added in v0.1.31

type SqlCommandOption func(*SqlCommand)

func WithDbConnectionFactory added in v0.1.31

func WithDbConnectionFactory(factory DBConnectionFactory) SqlCommandOption

func WithQuery added in v0.1.31

func WithQuery(query string) SqlCommandOption

func WithSubQueries added in v0.1.31

func WithSubQueries(subQueries map[string]string) SqlCommandOption

type SqletonCommand

type SqletonCommand interface {
	cmds.GlazeCommand
	RunQueryIntoGlaze(
		ctx context.Context,
		db *sqlx.DB,
		parameters map[string]interface{},
		gp cmds.Processor,
	) error
	RenderQuery(parameters map[string]interface{}) (string, error)
}

func LoadSqletonCommandFromYAML added in v0.1.15

func LoadSqletonCommandFromYAML(
	s io.Reader,
	factory DBConnectionFactory,
	options ...cmds.CommandDescriptionOption) (SqletonCommand, error)

Jump to

Keyboard shortcuts

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