pkg

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2023 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func OpenDatabaseFromViper

func OpenDatabaseFromViper() (*sqlx.DB, error)

func RunNamedQueryIntoGlaze

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

func RunQueryIntoGlaze

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

Types

type DatabaseConfig

type DatabaseConfig struct {
	Host            string
	Database        string
	User            string
	Password        string
	Port            int
	Schema          string
	Type            string
	DSN             string
	Driver          string
	DbtProfilesPath string
	DbtProfile      string
	UseDbtProfiles  bool
}

func NewDatabaseConfigFromViper

func NewDatabaseConfigFromViper() *DatabaseConfig

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 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
	// contains filtered or unexported fields
}

SqlCommand describes a command line command that runs a query

func NewSqlCommand

func NewSqlCommand(description *cmds.CommandDescription, query string) *SqlCommand

func (*SqlCommand) BuildCobraCommand

func (s *SqlCommand) BuildCobraCommand() (*cobra.Command, error)

func (*SqlCommand) Description

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

func (*SqlCommand) IsValid

func (sc *SqlCommand) IsValid() bool

func (*SqlCommand) RenderQuery

func (s *SqlCommand) RenderQuery(parameters map[string]interface{}) (string, error)

func (*SqlCommand) Run

func (s *SqlCommand) Run(map[string]interface{}, *cmds.GlazeProcessor) error

func (*SqlCommand) RunFromCobra

func (s *SqlCommand) RunFromCobra(cmd *cobra.Command, args []string) error

RunFromCobra actually runs the given SqletonCommand by using the cobra command to parse the necessary flags. It then first pings the database, and then renders the query results into a GlazedProcessor.

func (*SqlCommand) RunQueryIntoGlaze

func (s *SqlCommand) RunQueryIntoGlaze(
	ctx context.Context,
	db *sqlx.DB,
	parameters map[string]interface{},
	gp *cmds.GlazeProcessor) 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"`
	Flags     []*cmds.ParameterDefinition `yaml:"flags,omitempty"`
	Arguments []*cmds.ParameterDefinition `yaml:"arguments,omitempty"`

	Query string `yaml:"query"`
}

type SqlCommandLoader

type SqlCommandLoader struct {
}

func (*SqlCommandLoader) LoadCommandAliasFromYAML

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

func (*SqlCommandLoader) LoadCommandFromYAML

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

type SqletonCommand

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

Jump to

Keyboard shortcuts

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