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

sqlquery

package
v0.329.0 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2026 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsDestructiveQuery

func IsDestructiveQuery(query string) bool

IsDestructiveQuery reports whether the query deletes or drops resources. This is a best-effort guardrail for agents, not a SQL parser. Statements led by DELETE, DROP, or TRUNCATE (including after CTEs) require approval.

Types

type DestructiveQueryError

type DestructiveQueryError struct{}

DestructiveQueryError is returned when a query would delete or drop data or schema objects and --force was not passed.

func (*DestructiveQueryError) Error

func (e *DestructiveQueryError) Error() string

type Options

type Options struct {
	Organization string
	Database     string
	Branch       string
	Query        string
	// Keyspace is the Vitess keyspace for MySQL. Optional; defaults to @primary (same as pscale shell).
	Keyspace string
	// PostgresDB is the PostgreSQL database name. Defaults to postgres.
	PostgresDB string
	// PostgresAdditionalRoles adds built-in roles to the ephemeral credential.
	PostgresAdditionalRoles []string
	// Role is reader, writer, readwriter, or admin (same as pscale shell --role).
	Role string
	// Replica routes reads to replicas when true (same as pscale shell --replica).
	Replica bool
	// Force allows destructive SQL (DELETE, DROP, TRUNCATE) after explicit user approval.
	Force bool
}

Options selects the branch and SQL to execute.

type Result

type Result struct {
	Status       string           `json:"status"`
	Database     string           `json:"database"`
	Branch       string           `json:"branch"`
	Kind         string           `json:"kind"`
	Role         string           `json:"role,omitempty"`
	Replica      bool             `json:"replica,omitempty"`
	RowCount     int              `json:"row_count"`
	RowsAffected int64            `json:"rows_affected,omitempty"`
	Columns      []string         `json:"columns,omitempty"`
	Rows         []map[string]any `json:"rows,omitempty"`
	NextSteps    []string         `json:"next_steps,omitempty"`
}

Result is returned for `pscale sql --format json`.

func Execute

func Execute(ctx context.Context, ch *cmdutil.Helper, opts Options) (*Result, error)

Execute runs SQL against MySQL or PostgreSQL using ephemeral credentials.

type Session added in v0.307.0

type Session struct {
	// Kind is the database kind as reported by the API: "mysql",
	// "postgresql", or "horizon".
	Kind string
	// contains filtered or unexported fields
}

Session is an open connection to a database branch using ephemeral credentials. Unlike Execute, which opens and tears down a connection per query, a Session lets callers run several queries (e.g. a suite of diagnostic checks) over a single connection. Close must be called to release the connection and clean up the ephemeral credentials.

func NewSession added in v0.307.0

func NewSession(ctx context.Context, ch *cmdutil.Helper, opts Options) (*Session, error)

NewSession validates the options, looks up the database and branch, and opens a connection with ephemeral credentials (a branch password for MySQL, a temporary role for PostgreSQL).

func (*Session) Close added in v0.307.0

func (s *Session) Close()

Close releases the connection and cleans up the ephemeral credentials.

func (*Session) Engine added in v0.307.0

func (s *Session) Engine() string

Engine normalizes Kind to "mysql" or "postgresql".

func (*Session) Query added in v0.307.0

func (s *Session) Query(ctx context.Context, query string) ([]string, []map[string]any, error)

Query runs a single query over the session's connection and returns the column names (in result order) and rows.

Jump to

Keyboard shortcuts

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