Skip to content

Commit c96efba

Browse files
author
Polybase CI
committed
Merge remote-tracking branch 'origin/main' into release
2 parents 85e8041 + 407fea7 commit c96efba

9 files changed

+142
-56
lines changed

_snippets/examples/client-auth.mdx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
Open in [CodeSandbox](https://codesandbox.io/s/polybase-client-auth-vqo2ui?file=/index.html)
2+
3+
View [Schema for example](https://explorer.testnet.polybase.xyz/collections/pk%2F0xea448a816eba719df5155f1799d014d6ce74638fc5d42780597ad7e9df046a486ba295ed1c8364d284c416b350ba6b4e4db4966faf053e98cca6cab9fd6aa266%2FTest%2FUser/schema) in explorer
4+
5+
<iframe
6+
src="https://codesandbox.io/embed/polybase-client-auth-vqo2ui?autoresize=1&fontsize=14&hidenavigation=1&theme=dark"
7+
width="100%"
8+
height="500px"
9+
allow="accelerometer; ambient-light-sensor; camera; encrypted-media; geolocation; gyroscope; hid; microphone; midi; payment; usb; vr; xr-spatial-tracking"
10+
sandbox="allow-forms allow-modals allow-popups allow-presentation allow-same-origin allow-scripts"
11+
></iframe>

_snippets/examples/examples.mdx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
You can view our example apps
2+
[Simple CRUD](/simple-crud) and [Polybase Social](/polybase-social) to see it working in
3+
action.

collections.mdx

Lines changed: 47 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,55 @@ action.
1818

1919
## Create a collection
2020

21-
You can create a collection using the [Explorer](https://explorer.testnet.polybase.xyz) **(recommended)** or by using the client library and calling the `applySchema` method on your polybase instance.
21+
### Create collection using the Explorer (recommended)
2222

23-
<Info>
24-
We recommended you use [Polybase
25-
Explorer](https://explorer.testnet.polybase.xyz) to create your Collection. You will need to first login
26-
and create an account.
27-
</Info>
23+
Navigate to the [Explorer](https://explorer.testnet.polybase.xyz), and click on "Create Collection". You will then be prompted to sign in.
24+
25+
If you create a collection in the explorer, the collection will be owned by the account you used to sign in.
26+
27+
28+
### Create collection programmatically
29+
30+
To create a schema programatically, you can use the `applySchema` method on your Polybase client instance.
31+
32+
In this example, we create a collection called `City` that has `name` and `country` fields, and a `setCountry()` function. You can define multiple collections in a single `applySchema` call.
33+
34+
```js
35+
import { Polybase } from "@polybase/client"
36+
37+
const db = new Polybase({ defaultNamespace: "your-namespace" })
38+
39+
await db.applySchema(`
40+
@public
41+
collection City {
42+
id: string;
43+
name: string;
44+
country?: string;
45+
46+
constructor (id: string, name: string) {
47+
this.id = id;
48+
this.name = name;
49+
}
50+
51+
setCountry (country: string) {
52+
this.country = country;
53+
}
54+
}
2855
56+
@public
57+
collection Country {
58+
id: string;
59+
name: string;
60+
61+
constructor (id: string, name: string) {
62+
this.id = id;
63+
this.name = name;
64+
}
65+
}
66+
`,
67+
"your-namespace"
68+
); // your-namespace is optional if you have defined a default namespace
69+
```
2970

3071
<Warning>
3172
If you use `applySchema` you will need to sign the request [sign the request](https://docs.polybase.xyz/write#signing-requests), and

delete-data.mdx

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,50 @@ To delete data on Polybase, you must implement a function on your collection
66
that calls `selfdestruct()`. By convention, this should be a function called
77
`del()`.
88

9+
<Snippet file="examples/examples.mdx" />
10+
11+
### Define selfdestruct in Schema
12+
913
The following provides an example of a delete function that only allows the
1014
owner of the record to delete it.
1115

1216
```js
1317
@public
14-
collection Place {
15-
country: string;
16-
owner: id;
18+
collection City {
19+
id: string;
20+
owner: PublicKey;
1721

1822
constructor (id: string) {
1923
this.id = id;
20-
this.owner = ctx.publicKey.toHex();
24+
this.owner = ctx.publicKey;
2125
}
2226

2327
del () {
24-
if (owner != ctx.auth) {
25-
throw error();
28+
if (this.owner != ctx.publicKey) {
29+
throw error("You cannot delete this record");
2630
}
2731
selfdestruct();
2832
}
2933
}
3034

3135
```
36+
37+
### Call delete from the SDK
38+
39+
You can now call the `del()` function:
40+
41+
```js
42+
import { Polybase } from "@polybase/client"
43+
44+
const db = new Polybase({ defaultNamespace: "your-namespace" });
45+
const collectionReference = db.collection("City");
46+
47+
async function updateRecord () {
48+
const recordData = await collectionReference
49+
// the id of the record
50+
.record("new-york")
51+
// call the function you defined in your schema to delete a record
52+
.call("del");
53+
}
54+
```
55+

get-started.mdx

Lines changed: 27 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -49,54 +49,38 @@ const db = polybase.Polybase({
4949
5050
## Create a collection
5151
52-
Create collections using [Polybase Explorer](https://explorer.testnet.polybase.xyz) or the JavaScript SDK.
52+
You must create a collection before writing and reading data to Polybase. Create collections using [Polybase Explorer](https://explorer.testnet.polybase.xyz) **(recommended)** or programatically [using the JavaScript SDK](/collections#create-collection-programmatically).
5353
54-
<Info>
55-
We suggest creating collections using [Polybase Explorer](https://explorer.testnet.polybase.xyz). You will need to first login and create an account.
56-
</Info>
5754
58-
A Polybase collection describes the rules for a collection of data, not just a single record (as is the case with other smart collection languages).
55+
Watch Shaki create a simple collection using the Polybase Explorer.
56+
<iframe width="560" height="315" src="https://www.youtube.com/embed/EKHD7i1y4jc" title="Defining a collection in Polybase Explorer" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" allowfullscreen></iframe>
5957
60-
In this example we use the JavaScript SDK to create a collection called `City` that has `name` and `country` fields, and a `setCountry()` function. You can define multiple
61-
collections in a single `applySchema` call.
58+
Here's an example Schema:
6259
6360
```js
64-
await db.applySchema(`
65-
@public
66-
collection City {
67-
id: string;
68-
name: string;
69-
country?: string;
70-
71-
constructor (id: string, name: string) {
72-
this.id = id;
73-
this.name = name;
74-
}
75-
76-
setCountry (country: string) {
77-
this.country = country;
78-
}
61+
@public
62+
collection City {
63+
id: string;
64+
name: string;
65+
country?: string;
66+
67+
constructor (id: string, name: string) {
68+
this.id = id;
69+
this.name = name;
7970
}
8071
81-
@public
82-
collection Country {
83-
id: string;
84-
name: string;
85-
86-
constructor (id: string, name: string) {
87-
this.id = id;
88-
this.name = name;
89-
}
72+
setCountry (country: string) {
73+
this.country = country;
9074
}
91-
`,
92-
"your-namespace"
93-
); // your-namespace is optional if you have defined a default namespace
75+
}
9476
```
9577
96-
For more details on creating collections, see the [collection](/collections) overview.
78+
<Note>
79+
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.
80+
</Note>
9781
98-
## Create a collection record
9982
83+
## Create a collection record
10084
When you create a new record, the `constructor` function in your collection is called with the parameters you provide.
10185
10286
```js
@@ -134,6 +118,12 @@ const db = new Polybase({ defaultNamespace: "your-namespace" });
134118
const data = await db.collection("City").record("new-york").get();
135119
```
136120
121+
## Live Example
122+
123+
<Snippet file="examples/client-auth.mdx" />
124+
125+
126+
137127
## Next steps
138128
139129
<Card title="Understand Collections" icon="table" href="/collections">
@@ -143,4 +133,4 @@ const data = await db.collection("City").record("new-york").get();
143133
</Card>
144134
145135
<Card title="Read the Polybase Whitepaper" icon="file-lines" href="https://polybase.xyz/whitepaper">
146-
</Card>
136+
</Card>

mint.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "Polybase",
33
"versions": [
4-
"0.6.5"
4+
"0.6.6"
55
],
66
"logo": {
77
"light": "/logo/light.svg",
@@ -94,6 +94,7 @@
9494
{
9595
"group": "Examples",
9696
"pages": [
97+
"simple-crud",
9798
"polybase-social"
9899
]
99100
},

read.mdx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,8 @@ There are two ways to retrieve data in Polybase.
77
1. Fetch data once with `.get()`
88
2. Listen for real time updates with `.onSnapshot()`
99

10-
You can view our example app
11-
[Polybase Social](https://social.testnet.polybase.xyz) to see it working in
12-
action.
10+
<Snippet file="examples/examples.mdx" />
11+
1312

1413
## Get a single record
1514

simple-crud.mdx

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
title: "Simple CRUD"
3+
---
4+
5+
A minimal HTML example demonstrating the key features of Polybase:
6+
7+
- Authentication using [Polybase Auth](/authentication)
8+
- [get](/read#get-a-single-record) a record from Polybase
9+
- [create](/write-data#creating-a-record) new record
10+
- [update](/write-data#creating-a-record) existing record using `setName()` defined in the schema
11+
- [delete](/delete-data) existing record using `del()` defined in the schema
12+
13+
14+
## Example
15+
16+
<Snippet file="examples/client-auth.mdx" />
17+
18+

write-data.mdx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@ title: "Write Data"
44

55
You must [define a collection](/collections) before writing data to Polybase.
66

7-
You can view our example app
8-
[Polybase Social](https://social.testnet.polybase.xyz) to see it working in
9-
action.
7+
<Snippet file="examples/examples.mdx" />
8+
109

1110
## Creating a record
1211

0 commit comments

Comments
 (0)