Description
I have found these related issues/pull requests
I've found a list of open and closed issues related to fixtures in #[sqlx::test]
but I don't see anything about a feature request for a way to access this fixture loading functionality outside of #[sqlx::test]
, either in code or in the CLI.
Description
Hi, I'm using sqlx and of course #[sqlx::test]
for unit/integration tests, but I also have a "test client" for my app, and in development, I'd like to just be able to load fixtures manually.
(Another thought is "factories, not fixtures" which would be very useful in tests so we wouldn't have to maintain .sql files just for test fixtures, but that's out of scope here. I see a few limited crates like cder
that proport to do this, but I don't see much elegance on this front and integration with tests.)
Since we have to create .sql files for fixtures for use with the #[sqlx::test(fixtures(...)]
feature anyway, it would be nice if we could:
- re-use these outside of
#[sqlx::test]
; and - have access to it in the CLI, perhaps under
sqlx database fixtures
or similar.
Is there any way to expose the code that loads fixtures to a sqlx::fixtures!(...)
macro, just like sqlx::migrate!(...)
? Or even a non-macro function that just takes a list of fixtures to load? This would be really helpful in development to reduce boilerplate of either:
- Loading up the .sql files and executing them one by one; or
- Running an external command,
... when this capability is already built into sqlx.
Thanks!
Prefered solution
- Access to a function/method to load fixtures using the feature already built into sqlx, outside of
#[sqlx::test]
, similar tosqlx::migrate!(...)
e.g.sqlx::fixtures!(...)
or similar. - Access to this functionality via the CLI, perhaps under
sqlx database fixtures
or similar.
Is this a breaking change? Why or why not?
I don't think it would be a breaking change because I don't see any feature that exposes this functionality currently. Maybe I need a feature flag or something, but I don't see anything on it.
Thank you.