Skip to content

Commit 4215843

Browse files
calummooreshaki150697Shaki150697
authored
ENG-959: Update docs to encourage using explorer for creating collections (#102)
* Update get-started.mdx Added this video to show them how to create a simple collection using Explorer to encourage users to use Explorer. * Update get-started.mdx I have taken it off from Getting Started as you mentioned. Will now add it over to the Collections and add a new pull request for the same. * Update collections.mdx Moved over the SDK Collections code to the Collections section. Let me know if there are any more changes here to be made. * Created a new heading for Creating Collections Programmatically * Made the necessary changes as you had mentioned. * Made a small change to the doc * Split sections on creating collection --------- Co-authored-by: Shaki <[email protected]> Co-authored-by: Shaki150697 <[email protected]>
1 parent a4c683e commit 4215843

File tree

2 files changed

+58
-10
lines changed

2 files changed

+58
-10
lines changed

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

get-started.mdx

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,18 @@ 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+
Create collections using [Polybase Explorer](https://explorer.testnet.polybase.xyz) or the JavaScript SDK (`@polybase/client`).
53+
54+
Watch Shaki create a simple collection using the Polybase Explorer.
55+
<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>
5356
5457
<Info>
5558
We suggest creating collections using [Polybase Explorer](https://explorer.testnet.polybase.xyz). You will need to first login and create an account.
5659
</Info>
5760
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).
61+
## Create a collection programmatically
62+
63+
If you want to create your collection programatically, see [Creating collection with applySchema](/collections#).
5964
6065
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
6166
collections in a single `applySchema` call.
@@ -93,7 +98,9 @@ await db.applySchema(`
9398
); // your-namespace is optional if you have defined a default namespace
9499
```
95100
96-
For more details on creating collections, see the [collection](/collections) overview.
101+
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.
102+
103+
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).
97104
98105
## Create a collection record
99106
@@ -149,4 +156,4 @@ const data = await db.collection("City").record("new-york").get();
149156
</Card>
150157
151158
<Card title="Read the Polybase Whitepaper" icon="file-lines" href="https://polybase.xyz/whitepaper">
152-
</Card>
159+
</Card>

0 commit comments

Comments
 (0)