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

Fork everything as prisma-postgres #1

Open
wants to merge 3 commits into
base: pgbouncer-mode
Choose a base branch
from

Conversation

pimeys
Copy link
Owner

@pimeys pimeys commented Jan 15, 2021

No description provided.

Julius de Bruijn added 2 commits July 22, 2020 15:44
This enables usage with pgBouncer's transaction mode. Typically when
using the transaction mode, a client gets a new connection from
pgBouncer for every new transaction. It's quite useful and allows one to
use prepared statements in this mode. The workflow goes:

```sql
-- start a new transaction
BEGIN
-- deallocate all stored statements from the server to prevent
-- collisions
DEALLOCATE ALL
-- run the queries here
-- ..
-- ..
COMMIT -- or ROLLBACK
```

Now in a case where the query uses custom types such as enums, what
tokio-postgres does is it fetches the type info for the given type,
stores the info to the cache and also caches the statements for
fetching the info to the client. Now when we have two tables with
different custom types in both of them, we can imagine the following
workflow:

```rust
// first query
client.simple_query("BEGIN")?;
client.simple_query("DEALLOCATE ALL")?;
let stmt = client.prepare("SELECT \"public\".\"User\".\"id\", \"public\".\"User\".\"userType\" FROM \"public\".\"User\" WHERE 1=1 OFFSET $1")?;
dbg!(client.query(&stmt, &[&0i64])?);
client.simple_query("COMMIT")?;

// second query
client.simple_query("BEGIN")?;
client.simple_query("DEALLOCATE ALL")?;
let stmt = client.prepare("SELECT \"public\".\"Work\".\"id\", \"public\".\"Work\".\"workType\" FROM \"public\".\"Work\" WHERE 1=1 OFFSET $1")?;
dbg!(client.query(&stmt, &[&0i64])?);
client.simple_query("COMMIT")?;
```

The `userType` and `workType` are both enums, and the preparing of the
second query will give an error `prepared statement "s1" does not
exist`, where `s1` is the query to the `pg_catalog` for the type info.

The change here gives an extra flag for the client to disable caching
of statements.
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.

1 participant