To delete data on Polybase, you must implement a function on your collection that calls selfdestruct(). By convention, this should be a function called del().

You can view our example apps Simple CRUD and Polybase Social to see it working in action.

Define selfdestruct in Schema

The following provides an example of a delete function that only allows the owner of the record to delete it.

@public
collection City {
  id: string;
  owner: PublicKey;

  constructor (id: string) {
    this.id = id;
    this.owner = ctx.publicKey;
  }

  del () {
    if (this.owner != ctx.publicKey) {
      throw error("You cannot delete this record");
    }
    selfdestruct();
  }
}

Call delete from the SDK

You can now call the del() function:

import { Polybase } from "@polybase/client"

const db = new Polybase({ defaultNamespace: "your-namespace" });
const collectionReference = db.collection("City");

async function updateRecord () {
  const recordData = await collectionReference
    // the id of the record
    .record("new-york")
    // call the function you defined in your schema to delete a record
    .call("del");
}