Skip to content

Go SDK Reference

The Triggerware Go SDK is available on GitHub:

go get github.com/triggerware/go-client

Connect to a local Triggerware instance over TCP:

import tw "github.com/triggerware/triggerware-go"
client, err := tw.ConnectTCP("localhost:5221")
if err != nil {
log.Fatal(err)
}
defer client.Close()

After connecting, you can set defaults that apply to All subsequent queries:

FieldTypeDescriptionDefault
DefaultFetchSize*intMax rows per batch fetchnil (no limit)
DefaultTimeout*float64Timeout in seconds per query operationnil (no limit)
fetchSize := 100
client.DefaultFetchSize = &fetchSize
timeout := 5.0
client.DefaultTimeout = &timeout

Construct queries with the SQL or FOL helpers. Both default to the "DEMO" schema; pass an optional second argument to override it.

q := tw.SQL("SELECT name, email FROM contacts WHERE region = 'US'")
// With explicit schema
q := tw.SQL("SELECT * FROM users", "MY_SCHEMA")
// FOL query
q := tw.FOL("((x) s.t. (users x))", "MY_PACKAGE")

Pass a QueryRestriction to cap rows or set a timeout for a single execution. Pass nil to use client defaults.

limit := 50
r := &tw.QueryRestriction{RowLimit: &limit}
rs, err := client.ExecuteQuery(q, r)

ExecuteQuery runs a query and returns a ResultSet that streams rows lazily.

rs, err := client.ExecuteQuery(tw.SQL("SELECT name, age FROM people"), nil)
if err != nil {
log.Fatal(err)
}
for {
row, err := rs.Next()
if err == io.EOF {
break
}
if err != nil {
log.Fatal(err)
}
fmt.Println(row)
}

Check a query for errors without executing it:

err := client.ValidateQuery(tw.SQL("SELECT * FROM nonexistent"))
if err != nil {
fmt.Println(err) // "invalid query: ..."
}

ResultSet is returned by ExecuteQuery. Rows are fetched from the server in batches as needed.

Method / FieldDescription
Next() (Row, error)Returns the next row. Returns io.EOF when exhausted.
Pull(n int) ([]Row, error)Fetch up to n rows. Returns fewer if the result set is exhausted.
SignatureColumn metadata from the server.

Row is []any — a slice of values whose types correspond to the query’s output signature.

// Fetch exactly 10 rows
rows, err := rs.Pull(10)
// Iterate through the rest
for {
row, err := rs.Next()
if err == io.EOF {
break
}
if err != nil {
log.Fatal(err)
}
fmt.Println(row)
}

Manage connectors on the server to expose external data sources as virtual tables.

// Activate a connector
err := client.ActivateConnector("salesforce", map[string]any{"api_key": "..."})
// List active connectors
names, err := client.ListActiveConnectors()
fmt.Println(names) // ["salesforce", "zendesk"]
// Deactivate a connector
err = client.DeactivateConnector("salesforce")
MethodDescription
ActivateConnector(name string, jsonData any) errorLoad and activate a named connector. jsonData is passed to the connector on initialization.
DeactivateConnector(name string) errorDeactivate a connector and drop its virtual tables.
ListActiveConnectors() ([]string, error)Returns the names of all currently active connectors.

MethodDescription
Close()Closes the underlying TCP connection.
IsClosed() boolReports whether the connection has been closed.
Wait()Blocks until the connection is closed. Useful for long-running processes.

TypeReturned when
InvalidQueryErrorThe server rejects a query as syntactically invalid or referencing nonexistent tables/columns.

All other server-level errors are returned as the underlying jsonrpc.RPCError.