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

Query result iterator should return objects #83

Closed
malthe opened this issue Dec 6, 2023 · 0 comments
Closed

Query result iterator should return objects #83

malthe opened this issue Dec 6, 2023 · 0 comments
Labels
enhancement New feature or request

Comments

@malthe
Copy link
Owner

malthe commented Dec 6, 2023

The initial API design was more or less compatible with https://node-postgres.com/, i.e. pg.

In particular, query results were composed of rows and names (although the pg library provides fields from which you can get to the column names).

We want to preserve this result interface, while also providing a more ergonomic and idiomatic interface which we will call the iterator interface:

const result = client.query<{ message: string; }>(
    "SELECT 'Hello ' || $1 || '!' AS message",
    ['world']
);

for (const item of await result) {
    // 'Hello world!'
    console.log(item.message);
}

The awaited result object still provides the rows and names properties (as well as other properties, currently status which is the protocol statement status such as "SELECT 1" indicating that one row was selected).

In addition, rows will now be typed such that we have row.get(name: keyof T) returning a value which matches the generic type parameter.

This issue was spawned from the discussions in #66.

@malthe malthe added the enhancement New feature or request label Dec 6, 2023
@malthe malthe changed the title Query result to return objects rather than rows Query result iterator should return objects Dec 13, 2023
@malthe malthe closed this as completed Feb 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant