Documentation
¶
Overview ¶
Package natsql provides the top-level public API for the natsql materialized view engine.
This is the root package facade (D-46) that library consumers import. Three constructors are provided (D-47):
- New() — caller-owned JetStream context
- NewWithNATS() — caller-provided NATS connection (facade owns nc.Close())
- NewEmbedded() — embedded NATS server (facade owns shutdown)
Basic usage for Go library consumers:
import "github.com/gacopys/natsql"
eng, err := natsql.New(js, cfg, natsql.WithLogger(logger))
if err != nil { ... }
defer eng.Close()
eng.Start(ctx)
result := eng.Query(ctx, "SELECT * FROM users WHERE id = 'abc'")
Index ¶
Constants ¶
const ( ColumnTypeString = cfg.ColumnTypeString ColumnTypeNumber = cfg.ColumnTypeNumber ColumnTypeBoolean = cfg.ColumnTypeBoolean ColumnTypeTimestamp = cfg.ColumnTypeTimestamp )
Column type constants.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ColumnConfig ¶
type ColumnConfig = cfg.ColumnConfig
Config types re-exported from the cfg sub-package. This split breaks the import cycle between the root natsql package (which imports engine) and engine (which imports config types).
type ColumnType ¶
type ColumnType = cfg.ColumnType
Config types re-exported from the cfg sub-package. This split breaks the import cycle between the root natsql package (which imports engine) and engine (which imports config types).
type Config ¶
Config types re-exported from the cfg sub-package. This split breaks the import cycle between the root natsql package (which imports engine) and engine (which imports config types).
func LoadConfig ¶
LoadConfig reads a YAML or JSON config file and returns the parsed Config.
type ConsumerConfig ¶
type ConsumerConfig = cfg.ConsumerConfig
Config types re-exported from the cfg sub-package. This split breaks the import cycle between the root natsql package (which imports engine) and engine (which imports config types).
type Engine ¶
Engine wraps the internal engine with lifecycle ownership (D-48). Create via New, NewWithNATS, or NewEmbedded.
Methods from the underlying engine.Engine (Query, Start, Close, Stats) are accessible directly on this type through embedding.
func New ¶
New creates an Engine from a caller-owned JetStream context (D-47). The caller is responsible for closing the NATS connection and JetStream context. Use this when embedding natsql in an existing NATS application.
The config must be non-nil; Config.SetDefaults() and Config.Validate() are called automatically.
func NewEmbedded ¶
NewEmbedded creates an Engine with an embedded NATS server (D-47, D-48). This is the zero-infrastructure deployment mode — no external NATS required. The engine starts an embedded NATS JetStream server, connects to it, and owns the server lifecycle (shutdown on Close()).
The config path can specify cfg.NATS.StoreDir for persistent storage. Config.SetDefaults() and Config.Validate() are called automatically.
func NewWithNATS ¶
NewWithNATS creates an Engine from a NATS connection (D-47, D-48). The engine creates a JetStream context from the connection and owns nc.Close() — the caller should not call nc.Close() after passing it here.
The config must be non-nil; Config.SetDefaults() and Config.Validate() are called automatically.
func (*Engine) Close ¶
Close gracefully shuts down the engine and owned resources (D-48). Closes the internal engine first (stops materializers, HTTP, etc.), then shuts down embedded NATS if started by this facade, and finally closes the owned NATS connection.
Safe to call multiple times — subsequent calls are no-ops.
type HTTPConfig ¶
type HTTPConfig = cfg.HTTPConfig
Config types re-exported from the cfg sub-package. This split breaks the import cycle between the root natsql package (which imports engine) and engine (which imports config types).
type IndexConfig ¶
type IndexConfig = cfg.IndexConfig
Config types re-exported from the cfg sub-package. This split breaks the import cycle between the root natsql package (which imports engine) and engine (which imports config types).
type NATSConfig ¶
type NATSConfig = cfg.NATSConfig
Config types re-exported from the cfg sub-package. This split breaks the import cycle between the root natsql package (which imports engine) and engine (which imports config types).
type Option ¶
Option configures the Engine.
func WithHTTPServer ¶
WithHTTPServer parses an address string ("host:port") and sets the HTTP server port. If addr is empty, no action is taken.
func WithLogger ¶
WithLogger sets the logger for the engine and materializers.
func WithQueryPort ¶
WithQueryPort directly sets the HTTP query server port.
type QueryResult ¶
type QueryResult = query.QueryResult
--------------------------------------------------------------------------- QueryResult is the response envelope returned by Engine.Query.
type ViewConfig ¶
type ViewConfig = cfg.ViewConfig
Config types re-exported from the cfg sub-package. This split breaks the import cycle between the root natsql package (which imports engine) and engine (which imports config types).
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
natsql
command
Command natsql is the standalone binary for the NATS-native materialized view engine.
|
Command natsql is the standalone binary for the NATS-native materialized view engine. |
|
internal
|
|
|
cfg
Package cfg provides the configuration types for natsql.
|
Package cfg provides the configuration types for natsql. |
|
embed
Package embed starts and supervises a single NATS JetStream server in-process.
|
Package embed starts and supervises a single NATS JetStream server in-process. |
|
engine
Package engine provides the top-level Engine that manages materialized view lifecycles.
|
Package engine provides the top-level Engine that manages materialized view lifecycles. |
|
query
Package query provides the SQL query engine for natsql.
|
Package query provides the SQL query engine for natsql. |
|
transport
Package transport provides NATS request-reply and HTTP handlers for executing SQL queries against the engine.
|
Package transport provides NATS request-reply and HTTP handlers for executing SQL queries against the engine. |