sqlproxy

package
v0.55.0 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2026 License: Apache-2.0 Imports: 26 Imported by: 0

Documentation

Overview

Package sqlproxy implements the proxy executing read-only queries against the SQL datasources (datasource proxy kind "SQLProxy").

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Proxy

type Proxy struct {
	// Config is the SQL proxy configuration of the datasource (driver, host, database...). It is required.
	Config *datasourceSQL.Config
	// Secret contains the credentials and the TLS config used to reach the database. It must already be decrypted.
	// It can be nil.
	Secret *v1.SecretSpec
	// Name is the name of the datasource, used in the logs.
	Name string
	// Project is the project of the datasource, used in the logs. Empty for a global datasource.
	Project string
	// Path is the path of the request, only used in the error messages.
	Path string
	// Guard verifies every connection made to the database. It is required.
	Guard *netguard.Guard
	// contains filtered or unexported fields
}

Proxy executes a read-only SQL query against a datasource (datasource proxy kind "SQLProxy"). It must be built with New, once per request to serve.

The query is checked to start with a read statement, then executed in a read-only transaction. Every connection to the database is verified by the Guard.

func New

func New(p Proxy) (*Proxy, error)

New returns the Proxy described by p, once verified it holds the settings required to serve requests safely: the config of the datasource and the Guard.

func (*Proxy) Serve

func (s *Proxy) Serve(c echo.Context) error

Serve executes the SQL query sent in the body of the request of c (a POST request, see sqlQuery), and writes its result to c as JSON (see SQLResponse).

type SQLColumnMetadata

type SQLColumnMetadata struct {
	Name string `json:"name"`
	Type string `json:"type"`
}

SQLColumnMetadata represents metadata for a single column in SQL result

type SQLResponse

type SQLResponse struct {
	Columns []SQLColumnMetadata `json:"columns"`
	Rows    []SQLRow            `json:"rows"`
}

SQLResponse represents the complete SQL query response

type SQLRow

type SQLRow map[string]any

SQLRow represents a single row in an SQL result with column name to value mapping

Jump to

Keyboard shortcuts

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