Skip to content

Commit d0fdb7d

Browse files
committed
Add schema example to create collection get started
1 parent 4215843 commit d0fdb7d

File tree

1 file changed

+18
-41
lines changed

1 file changed

+18
-41
lines changed

get-started.mdx

Lines changed: 18 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -49,61 +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 (`@polybase/client`).
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).
53+
5354
5455
Watch Shaki create a simple collection using the Polybase Explorer.
5556
<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>
5657
57-
<Info>
58-
We suggest creating collections using [Polybase Explorer](https://explorer.testnet.polybase.xyz). You will need to first login and create an account.
59-
</Info>
60-
61-
## Create a collection programmatically
62-
63-
If you want to create your collection programatically, see [Creating collection with applySchema](/collections#).
64-
65-
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
66-
collections in a single `applySchema` call.
58+
Here's an example Schema:
6759
6860
```js
69-
await db.applySchema(`
70-
@public
71-
collection City {
72-
id: string;
73-
name: string;
74-
country?: string;
75-
76-
constructor (id: string, name: string) {
77-
this.id = id;
78-
this.name = name;
79-
}
80-
81-
setCountry (country: string) {
82-
this.country = country;
83-
}
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;
8470
}
8571
86-
@public
87-
collection Country {
88-
id: string;
89-
name: string;
90-
91-
constructor (id: string, name: string) {
92-
this.id = id;
93-
this.name = name;
94-
}
72+
setCountry (country: string) {
73+
this.country = country;
9574
}
96-
`,
97-
"your-namespace"
98-
); // your-namespace is optional if you have defined a default namespace
75+
}
9976
```
10077
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.
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>
10281
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).
10482
10583
## Create a collection record
106-
10784
When you create a new record, the `constructor` function in your collection is called with the parameters you provide.
10885
10986
```js

0 commit comments

Comments
 (0)