Skip to content

Commit 741e0ae

Browse files
committed
docs: add input
1 parent 90b3d0f commit 741e0ae

File tree

2 files changed

+217
-0
lines changed

2 files changed

+217
-0
lines changed

docs/input.md

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
# Input
2+
3+
Input data represents the arguments of the function in the Polybase collection.
4+
5+
## Usage
6+
7+
To get started, you need to find out what arguments the function you want to call takes. Let's consider an example with a constructor function:
8+
9+
```polylang
10+
collection Example {
11+
id: string;
12+
...
13+
14+
constructor(
15+
id: string,
16+
name: string,
17+
age: number,
18+
) { ... }
19+
}
20+
```
21+
22+
So, you need to pass the following arguments: `id`, `name`, `age`. This can be done in several ways.
23+
24+
### Structure
25+
26+
```go
27+
type Input struct {
28+
ID string
29+
Name string
30+
Age int
31+
}
32+
33+
input := Input{"1", "example", 146}
34+
coll.Create(..., args: input)
35+
```
36+
37+
### Pointer
38+
39+
```go
40+
var (
41+
id = "1"
42+
name = "example"
43+
age = 146
44+
)
45+
46+
coll.Create(..., args: &id, &name, &age)
47+
```
48+
49+
### Array
50+
51+
```go
52+
input := []any{"1", "example", 146}
53+
coll.Create(..., args: input)
54+
```
55+
56+
Please note that the array or slice must be of type `any`, otherwise this array or slice will be used as a single argument.
57+
58+
## Example
59+
60+
This example is intended solely to demonstrate the capabilities of the argument parser.
61+
62+
```polylang
63+
collection Example {
64+
id: string;
65+
info: {
66+
age: number;
67+
alive: boolean;
68+
},
69+
tags: string[];
70+
balance: map<string, number>;
71+
72+
constructor(
73+
id string,
74+
age number,
75+
alive boolean,
76+
tags string[],
77+
balance: map<string, number>
78+
) { ... }
79+
}
80+
```
81+
82+
```go
83+
type Info struct {
84+
Age int
85+
Alive bool
86+
}
87+
88+
var (
89+
id = "uid:1"
90+
info = Info{146, true}
91+
tags = []string{"durudex", "blockchain"}
92+
balance = map[string]int{"DUR": 1}
93+
)
94+
95+
coll.Create(..., args: id, info, tags, balance)
96+
```
97+
98+
**The final result that will be sent to the Polybase API will have the following format:**
99+
100+
```json
101+
["uid:1", 146, true, ["durudex", "blockchain"], {"DUR": 1}]
102+
```

docs/uk/input.md

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
# Вхідні дані
2+
3+
Вхідні дані представляють аргументи функції у колекції Polybase.
4+
5+
## Використання
6+
7+
Щоб розпочати використання, вам потрібно знати, які аргументи приймає функція, яку ви плануєте викликати. Розглянемо приклад функції-конструктора:
8+
9+
```polylang
10+
collection Example {
11+
id: string;
12+
...
13+
14+
constructor(
15+
id: string,
16+
name: string,
17+
age: number,
18+
) { ... }
19+
}
20+
```
21+
22+
Отже, вам потрібно передати такі аргументи: `id`, `name`, `age`. Це можна зробити декількома способами.
23+
24+
### Значення
25+
26+
```go
27+
var (
28+
id = "1"
29+
name = "example"
30+
age = 146
31+
)
32+
33+
coll.Create(..., args: id, name, status)
34+
```
35+
36+
### Структура
37+
38+
```go
39+
type Input struct {
40+
ID string
41+
Name string
42+
Age int
43+
}
44+
45+
input := Input{"1", "example", 146}
46+
47+
coll.Create(..., args: input)
48+
```
49+
50+
### Вказівник
51+
52+
```go
53+
var (
54+
id = "1"
55+
name = "example"
56+
age = 146
57+
)
58+
59+
coll.Create(..., args: &id, &name, &age)
60+
```
61+
62+
### Масив
63+
64+
```go
65+
input := []any{"1", "example", 146}
66+
coll.Create(..., args: input)
67+
```
68+
69+
Зверніть увагу, що масив або зріз повинен мати тип `any`, інакше цей масив або зріз буде використано як один аргумент.
70+
71+
## Приклад
72+
73+
Цей приклад призначений виключно для демонстрації можливостей аналізатора аргументів.
74+
75+
```polylang
76+
collection Example {
77+
id: string;
78+
info: {
79+
age: number;
80+
alive: boolean;
81+
},
82+
tags: string[];
83+
balance: map<string, number>;
84+
85+
constructor(
86+
id string,
87+
age number,
88+
alive boolean,
89+
tags string[],
90+
balance: map<string, number>
91+
) { ... }
92+
}
93+
```
94+
95+
```go
96+
type Info struct {
97+
Age int
98+
Alive bool
99+
}
100+
101+
var (
102+
id = "uid:1"
103+
info = Info{146, true}
104+
tags = []string{"durudex", "blockchain"}
105+
balance = map[string]int{"DUR": 1}
106+
)
107+
108+
coll.Create(..., args: id, info, tags, balance)
109+
```
110+
111+
**Кінцевий результат, який буде надіслано до API Polybase, матиме наступний вигляд:**
112+
113+
```json
114+
["uid:1", 146, true, ["durudex", "blockchain"], {"DUR": 1}]
115+
```

0 commit comments

Comments
 (0)