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

fix: broken ndjson implementation #18

Merged
merged 2 commits into from
May 14, 2024
Merged

fix: broken ndjson implementation #18

merged 2 commits into from
May 14, 2024

Conversation

rexxars
Copy link
Member

@rexxars rexxars commented May 13, 2024

Fixes #17

Was broken by e5e7e57 upgrading the major of ndjson without updating the API.

@rexxars rexxars requested a review from sgulseth May 13, 2024 16:31
src/cli.js Outdated
Comment on lines 108 to 119
const value = await result.get()

if (Array.isArray(value)) {
for await (const row of value) {
yield JSON.stringify(row)
yield '\n'
}
} else {
yield JSON.stringify(await result.get())
yield JSON.stringify(value)
yield '\n'
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think all we want to do is change L108 to if (result.type == 'stream') { that way we stream the values per document in the resulting query

The proposed solution would turn any arrays into ndjson separated list, echo '{\"foo\": [1,2,3,4]}\n{\"bar\": [2]}' | ./bin/groq.js -n --pretty '*[][0].foo' would return '1\n2\n3\n4instead of[1,2,3,4]`

@sgulseth sgulseth merged commit 8e55835 into main May 14, 2024
6 checks passed
@sgulseth sgulseth deleted the fix/ndjson branch May 14, 2024 12:00
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

Successfully merging this pull request may close these issues.

TypeError when using -n CLI flag
2 participants