-
Notifications
You must be signed in to change notification settings - Fork 0
/
loadEntireTable.js
63 lines (43 loc) · 1.26 KB
/
loadEntireTable.js
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
// A simple script that fully loads a table of your choosing.
// Meaning performance is going to suck if you try to run it on a 50k-record behemoth.
// But hey - it's convenient.
const
Log = {
s: [],
latest: function(){
return this.s[this.s.length-1]
},
show: () => output.inspect(Log.s)
}
const
allTables = base.tables.flatMap(table => table.name),
menu = async function (buttons,label) {
return await input.buttonsAsync(label??'', allTables)
.then(click => Log.s.push(click))
},
tableNameMenu = () => menu(allTables,'Choose a table to load:'),
allFields = (table) => base.getTable(table).fields.flatMap(field=>field.name)
class Frame {
constructor(config){
return config.render().then(()=>{
output.clear()
config.callback()
})
}
}
await new Frame({
render: tableNameMenu,
callback: () => Log.s.push(allFields(Log.latest()))
})
const
q = await base.getTable(Log.s[0])
.selectRecordsAsync(),
Result = []
q.records.forEach(record => {
const object = {}
Log.s[1].forEach(
field => object[field] = record.getCellValue(field)
)
Result.push(object)
})
output.inspect(Result)