You must create a collection before writing and reading data to Polybase. Create collections using Polybase Explorer(recommended) or programatically using the JavaScript SDK.Watch Shaki create a simple collection using the Polybase Explorer.
A Polybase collection is just like an Ethereum contract, but instead of being for a single record, collections describes the rules for a set of records.
When you create a new record, the constructor function in your collection is called with the parameters you provide.
Copy
Ask AI
import { Polybase } from "@polybase/client";const db = new Polybase({ defaultNamespace: "your-namespace" });// Based on the collection code above, "new-york" is the `id` of the new record. // The `id` "new-york" must be unique (not already exist in the collection)await db.collection("City").create(["new-york", "New York"]); // new-york is the `id`, New York is the `name`
You can update records by calling methods defined on your collection.
Copy
Ask AI
import { Polybase } from "@polybase/client";const db = new Polybase({ defaultNamespace: "your-namespace" });await db.collection("City").call("setCountry", ["USA"]);
import { Polybase } from "@polybase/client";const db = new Polybase({ defaultNamespace: "your-namespace" });const data = await db.collection("City").record("new-york").get();