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

Implement first() for easy retrieval of single-row results #25

Merged
merged 3 commits into from
Jan 23, 2025

Conversation

evyatark2
Copy link
Contributor

No description provided.

src/result.zig Outdated

if (ret) |_| {
const i = r.iter();
while (try i.next()) |_| {}
Copy link
Owner

@speed2exe speed2exe Jan 23, 2025

Choose a reason for hiding this comment

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

@evyatark2 We should move this logic to line 147 instead, so that there won't be a need for if statement, something like:

            switch (row_res) {
                .ok => return null,
                .err => |err| return err.asError(),
                .row => |row| {
                    const i = r.iter();
                    while (try i.next()) |_| {}
                    return row
                },
            };

@speed2exe
Copy link
Owner

@evyatark2 We should also add a simple test case that returns 2 rows e.g. SELECT 1 UNION ALL SELECT 2, then call this method, ping the connection after (make sure that the connection is working normally after query).

@speed2exe
Copy link
Owner

LGTM

@speed2exe speed2exe merged commit d6c1f3b into speed2exe:main Jan 23, 2025
2 checks passed
@evyatark2 evyatark2 deleted the first branch January 23, 2025 17:12
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.

2 participants