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

Rust: Streams should borrow the transaction #449

Closed
dmitrii-ubskii opened this issue Sep 25, 2023 · 0 comments · Fixed by #515
Closed

Rust: Streams should borrow the transaction #449

dmitrii-ubskii opened this issue Sep 25, 2023 · 0 comments · Fixed by #515

Comments

@dmitrii-ubskii
Copy link
Member

Problem to Solve

Currently it is possible to write this:

fn get_users(database: Database) -> Result<impl Stream<Item = Result<ConceptMap>>> {
    Session::new(database, Data).await?
        .transaction(TransactionType::Read).await?
        .query().match_("match $x isa user;")
}

This compiles and correctly returns the match query stream. However, as soon as we exit the scope of the function, the transaction is dropped and closed, and the stream is closed immediately, returning no items. This behaviour is confusing.

Proposed Solution

Query and concept streams should be bound by the lifetime of the transaction (/ query manager / concept manager). In that case, the above snippet will not compile, forcing the user to either hold on to the session and transaction handles, or retrieve all the data up front.

@dmitrii-ubskii dmitrii-ubskii self-assigned this Sep 25, 2023
dmitrii-ubskii added a commit that referenced this issue Nov 3, 2023
…hecks (#515)

## What is the goal of this PR?

We improve the UX of Driver usage in several ways:

- [Rust/Java/Python] Fix the formatting of error messages received from
the server during a transaction.
- [Java] Fix native error message formatting.
- [Java/Python] Add the ability to enable Rust logging over FFI
(resolves #482).
- The granularity of the logs is controlled by the
`TYPEDB_DRIVER_LOG_LEVEL` environment variable, which can be set to any
value of `error` (default), `warn`, `info`, `debug`, or `trace`, in
order of increasing verbosity. Setting the value to
`"typedb_driver=info"` will show only the typedb-driver messages.
- More advanced syntax is described in [the env_logger
documentation](https://docs.rs/env_logger/latest/env_logger/index.html#enabling-logging)
- [Rust] Network streams now borrow the transaction, so that the
transaction can't be mistakenly dropped. (resolves #449)
dmitrii-ubskii added a commit to dmitrii-ubskii/typedb-driver that referenced this issue Jan 8, 2024
…hecks (typedb#515)

## What is the goal of this PR?

We improve the UX of Driver usage in several ways:

- [Rust/Java/Python] Fix the formatting of error messages received from
the server during a transaction.
- [Java] Fix native error message formatting.
- [Java/Python] Add the ability to enable Rust logging over FFI
(resolves typedb#482).
- The granularity of the logs is controlled by the
`TYPEDB_DRIVER_LOG_LEVEL` environment variable, which can be set to any
value of `error` (default), `warn`, `info`, `debug`, or `trace`, in
order of increasing verbosity. Setting the value to
`"typedb_driver=info"` will show only the typedb-driver messages.
- More advanced syntax is described in [the env_logger
documentation](https://docs.rs/env_logger/latest/env_logger/index.html#enabling-logging)
- [Rust] Network streams now borrow the transaction, so that the
transaction can't be mistakenly dropped. (resolves typedb#449)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants