db

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2026 License: MIT Imports: 12 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

DB node

Type: db
Category: Storage

Parameterized SQL query/exec on a neat DSN (sqlite/postgres/mysql/...).

Behavior

This node is registered as db and runs as part of a workflow. Its exact runtime behavior is implemented in node.go; this document summarizes the editor-facing purpose and configuration contract.

Configuration

Field Type Default Description
dsn string DSN — Neat-style database DSN (sqlite://file.db, postgres://user:pass@host/db, mysql://...). Bare paths and :memory: are treated as SQLite. "env:NAME" resolves the DSN from the scoped env chain. Credential: masked, stored outside the exported flow document
errorCatch boolean false Error Catch Port — Adds a dedicated "error" output port; a node failure emits msg.error={text,node,full} on it when wired, else the catch/problem-queue ladder applies
operation string query Operation
params string Params Field — Optional dotted msg field path resolving to a bind-args array (e.g. "params"); empty uses the message's params data field
readOnly boolean false Read Only — Reject exec operations at deploy time
split boolean false Split Rows — Query only: emit one message per result row instead of one array payload
sql string SQL — Statement with ? bind placeholders (rebound to the driver's native style — $n for postgres, @pn for sqlserver). Params bind; values are never interpolated into the SQL string

Implementation

  • node.go contains the executor, validation, schema, and registration.
  • editor.html contains the editor integration.
  • node_test.go, when present, contains behavioral tests.

Documentation

Overview

Package db contains the db node implementation.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DBConfig

type DBConfig struct {
	// DSN is a neat-style database DSN ("sqlite://file.db",
	// "postgres://user:pass@host/db", "mysql://user:pass@host/db").
	// Bare paths and ":memory:" are treated as SQLite DSNs.
	// "env:NAME" resolves the DSN from the scoped env chain.
	DSN string `json:"dsn"`
	// Operation is "query" (default) or "exec".
	Operation string `json:"operation"`
	// SQL is the statement with '?' bind placeholders (rebound to
	// the driver's native style). Values are never interpolated.
	SQL string `json:"sql"`
	// Params supplies bind values: a JSON array of literals, or a
	// string naming a dotted msg field path that resolves to an
	// array (e.g. "params", "payload.items", "msg.args"). Empty
	// falls back to an array at the message's "params" data field.
	Params interface{} `json:"params"`
	// Split emits one message per result row (query only).
	Split bool `json:"split"`
	// ReadOnly rejects exec operations at deploy time.
	ReadOnly bool `json:"readOnly"`
}

DBConfig holds the node.Data fields of a db node.

type DBNode

type DBNode struct {
	*nodebase.BaseNode
	// contains filtered or unexported fields
}

DBNode is the executor shell: Activate opens the pool, Execute runs one statement, Expand fans out rows in split mode, Stop closes.

func NewDBNode

func NewDBNode(node nodestore.NodeInterface, config *DBConfig, host nodebase.NodeHost) *DBNode

NewDBNode creates a new db node executor shell.

func (*DBNode) Activate

func (n *DBNode) Activate(ctx context.Context) error

Activate implements Activator: deploy opens the pooled connection and pings it, so an unparseable DSN or an unreachable database fails the deploy rather than the first message.

func (*DBNode) Execute

Execute runs the configured statement against the pool.

func (*DBNode) Expand

Expand implements MessageExpander: in split mode each result row becomes its own message (Data = the row object); an empty result set emits nothing. Non-split executions (and exec results) pass their single output through unchanged.

func (*DBNode) Stop

func (n *DBNode) Stop() error

Stop implements Stopper: closes the pooled handle. A subsequent Execute fails cleanly until the next Activate reopens it. Must not recreate host state — it may already be wiped.

func (*DBNode) StopKey

func (n *DBNode) StopKey() string

stopKey dedupes stopper registration: all executor shells of one node share the same pool.

func (*DBNode) Validate

func (n *DBNode) Validate() error

Validate checks config at deploy time: dsn and sql are required, operation must be known, readOnly rejects exec.

Jump to

Keyboard shortcuts

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