Skip to content
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

Access NR global context inside function #31

Open
tmdoit-zz opened this issue Jun 27, 2020 · 0 comments
Open

Access NR global context inside function #31

tmdoit-zz opened this issue Jun 27, 2020 · 0 comments

Comments

@tmdoit-zz
Copy link
Contributor

tmdoit-zz commented Jun 27, 2020

I'm trying to use external moment.js lib without luck. Here is my code:

CREATE FUNCTION getWeek AS 
``
    function(x) { 
        let moment = global.get('moment');
        return moment(x).week();
    }
``;
SELECT 
    COUNT(*), 
    SUBSTRING(created_at,1,10) AS created_at,
    getWeek(created_at)
FROM ?
GROUP BY SUBSTRING(created_at,1,10)

I failed also when tried to acceess msg object. Is there a way to resolve it?

EDITED:
As a workaround I used moment in function node before using alasql node so I can work with "ready" data.

let moment = global.get('moment');
for (let i = 0; i < msg.payload.length; i++) {
    msg.payload[i].week = moment(msg.payload[i].created_at).week(),
    msg.payload[i].month = moment(msg.payload[i].created_at).month(),
    msg.payload[i].yaer = moment(msg.payload[i].created_at).year()
}
return msg;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant