diff --git a/sqlx-cli/src/prepare.rs b/sqlx-cli/src/prepare.rs index 95df2c54..fa166f68 100644 --- a/sqlx-cli/src/prepare.rs +++ b/sqlx-cli/src/prepare.rs @@ -5,6 +5,7 @@ use remove_dir_all::remove_dir_all; use sqlx::any::{AnyConnectOptions, AnyKind}; use std::collections::BTreeMap; use std::fs::File; +use std::io::BufWriter; use std::process::Command; use std::str::FromStr; use std::time::SystemTime; @@ -32,7 +33,9 @@ pub fn run(url: &str, merge: bool, cargo_args: Vec) -> anyhow::Result<() } serde_json::to_writer_pretty( - File::create("sqlx-data.json").context("failed to create/open `sqlx-data.json`")?, + BufWriter::new( + File::create("sqlx-data.json").context("failed to create/open `sqlx-data.json`")?, + ), &DataFile { db: db_kind, data }, ) .context("failed to write to `sqlx-data.json`")?; diff --git a/sqlx-macros/src/query/data.rs b/sqlx-macros/src/query/data.rs index 33055816..ee123b50 100644 --- a/sqlx-macros/src/query/data.rs +++ b/sqlx-macros/src/query/data.rs @@ -40,6 +40,7 @@ pub mod offline { use std::fmt::{self, Formatter}; use std::fs::File; + use std::io::{BufReader, BufWriter}; use std::path::Path; use proc_macro2::Span; @@ -60,11 +61,11 @@ pub mod offline { /// Find and deserialize the data table for this query from a shared `sqlx-data.json` /// file. The expected structure is a JSON map keyed by the SHA-256 hash of queries in hex. pub fn from_data_file(path: impl AsRef, query: &str) -> crate::Result { - serde_json::Deserializer::from_reader( + serde_json::Deserializer::from_reader(BufReader::new( File::open(path.as_ref()).map_err(|e| { format!("failed to open path {}: {}", path.as_ref().display(), e) })?, - ) + )) .deserialize_map(DataFileVisitor { query, hash: hash_string(query), @@ -107,8 +108,10 @@ pub mod offline { )); serde_json::to_writer_pretty( - File::create(&path) - .map_err(|e| format!("failed to open path {}: {}", path.display(), e))?, + BufWriter::new( + File::create(&path) + .map_err(|e| format!("failed to open path {}: {}", path.display(), e))?, + ), self, ) .map_err(Into::into)