Skip to main content

Client

interface Client {
query(statement: string, values: Value[] = []): Promise<Record<string, any>[]>
queryStream(statement: string, values: Value[] = []): RowStream
transaction(): Promise<Transaction>
}

Clients are wrappers around a connection to a shared database that can be configured to point towards a particular branch and user combination.

new (constructor)#

interface Configuration {
branch?: string, // defaults to $BRANCH at compile-time
key?: string // defaults to an 'anonymous' user
}
function new(configuration?: Configuration): Client

Construct a new Client with a Configuration. Clients have a built-in branch configured at compile-time (see Branching), but this value can be overwritten through the Configuration. The default ROLE (anonymous) can be overwritten with a valid key from the User Dashboard.

query#

async function query(statement: string, values: Value[] = []): Promise<Record<string, any>[]>

query is the async interface for interacting with a database. All queries return an Array of rows (empty if nothing is returned from the query itself), with each row represented as an Object built from returned column names. See the Quick Start for more examples of running both simple and parameterized queries.

info

Typed queries without the use of any are on the Roadmap.

queryStream#

function queryStream(statement: string, values: Value[] = []): RowStream

Like query, but returning a stream of rows as they arrive from the server. This method is strongly preferred for large queries.

The RowStream returned by queryStream() is a standard Node stream that emits data, error, and end events. RowStream use object mode, returning Record<string, any> for each row as it arrives.

transaction#

async function transaction(): Promise<Transaction>

Creates a new Transaction

getBranch#

function getBranch(): string

Each client is compiled for a specific branch. To query that branch at runtime, use getBranch().