sql

package
v1.15.1 Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

README

Sql Lookup Plugin

The sql lookup plugin performs SQL query for reading lookup data. This plugin is based on jmoiron/sqlx package. See drivers list here.

A few words about plugin modes.

In horizontal mode plugin stores query result as a list of maps. For example, if your query returns table like this:

role description
admin Full access
user Just user

The lookup data will be:

[
  {"role": "admin", "description": "Full access"},
  {"role": "user",  "description": "Just user"},
]

More classic case, vertical, takes key_column column as a map key:

param_name value description
currency USDT Main currency
fee_percent 2 Transfer fee

And transforms query result into map of maps:

{
  "currency":    {"value": "USDT", "description": "Main currency"},
  "fee_percent": {"value": "2",    "description": "Transfer fee"}
}

Configuration

[[lookups]]
  [lookups.sql]
    alias = "transfers.settings"

    # lookup update interval
    # if zero, plugin executes onUpdate query only on pipeline startup
    interval = "30s"

    # SQL driver, must be on of: "pgx", "mysql", "sqlserver", "oracle", "clickhouse"
    driver = "pgx"

    # datasource service name in selected driver format
    dsn = "postgres://localhost:5432/postgres"

    # authentication credentials
    # if both not empty, takes precedence over ones provided in DSN
    username = ""
    password = ""

    # queries execution timeout
    query_timeout = "30s"

    # plugin mode, "vertical" or "horizontal"
    mode = "vertical"

    # column name which value will be used as a lookup map key
    # used and required only in "vertical" mode
    key_column = "param_name"

    # database connection params - https://pkg.go.dev/database/sql#DB.SetConnMaxIdleTime
    conns_max_idle_time = "10m"
    conns_max_life_time = "10m"
    conns_max_open = 2
    conns_max_idle = 1

    ## TLS configuration
    # if true, TLS client will be used
    tls_enable = false
    # trusted root certificates for server
    tls_ca_file = "/etc/neptunus/ca.pem"
    # used for TLS client certificate authentication
    tls_key_file = "/etc/neptunus/key.pem"
    tls_cert_file = "/etc/neptunus/cert.pem"
    # minimum TLS version, not limited by default
    tls_min_version = "TLS12"
    # send the specified TLS server name via SNI
    tls_server_name = "exmple.svc.local"
    # use TLS but skip chain & host verification
    tls_insecure_skip_verify = false

    # lookup data query
    # # if both, "file" and "query" are set, file is prioritized
    [lookups.sql.on_update]
      file = "settings.sql"
      query = '''
SELECT * FROM SETTINGS_TABLE;
      '''

Documentation

Index

Constants

View Source
const (
	ModeHorizontal = "horizontal"
	ModeVertical   = "vertical"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Sql

type Sql struct {
	*core.BaseLookup `mapstructure:"-"`
	*csql.Connector  `mapstructure:",squash"`
	OnUpdate         csql.QueryInfo `mapstructure:"on_update"`
	Mode             string         `mapstructure:"mode"`
	KeyColumn        string         `mapstructure:"key_column"`
	// contains filtered or unexported fields
}

func (*Sql) Close

func (l *Sql) Close() error

func (*Sql) Init

func (l *Sql) Init() error

func (*Sql) Update

func (l *Sql) Update() (any, error)

Jump to

Keyboard shortcuts

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