Optional
close: null | FunctionRetrieves the names of all tables that this client has access to.
name
is a string identifier unique to the [Table
] (per [Client
]),
which can be used in conjunction with [Client::open_table
] to get
a [Table
] instance without the use of [Client::table
]
constructor directly (e.g., one created by another [Client
]).
const tables = await client.get_hosted_table_names();
Optional
reconnect: null | FunctionRegister a callback which is invoked whenever [Client::table
] (on this
[Client
]) or [Table::delete
] (on a [Table
] belinging to this
[Client
]) are called.
Opens a [Table
] that is hosted on the perspective_server::Server
that is connected to this [Client
].
The name
property of [TableInitOptions
] is used to identify each
[Table
]. [Table
] name
s can be looked up for each [Client
]
via [Client::get_hosted_table_names
].
Get a virtual [Table
] named "table_one" from this [Client
]
const tables = await client.open_table("table_one");
Remove a callback previously registered via
Client::on_hosted_tables_update
.
Creates a new [Table
] from either a schema or data.
The [Client::table
] factory function can be initialized with either a
schema (see [Table::schema
]), or data in one of these formats:
When instantiated with data, the schema is inferred from this data.
While this is convenient, inferrence is sometimes imperfect e.g.
when the input is empty, null or ambiguous. For these cases,
[Client::table
] can first be instantiated with a explicit schema.
When instantiated with a schema, the resulting [Table
] is empty but
with known column names and column types. When subsqeuently
populated with [Table::update
], these columns will be coerced to
the schema's type. This behavior can be useful when
[Client::table
]'s column type inferences doesn't work.
The resulting [Table
] is virtual, and invoking its methods
dispatches events to the perspective_server::Server
this
[Client
] connects to, where the data is stored and all calculation
occurs.
arg
- Either schema or initialization data.options
- Optional configuration which provides one of:
limit
- The max number of rows the resulting [Table
] can
store.index
- The column name to use as an index column. If this
Table
is being instantiated by data, this column name must be
present in the data.name
- The name of the table. This will be generated if it is
not provided.format
- The explicit format of the input data, can be one of
"json"
, "columns"
, "csv"
or "arrow"
. This overrides
language-specific type dispatch behavior, which allows stringified
and byte array alternative inputs.Load a CSV from a string
:
const table = await client.table("x,y\n1,2\n3,4");
Load an Arrow from an ArrayBuffer
:
import * as fs from "node:fs/promises";
const table2 = await client.table(await fs.readFile("superstore.arrow"));
Load a CSV from a UInt8Array
(the default for this type is Arrow)
using a format override:
const enc = new TextEncoder();
const table = await client.table(enc.encode("x,y\n1,2\n3,4"), {
format: "csv",
});
Create a table with an index
:
const table = await client.table(data, { index: "Row ID" });
Optional
options: null | TableInitOptionsTerminates this [Client
], cleaning up any [crate::View
] handles the
[Client
] has open as well as its callbacks.
An instance of a [
Client
] is a connection to a singleperspective_server::Server
, whether locally in-memory or remote over some transport like a WebSocket.The browser and node.js libraries both support the
websocket(url)
constructor, which connects to a remoteperspective_server::Server
instance over a WebSocket transport.In the browser, the
worker()
constructor creates a new Web Workerperspective_server::Server
and returns a [Client
] connected to it.In node.js, a pre-instantied [
Client
] connected synhronously to a global singletonperspective_server::Server
is the default module export.JavaScript Examples
Create a Web Worker
perspective_server::Server
in the browser and return a [Client
] instance connected for it:Create a WebSocket connection to a remote
perspective_server::Server
:Access the synchronous client in node.js: