-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
#[sqlx::test] #330
Comments
We should put the connection into a never-committed transaction. The general idea is anything done to the test transaction is not visible outside that test. See http://docs.diesel.rs/diesel/connection/trait.Connection.html#method.begin_test_transaction for a similar concept in Diesel. Additionally, we should probably add a way to create a singleton Pool ( singleton meaning the pool has a single connection it manages and doesn't ever add any more ) from a connection like |
I agree with the transaction but the attribute should accept an argument to disable this for stuff that doesn't work in a transaction (I'm not sure what).
|
Was this ever implemented? I'm looking for a way to do this with sqlx (I used to do it in Diesel with the linked method) but I don't see anything in sqlx-test's source code that would do this. Edit: BTW, it would be helpful to have documentation for |
any chance this will get implemented, and furthermore is there an interface that simplifies fakes or mocks of PgConnection when one doesn't need to actually call all the way to the database? thanks |
I've spent the last week or so prototyping this attribute after having finally nailed down exactly how we want it to work: #2001 |
Thought of this one a while ago before public release but it didn't make it to this issue tracker.
Basically enables this pattern:
Where the emitted code is equivalent to something like this:
@mehcode has a version of this on
develop
already, although it only covers the#[tokio::test]
/#[async_std::test]
part (which effectively just inlines what those attributes do): https://github.com/launchbadge/sqlx/blob/develop/sqlx-rt-macros/src/lib.rsThe only real question I think is what to do as far as the error from
dotenv::var()
because the error that's emitted is not helpful at all in the case ofDATABASE_URL
not being defined, and would be compounded by the fact that the user wouldn't be able to immediately see the code where it came from.My current best idea is to add a (hidden?) variant to
sqlx::Error
, since the function result's error type would need to be convertible fromsqlx::Error
anyway for theconnect()
call and any calls that actually use the connection. Some users will probably elect to just usesqlx::Result
anyway.The text was updated successfully, but these errors were encountered: