examples/

directory
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Dec 5, 2026 License: Apache-2.0

README

ScopeDB Go SDK examples

Run these examples from the repository root. They use only the public SDK API.

Query and catalog examples

Example Shows Run
statement Run a query and read its results go run ./examples/statement
catalog Read a schema definition and list its tables go run ./examples/catalog

The shared helper reads:

  • SCOPEDB_ENDPOINT (defaults to http://127.0.0.1:6543)
  • SCOPEDB_API_KEY (falls back to SCOPEDB_TOKEN)
  • SCOPEDB_DATABASE (defaults to scopedb)
  • SCOPEDB_SCHEMA (defaults to public)

ScopeQL is documented in the quickstart, query guide, and language reference.

Before running a write example

Set SCOPEDB_WRITE_TABLE to an existing table name. Configure its database and schema with SCOPEDB_DATABASE and SCOPEDB_SCHEMA:

export SCOPEDB_WRITE_TABLE=sdk_example_events

The write examples use these columns:

Column Value used by examples
id integer
event_id string
occurred_at timestamp
name string
attributes object

Choose a write example

Start with append_stream to write Go structs. The SDK encodes and batches the rows for you.

Example Choose it when Run
append_stream Write Go structs with an append stream go run ./examples/append_stream
bulk_append Import an NDJSON file with bounded memory go run ./examples/patterns/bulk_append < events.ndjson
telemetry Write logs or events with TrySend and continue after write errors go run ./examples/patterns/telemetry
append_ndjson Write one already encoded NDJSON request go run ./examples/append_ndjson

For stream admission, delivery reports, and retries, see the usage guide and write contracts.

Import an NDJSON file

The bulk_append example reads standard input one line at a time, skips blank lines, and passes JSON objects to Send without converting numbers through float64. Each input line must fit within 8 MiB, including its line ending. A file for the example table can contain:

{"id":1,"event_id":"import-1","occurred_at":"2026-10-23T00:00:00Z","name":"checkout.completed","attributes":{"store":"north"}}
{"id":2,"event_id":"import-2","occurred_at":"2026-10-23T00:00:01Z","name":"checkout.completed","attributes":{"store":"south"}}

Run go run ./examples/patterns/bulk_append < events.ndjson. The stream applies backpressure as its queue fills and Shutdown waits for accepted rows to settle. On an input or write error, the example reports the error and the delivery counts before exiting with a nonzero status.

Some rows may commit before an import fails. This example disables automatic retries; reconcile an incomplete import before rerunning the file, since replaying it can duplicate rows. Transform input before admission when it does not match the destination columns.

Compile every example

go build ./examples/...

Directories

Path Synopsis
Package main demonstrates one caller-encoded raw NDJSON table append.
Package main demonstrates one caller-encoded raw NDJSON table append.
Package main demonstrates strict bounded asynchronous table appends.
Package main demonstrates strict bounded asynchronous table appends.
Package main demonstrates declarative catalog discovery.
Package main demonstrates declarative catalog discovery.
internal
exampleutil
Package exampleutil contains configuration shared by the runnable examples.
Package exampleutil contains configuration shared by the runnable examples.
patterns
bulk_append command
Package main imports NDJSON from standard input with bounded streaming writes.
Package main imports NDJSON from standard input with bounded streaming writes.
telemetry command
Package main demonstrates observable best-effort telemetry delivery.
Package main demonstrates observable best-effort telemetry delivery.
Package main demonstrates synchronous and asynchronous statement queries.
Package main demonstrates synchronous and asynchronous statement queries.

Jump to

Keyboard shortcuts

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