-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[#40] Consistent column order for MBCUSTOMQUERY #50
base: main
Are you sure you want to change the base?
Conversation
This reverts commit 6442a65.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just read through the code briefly for now. I think this is dependent on #35? I'll review that next!
src/Code.js
Outdated
@@ -469,7 +469,12 @@ function MBCUSTOMQUERY(events, groupBy, orderBy, limit, offset) { | |||
|
|||
// turn the array of objects into a flat array | |||
const objArr = results.result.rows; | |||
return objectArrayToArray(objArr); | |||
const headersPreset = Array(payload.events[0].select.length); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could events[0]
ever be null
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it could be null but throw new Error()
will happen before
multibaas-for-google-sheets/src/library/Build.js
Lines 136 to 151 in 15bfb63
function buildCustomQuery(events, groupBy, orderBy, limit, offset) { | |
const query = { | |
events: [], | |
}; | |
if (groupBy && groupBy !== '') { | |
query.groupBy = groupBy; | |
} | |
if (orderBy && orderBy !== '') { | |
query.orderBy = orderBy; | |
} | |
// parse and validate header row | |
if (events.length < 1) { | |
throw new Error(`Expecting a header row followed by one or more data rows, found ${events.length} rows total`); | |
} |
I think this is not dependent on it because this PR is for |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Almost there! Some adjustment needed per my comment below.
src/Code.js
Outdated
return objectArrayToArray(objArr); | ||
const headersPreset = Array(payload.events[0].select.length); | ||
// eslint-disable-next-line no-restricted-syntax, guard-for-in | ||
for (const s of payload.events[0].select) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that it's not a requirement that each event row is the same event, nor that it has the same aliases. Therefore, I don't think we can just use events[0]
:
Which generates the following query:
{
"events": [
{
"eventName": "Transfer",
"select": [
{
"alias": "abc",
"inputIndex": 0,
"type": "input"
},
{
"alias": "ghi",
"inputIndex": 2,
"type": "input"
}
],
"filter": {
"rule": "and",
"children": [
{
"operator": "equal",
"value": "autotoken",
"fieldType": "contract_address_label"
}
]
}
},
{
"eventName": "Mint",
"select": [
{
"alias": "def",
"inputIndex": 1,
"type": "input"
},
{
"alias": "jkl",
"inputIndex": 2,
"type": "input"
}
],
"filter": {
"rule": "and",
"children": [
{
"operator": "equal",
"value": "autotoken",
"fieldType": "contract_address_label"
}
]
}
}
]
}
With the following result:
{
"status": 200,
"message": "success",
"result": {
"rows": [
{
"abc": null,
"def": "0xf9450d254a66ab06b30cfa9c6e7ae1b7598c7172",
"ghi": null,
"jkl": "100000000000"
},
{
"abc": "0x0000000000000000000000000000000000000000",
"def": null,
"ghi": "100000000000",
"jkl": null
},
{
"abc": "0xf9450d254a66ab06b30cfa9c6e7ae1b7598c7172",
"def": null,
"ghi": "10000000000",
"jkl": null
},
{
"abc": "0xf9450d254a66ab06b30cfa9c6e7ae1b7598c7172",
"def": null,
"ghi": "1000000000",
"jkl": null
},
{
"abc": null,
"def": "0xf9450d254a66ab06b30cfa9c6e7ae1b7598c7172",
"ghi": null,
"jkl": "100000000000"
},
{
"abc": "0x0000000000000000000000000000000000000000",
"def": null,
"ghi": "100000000000",
"jkl": null
},
{
"abc": "0xf9450d254a66ab06b30cfa9c6e7ae1b7598c7172",
"def": null,
"ghi": "2000000000",
"jkl": null
},
{
"abc": null,
"def": "0xf9450d254a66ab06b30cfa9c6e7ae1b7598c7172",
"ghi": null,
"jkl": "870000000"
},
{
"abc": "0x0000000000000000000000000000000000000000",
"def": null,
"ghi": "870000000",
"jkl": null
},
{
"abc": "0xf9450d254a66ab06b30cfa9c6e7ae1b7598c7172",
"def": null,
"ghi": "100",
"jkl": null
}
]
}
}
I tested this PR by merging #35 into this branch, and indeed, the output is broken:
Conflicts: src/Code.spec.js src/library/Util.js
Resolves #40
Result columns will be ordered based on what input
index
is set forMBCUSTOMQUERY