-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
examples.ts
76 lines (65 loc) · 1.51 KB
/
examples.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import { Airtable, Field } from "./mod.ts";
const airtable = new Airtable({
apiKey: "keyXXXXXXXXXXXXXX",
baseId: "appXXXXXXXXXXXXXX",
tableName: "Some table name",
});
const airtableUsingEnv = new Airtable({
useEnv: true,
});
const results = await airtable.select();
type Fields = {
["Name"]: string;
["Age"]: number;
["Active"]?: Field.Checkbox;
};
const { records, offset } = await airtable.select<Fields>({
fields: ["Name", "Age"],
maxRecords: 420,
pageSize: 69,
sort: [
{ field: "Name", direction: "asc" },
{ field: "Age", direction: "desc" },
],
view: "Grid view",
});
const { id, fields, createdTime } = await airtable.find("recXXXXXXXXXXXXXX");
const createOne = await airtable.create({
["Name"]: "Griko Nibras",
["Age"]: 25,
});
const createMultiple = await airtable.create<Fields>(
[
{ ["Name"]: "Foo", ["Age"]: 20 },
{ ["Name"]: "Bar", ["Age"]: 15 },
],
{ typecast: true }
);
const updateOne = await airtable.update<Fields>("recXXXXXXXXXXXXXX", {
["Name"]: "Adult boi",
["Age"]: 30,
});
const updateMultiple = await airtable.update<Fields>(
[
{
id: "recXXXXXXXXXXXXXX",
fields: {
["Name"]: "Adult boi",
["Age"]: 30,
},
},
{
id: "recXXXXXXXXXXXXXX",
fields: {
["Name"]: "Yung boi",
["Age"]: 15,
},
},
],
{ typecast: true }
);
const deleteOne = await airtable.delete("recXXXXXXXXXXXXXX");
const deleteMultiple = await airtable.delete([
"recXXXXXXXXXXXXXX",
"recXXXXXXXXXXXXXX",
]);