mirror of
https://github.com/launchbadge/sqlx.git
synced 2025-10-03 15:55:45 +00:00
Customize the macro error message based on offline status (#2769)
This commit is contained in:
parent
54c5d6bc3c
commit
080d57af3a
@ -160,33 +160,28 @@ pub fn expand_input<'a>(
|
|||||||
..
|
..
|
||||||
} => QueryDataSource::live(db_url)?,
|
} => QueryDataSource::live(db_url)?,
|
||||||
|
|
||||||
_ => {
|
Metadata { offline, .. } => {
|
||||||
// Try load the cached query metadata file.
|
// Try load the cached query metadata file.
|
||||||
let filename = format!("query-{}.json", hash_string(&input.sql));
|
let filename = format!("query-{}.json", hash_string(&input.sql));
|
||||||
|
|
||||||
// Check SQLX_OFFLINE_DIR, then local .sqlx, then workspace .sqlx.
|
// Check SQLX_OFFLINE_DIR, then local .sqlx, then workspace .sqlx.
|
||||||
let data_file_path = if let Some(sqlx_offline_dir_path) = env("SQLX_OFFLINE_DIR")
|
let dirs = [
|
||||||
.ok()
|
env("SQLX_OFFLINE_DIR").ok().map(PathBuf::from),
|
||||||
.map(PathBuf::from)
|
Some(METADATA.manifest_dir.join(".sqlx")),
|
||||||
|
Some(METADATA.workspace_root().join(".sqlx")),
|
||||||
|
];
|
||||||
|
let Some(data_file_path) = dirs
|
||||||
|
.iter()
|
||||||
|
.filter_map(|path| path.as_ref())
|
||||||
.map(|path| path.join(&filename))
|
.map(|path| path.join(&filename))
|
||||||
.filter(|path| path.exists())
|
.find(|path| path.exists())
|
||||||
{
|
else {
|
||||||
sqlx_offline_dir_path
|
|
||||||
} else if let Some(local_path) =
|
|
||||||
Some(METADATA.manifest_dir.join(".sqlx").join(&filename))
|
|
||||||
.filter(|path| path.exists())
|
|
||||||
{
|
|
||||||
local_path
|
|
||||||
} else if let Some(workspace_path) =
|
|
||||||
Some(METADATA.workspace_root().join(".sqlx").join(&filename))
|
|
||||||
.filter(|path| path.exists())
|
|
||||||
{
|
|
||||||
workspace_path
|
|
||||||
} else {
|
|
||||||
return Err(
|
return Err(
|
||||||
"`DATABASE_URL` must be set, or `cargo sqlx prepare` must have been run \
|
if *offline {
|
||||||
and .sqlx must exist, to use query macros"
|
"`SQLX_OFFLINE=true` but there is no cached data for this query, run `cargo sqlx prepare` to update the query cache or unset `SQLX_OFFLINE`"
|
||||||
.into(),
|
} else {
|
||||||
|
"set `DATABASE_URL` to use query macros online, or run `cargo sqlx prepare` to update the query cache"
|
||||||
|
}.into()
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user