Help us shape the future of Go! Take the 2026 Go Developer Survey

sql

package
v0.4.14 Latest Latest
Warning

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

Go to latest
Published: Sep 16, 2026 License: MIT Imports: 22 Imported by: 10

Documentation

Index

Constants

View Source
const DbtSlug = "dbt"
View Source
const SqlConnectionSlug = "sql-connection"

Variables

This section is empty.

Functions

func CleanQuery added in v0.0.21

func CleanQuery(query string) string

func CreateTemplate

func CreateTemplate(
	ctx context.Context,
	subQueries map[string]string,
	ps map[string]interface{},
	db *sqlx.DB,
) *template.Template

func GetConnectionStringFromParsedLayers added in v0.1.40

func GetConnectionStringFromParsedLayers(parsedValues *values.Values) (string, error)

GetConnectionStringFromParsedLayers extracts a connection string from parsed values. This is useful for tools like River that need a connection string directly

func GetConnectionStringFromSqlConnectionLayer added in v0.1.40

func GetConnectionStringFromSqlConnectionLayer(
	parsedValues *values.Values,
	sqlConnectionLayerName string,
	dbtLayerName string,
) (string, error)

GetConnectionStringFromSqlConnectionLayer extracts a connection string from specific section names

func OpenDatabaseFromDefaultSqlConnectionLayer

func OpenDatabaseFromDefaultSqlConnectionLayer(
	ctx context.Context,
	parsedValues *values.Values,
) (*sqlx.DB, error)

func OpenDatabaseFromSqlConnectionLayer

func OpenDatabaseFromSqlConnectionLayer(
	ctx context.Context,
	parsedValues *values.Values,
	sqlConnectionLayerName string,
	dbtLayerName string,
) (*sqlx.DB, error)

func RenderQuery added in v0.0.28

func RenderQuery(
	ctx context.Context,
	db *sqlx.DB,
	query string,
	subQueries map[string]string,
	data map[string]interface{},
) (string, error)

func RunNamedQueryIntoGlaze

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

func RunQuery

func RunQuery(
	ctx context.Context,
	subQueries map[string]string,
	query string,
	ps2 map[string]interface{},
	db *sqlx.DB,
) (string, *sqlx.Rows, error)

func RunQueryIntoGlaze

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

Types

type DBConnectionFactory added in v0.1.0

type DBConnectionFactory func(ctx context.Context, parsedValues *values.Values) (*sqlx.DB, error)

type DatabaseConfig

type DatabaseConfig struct {
	Host            string `glazed:"host"`
	Database        string `glazed:"database"`
	User            string `glazed:"user"`
	Password        string `glazed:"password"` // #nosec G117 -- Password is part of the DB config model.
	Port            int    `glazed:"port"`
	Schema          string `glazed:"schema"`
	Type            string `glazed:"db-type"`
	DSN             string `glazed:"dsn"`
	Driver          string `glazed:"driver"`
	SSLDisable      bool   `glazed:"ssl-disable"`
	DbtProfilesPath string `glazed:"dbt-profiles-path"`
	DbtProfile      string `glazed:"dbt-profile"`
	UseDbtProfiles  bool   `glazed:"use-dbt-profiles"`
}

func NewConfigFromParsedLayers

func NewConfigFromParsedLayers(parsedSections ...*values.SectionValues) (*DatabaseConfig, error)

func NewConfigFromRawParsedLayers added in v0.1.32

func NewConfigFromRawParsedLayers(parsedValues *values.Values) (*DatabaseConfig, error)

func (*DatabaseConfig) Connect

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

func (*DatabaseConfig) GetConnectionString added in v0.1.40

func (c *DatabaseConfig) GetConnectionString() (string, error)

GetConnectionString returns the connection string for this database config

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

type DbtParameterLayer struct {
	schema.SectionImpl `yaml:",inline"`
}

func NewDbtParameterLayer

func NewDbtParameterLayer(
	options ...schema.SectionOption,
) (*DbtParameterLayer, error)

type DbtSettings added in v0.1.0

type DbtSettings struct {
	DbtProfilesPath string `glazed:"dbt-profiles-path"`
	UseDbtProfiles  bool   `glazed:"use-dbt-profiles"`
	DbtProfile      string `glazed:"dbt-profile"`
}

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"` // #nosec G117 -- This struct intentionally models database credentials.
	Schema     string `yaml:"schema"`
	Database   string `yaml:"database"`
	SSLDisable bool   `yaml:"ssl_disable"`
}

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 SqlConnectionParameterLayer added in v0.1.0

type SqlConnectionParameterLayer struct {
	schema.SectionImpl `yaml:",inline"`
}

func NewSqlConnectionParameterLayer

func NewSqlConnectionParameterLayer(
	options ...schema.SectionOption,
) (*SqlConnectionParameterLayer, error)

type SqlConnectionSettings added in v0.1.0

type SqlConnectionSettings struct {
	Host       string `glazed:"host"`
	Port       int    `glazed:"port"`
	Database   string `glazed:"database"`
	User       string `glazed:"user"`
	Password   string `glazed:"password"` // #nosec G117 -- Password is a required connection setting.
	Schema     string `glazed:"schema"`
	DbType     string `glazed:"db-type"`
	Repository string `glazed:"repository"`
	Dsn        string `glazed:"dsn"`
	Driver     string `glazed:"driver"`
	SSLDisable bool   `glazed:"ssl-disable"`
}

Jump to

Keyboard shortcuts

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