sqlchan

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Jun 28, 2026 License: GPL-3.0 Imports: 18 Imported by: 0

Documentation

Overview

Package sqlchan is Bindle's SQL channel to an IBM i host: run SQL and read structured results, alongside the SSH/CL transport.

The MVP backend drives the open-source db2util (PASE, installable via yum and present on pub400) over the existing SSH transport: it runs DDL/DML and returns query result sets as JSON. The Conn interface keeps room for a mapepire backend later without touching callers (e.g. migrations).

Index

Constants

View Source
const ControlTable = "BINDLE_MIGRATIONS"

ControlTable is the per-schema table tracking applied migrations.

View Source
const DefaultDb2util = "/QOpenSys/pkgs/bin/db2util"

DefaultDb2util is the usual PASE path of db2util.

Variables

This section is empty.

Functions

This section is empty.

Types

type ChecksumMismatchError

type ChecksumMismatchError struct {
	ID, Was, Now string
}

ChecksumMismatchError means an already-applied migration's file changed — published migrations must be immutable.

func (*ChecksumMismatchError) Error

func (e *ChecksumMismatchError) Error() string

type Conn

type Conn interface {
	// Exec runs a statement with no result set (DDL/DML).
	Exec(stmt string) error
	// Query runs a statement and returns its rows.
	Query(stmt string) ([]Row, error)
}

Conn runs SQL against an IBM i host.

type Db2util

type Db2util struct {
	// contains filtered or unexported fields
}

Db2util is a Conn backed by the db2util CLI over SSH.

func NewDb2util

func NewDb2util(h Host, bin string) *Db2util

NewDb2util returns a db2util-backed connection. An empty bin uses the default path.

func (*Db2util) Exec

func (d *Db2util) Exec(stmt string) error

Exec runs a statement and discards any output.

func (*Db2util) Query

func (d *Db2util) Query(stmt string) ([]Row, error)

Query runs a statement and parses db2util's JSON result.

type Host

type Host interface {
	Run(cmd string) (transport.Result, error)
}

Host is the slice of the SSH transport sqlchan needs.

type Mapepire

type Mapepire struct {
	// contains filtered or unexported fields
}

Mapepire is a Conn backed by the mapepire-server WebSocket protocol.

func DialMapepire

func DialMapepire(ctx context.Context, opts MapepireOptions) (*Mapepire, error)

DialMapepire opens a mapepire connection over the tunnel.

func (*Mapepire) Close

func (m *Mapepire) Close() error

Close ends the WebSocket connection.

func (*Mapepire) Exec

func (m *Mapepire) Exec(stmt string) error

Exec runs a statement and discards rows.

func (*Mapepire) Query

func (m *Mapepire) Query(stmt string) ([]Row, error)

Query runs a statement and returns its rows.

func (*Mapepire) SetSchema

func (m *Mapepire) SetSchema(schema string) error

SetSchema sets the connection's current schema so unqualified object names in migrations resolve there. mapepire defaults to *SQL naming (schema = user), so this is required for migrations targeting another library.

type MapepireOptions

type MapepireOptions struct {
	Tunnel   Tunnel // how to reach the daemon (SSH direct-tcpip)
	Host     string // host name as the daemon sees it (default "localhost")
	Port     int    // daemon port (default 8076)
	User     string
	Password string
	Insecure bool          // accept the daemon's self-signed cert (default true)
	Timeout  time.Duration // per-request timeout (default 30s)
}

MapepireOptions configures a mapepire connection.

type Migration

type Migration struct {
	ID       string // filename without extension, e.g. "0001_init"
	Path     string
	Checksum string // sha256 hex of the file contents
}

Migration is one versioned DDL/DML file.

func LoadMigrations

func LoadMigrations(dir string) ([]Migration, error)

LoadMigrations reads *.sql files from dir, sorted lexicographically by name.

type MigrationResult

type MigrationResult struct {
	Applied []string // ids applied this run, in order
	Skipped []string // ids already applied
}

MigrationResult records what Migrate did.

func Migrate

func Migrate(conn Conn, schema, dir string, logf func(string, ...any)) (*MigrationResult, error)

Migrate applies pending migrations in order against the schema. It is idempotent (re-running applies nothing), ordered, and checksum-guarded.

type Row

type Row map[string]any

Row is one result row: column name -> value.

type SQLError

type SQLError struct {
	Stmt   string
	Detail string
}

SQLError is a statement that failed on the host.

func (*SQLError) Error

func (e *SQLError) Error() string

type Tunnel

type Tunnel interface {
	DialTunnel(addr string) (net.Conn, error)
}

Tunnel opens a TCP connection to an address as seen from the IBM i host (satisfied by transport.SSH.DialTunnel). mapepire usually binds localhost, so it is reached through the SSH connection rather than a public port.

Jump to

Keyboard shortcuts

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