diff --git a/butane/src/lib.rs b/butane/src/lib.rs index 8cd2691e..1e97f5d1 100644 --- a/butane/src/lib.rs +++ b/butane/src/lib.rs @@ -171,9 +171,10 @@ pub mod prelude { //! Its use is recommended, but not required. If not used, the use //! of butane's macros may require some of its re-exports to be //! used manually. + pub use butane_core::db::BackendConnection; + #[doc(no_inline)] pub use crate::DataObject; #[doc(no_inline)] pub use crate::DataResult; - pub use butane_core::db::BackendConnection; } diff --git a/butane/tests/basic.rs b/butane/tests/basic.rs index 350829f7..bae7fac3 100644 --- a/butane/tests/basic.rs +++ b/butane/tests/basic.rs @@ -2,11 +2,10 @@ use butane::db::Connection; use butane::{butane_type, find, model, query}; use butane::{colname, prelude::*}; use butane::{ForeignKey, ObjectState}; +use butane_test_helper::*; use chrono::{naive::NaiveDateTime, offset::Utc, DateTime}; use serde::Serialize; -use butane_test_helper::*; - #[butane_type] pub type Whatsit = String; diff --git a/butane/tests/common/blog.rs b/butane/tests/common/blog.rs index 265cd37c..6cad8786 100644 --- a/butane/tests/common/blog.rs +++ b/butane/tests/common/blog.rs @@ -2,7 +2,6 @@ use butane::prelude::*; use butane::{dataresult, model}; use butane::{db::Connection, ForeignKey, Many, ObjectState}; use chrono::{naive::NaiveDateTime, offset::Utc}; - #[cfg(feature = "fake")] use fake::Dummy; diff --git a/butane/tests/custom_enum_derived.rs b/butane/tests/custom_enum_derived.rs index e015a7e1..8d71d6e8 100644 --- a/butane/tests/custom_enum_derived.rs +++ b/butane/tests/custom_enum_derived.rs @@ -3,7 +3,6 @@ use butane::db::Connection; use butane::prelude::*; use butane::{model, query}; use butane::{FieldType, FromSql, ObjectState, SqlVal, ToSql}; - use butane_test_helper::*; #[derive(PartialEq, Eq, Debug, Clone, FieldType)] diff --git a/butane/tests/custom_pg.rs b/butane/tests/custom_pg.rs index 91735be6..448d7e0f 100644 --- a/butane/tests/custom_pg.rs +++ b/butane/tests/custom_pg.rs @@ -1,14 +1,14 @@ // We wrap everything in an inner module just so it's easier to have the feature gate in one place #[cfg(feature = "pg")] mod custom_pg { + use std::result::Result; + use butane::custom::{SqlTypeCustom, SqlValRefCustom}; use butane::prelude::*; use butane::{butane_type, db::Connection, model, ObjectState}; use butane::{FieldType, FromSql, SqlType, SqlVal, SqlValRef, ToSql}; use butane_test_helper::{maketest, maketest_pg}; - use std::result::Result; - // newtype so we can implement traits for it. #[butane_type(Custom(POINT))] #[derive(Debug, PartialEq, Clone)] diff --git a/butane/tests/custom_type.rs b/butane/tests/custom_type.rs index 85fb0ab5..9fd8e005 100644 --- a/butane/tests/custom_type.rs +++ b/butane/tests/custom_type.rs @@ -2,7 +2,6 @@ use butane::db::Connection; use butane::prelude::*; use butane::{butane_type, model, query}; use butane::{FieldType, FromSql, ObjectState, SqlType, SqlVal, SqlValRef, ToSql}; - use butane_test_helper::*; #[butane_type(Text)] diff --git a/butane/tests/fake.rs b/butane/tests/fake.rs index 3650b53a..707f5596 100644 --- a/butane/tests/fake.rs +++ b/butane/tests/fake.rs @@ -1,15 +1,13 @@ use butane::db::Connection; use butane::{find, DataObject, ForeignKey}; - use butane_test_helper::*; mod common; -fn fake_blog_post(conn: Connection) { - use fake::{Fake, Faker}; - - use common::blog::{Blog, Post, Tag}; +use common::blog::{Blog, Post, Tag}; +use fake::{Fake, Faker}; +fn fake_blog_post(conn: Connection) { let mut fake_blog: Blog = Faker.fake(); fake_blog.save(&conn).unwrap(); diff --git a/butane/tests/json.rs b/butane/tests/json.rs index d7c72924..86e8f953 100644 --- a/butane/tests/json.rs +++ b/butane/tests/json.rs @@ -3,11 +3,10 @@ use std::collections::HashMap; use butane::model; use butane::prelude::*; use butane::{db::Connection, FieldType, ObjectState}; +use butane_test_helper::*; use serde::{Deserialize, Serialize}; use serde_json::Value; -use butane_test_helper::*; - #[model] #[derive(PartialEq, Eq, Debug, Clone)] struct FooJJ { diff --git a/butane/tests/many.rs b/butane/tests/many.rs index fba2bd5d..21a1c58d 100644 --- a/butane/tests/many.rs +++ b/butane/tests/many.rs @@ -1,7 +1,6 @@ use butane::db::Connection; use butane::prelude::*; use butane::{model, query::OrderDirection, Many, ObjectState}; - use butane_test_helper::*; mod common; diff --git a/butane/tests/migration-tests.rs b/butane/tests/migration-tests.rs index 34c8128e..69390eb5 100644 --- a/butane/tests/migration-tests.rs +++ b/butane/tests/migration-tests.rs @@ -4,13 +4,12 @@ use butane::migrations::{ }; use butane::{db::Connection, prelude::*, SqlType, SqlVal}; use butane_core::codegen::{butane_type_with_migrations, model_with_migrations}; +use butane_test_helper::*; use proc_macro2::TokenStream; use quote::quote; use sqlparser::dialect::GenericDialect; use sqlparser::parser::Parser as SqlParser; -use butane_test_helper::*; - #[test] fn current_migration_basic() { let tokens = quote! { diff --git a/butane/tests/nullable.rs b/butane/tests/nullable.rs index 084f4c3c..734dd087 100644 --- a/butane/tests/nullable.rs +++ b/butane/tests/nullable.rs @@ -1,7 +1,6 @@ use butane::db::Connection; use butane::prelude::*; use butane::{model, query}; - use butane_test_helper::*; #[model] diff --git a/butane/tests/query.rs b/butane/tests/query.rs index f602f14a..50b69d9d 100644 --- a/butane/tests/query.rs +++ b/butane/tests/query.rs @@ -2,9 +2,8 @@ use butane::db::Connection; use butane::prelude::*; use butane::query::BoolExpr; use butane::{colname, filter, find, query, Many}; -use chrono::{TimeZone, Utc}; - use butane_test_helper::*; +use chrono::{TimeZone, Utc}; mod common; use common::blog; diff --git a/butane/tests/r2d2.rs b/butane/tests/r2d2.rs index 12ff11f8..fbf6cbe7 100644 --- a/butane/tests/r2d2.rs +++ b/butane/tests/r2d2.rs @@ -1,6 +1,5 @@ -use butane_test_helper::{pg_connspec, setup_db, sqlite_connspec}; - use butane::db; +use butane_test_helper::{pg_connspec, setup_db, sqlite_connspec}; use r2d2_for_test as r2d2; #[cfg(feature = "sqlite")] diff --git a/butane/tests/uuid.rs b/butane/tests/uuid.rs index d2ac66a3..50793d8b 100644 --- a/butane/tests/uuid.rs +++ b/butane/tests/uuid.rs @@ -1,9 +1,8 @@ use butane::model; use butane::prelude::*; use butane::{db::Connection, ObjectState}; -use uuid_for_test::Uuid; - use butane_test_helper::*; +use uuid_for_test::Uuid; #[model] #[derive(PartialEq, Eq, Debug, Clone)] diff --git a/butane_cli/src/lib.rs b/butane_cli/src/lib.rs index ad17db52..360ad494 100644 --- a/butane_cli/src/lib.rs +++ b/butane_cli/src/lib.rs @@ -261,7 +261,9 @@ pub fn clean(base_dir: &Path) -> Result<()> { pub fn get_migrations(base_dir: &Path) -> Result { let root = base_dir.join("migrations"); if !root.exists() { - eprintln!("No butane migrations directory found. Add at least one model to your project and build."); + eprintln!( + "No butane migrations directory found. Add at least one model to your project and build." + ); std::process::exit(1); } Ok(migrations::from_root(root)) diff --git a/butane_cli/src/main.rs b/butane_cli/src/main.rs index 4885d680..078bcf83 100644 --- a/butane_cli/src/main.rs +++ b/butane_cli/src/main.rs @@ -1,11 +1,10 @@ use std::path::PathBuf; -use clap::{value_parser, Arg, ArgMatches}; - use butane_cli::{ base_dir, clean, clear_data, collapse_migrations, delete_table, embed, handle_error, list_migrations, migrate, Result, }; +use clap::{value_parser, Arg, ArgMatches}; fn main() { let app = clap::Command::new("butane") diff --git a/butane_codegen/src/filter.rs b/butane_codegen/src/filter.rs index ab116467..08583950 100755 --- a/butane_codegen/src/filter.rs +++ b/butane_codegen/src/filter.rs @@ -1,9 +1,10 @@ -use super::*; use proc_macro2::Span; use proc_macro2::TokenStream as TokenStream2; use quote::{quote, quote_spanned, ToTokens}; use syn::{spanned::Spanned, BinOp, Expr, ExprBinary, ExprMethodCall, ExprPath, Ident, LitStr}; +use super::*; + pub fn for_expr(dbres: &Ident, expr: &Expr) -> TokenStream2 { handle_expr("e!(<#dbres as butane::DataResult>::DBO::fields()), expr) } diff --git a/butane_codegen/src/lib.rs b/butane_codegen/src/lib.rs index 0bc1453e..75de5f5a 100644 --- a/butane_codegen/src/lib.rs +++ b/butane_codegen/src/lib.rs @@ -5,13 +5,14 @@ #![deny(missing_docs)] extern crate proc_macro; +use std::path::PathBuf; + use butane_core::migrations::adb::{DeferredSqlType, TypeIdentifier}; use butane_core::{codegen, make_compile_error, migrations, SqlType}; use proc_macro::TokenStream; use proc_macro2::TokenStream as TokenStream2; use proc_macro2::TokenTree; use quote::quote; -use std::path::PathBuf; use syn::{Expr, Ident}; mod filter; diff --git a/butane_core/src/codegen/dbobj.rs b/butane_core/src/codegen/dbobj.rs index a9d8f116..c8835501 100644 --- a/butane_core/src/codegen/dbobj.rs +++ b/butane_core/src/codegen/dbobj.rs @@ -1,11 +1,12 @@ -use super::*; -use crate::migrations::adb::{DeferredSqlType, TypeIdentifier}; -use crate::SqlType; use proc_macro2::TokenStream as TokenStream2; use proc_macro2::{Ident, Span}; use quote::{quote, quote_spanned}; use syn::{spanned::Spanned, Field, ItemStruct}; +use super::*; +use crate::migrations::adb::{DeferredSqlType, TypeIdentifier}; +use crate::SqlType; + // Configuration that can be specified with attributes to override default behavior #[derive(Clone, Debug, Default)] pub struct Config { diff --git a/butane_core/src/codegen/migration.rs b/butane_core/src/codegen/migration.rs index fa077218..c5cdad37 100644 --- a/butane_core/src/codegen/migration.rs +++ b/butane_core/src/codegen/migration.rs @@ -1,8 +1,9 @@ +use syn::{Field, ItemStruct}; + use super::*; use crate::migrations::adb::{AColumn, ATable}; use crate::migrations::{MigrationMut, MigrationsMut}; use crate::Result; -use syn::{Field, ItemStruct}; pub fn write_table_to_disk( ms: &mut impl MigrationsMut, diff --git a/butane_core/src/codegen/mod.rs b/butane_core/src/codegen/mod.rs index 55008862..3214f19a 100644 --- a/butane_core/src/codegen/mod.rs +++ b/butane_core/src/codegen/mod.rs @@ -1,8 +1,5 @@ //! Code-generation backend -use crate::migrations::adb::{DeferredSqlType, TypeIdentifier, TypeKey}; -use crate::migrations::{MigrationMut, MigrationsMut}; -use crate::{SqlType, SqlVal}; use proc_macro2::TokenStream as TokenStream2; use proc_macro2::{Ident, Span, TokenTree}; use quote::{quote, ToTokens}; @@ -13,6 +10,10 @@ use syn::{ MetaNameValue, }; +use crate::migrations::adb::{DeferredSqlType, TypeIdentifier, TypeKey}; +use crate::migrations::{MigrationMut, MigrationsMut}; +use crate::{SqlType, SqlVal}; + const OPTION_TYNAMES: [&str; 2] = ["Option", "std::option::Option"]; const MANY_TYNAMES: [&str; 2] = ["Many", "butane::Many"]; const FKEY_TYNAMES: [&str; 2] = ["ForeignKey", "butane::ForeignKey"]; diff --git a/butane_core/src/custom.rs b/butane_core/src/custom.rs index 40c1ac60..00d8a2e6 100644 --- a/butane_core/src/custom.rs +++ b/butane_core/src/custom.rs @@ -5,9 +5,10 @@ //! source repository. Not supported for the Sqlite backend as Sqlite //! supports a very limited set of types to begin with. -use serde::{Deserialize, Serialize}; use std::fmt; +use serde::{Deserialize, Serialize}; + /// For use with [SqlType::Custom](crate::SqlType) #[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)] pub enum SqlTypeCustom { diff --git a/butane_core/src/db/connmethods.rs b/butane_core/src/db/connmethods.rs index 71cf74dc..eb3d3ad7 100644 --- a/butane_core/src/db/connmethods.rs +++ b/butane_core/src/db/connmethods.rs @@ -1,11 +1,12 @@ //! Not expected to be called directly by most users. Used by code //! generated by `#[model]`, `query!`, and other macros. -use crate::query::{BoolExpr, Expr, Order}; -use crate::{Result, SqlType, SqlVal, SqlValRef}; use std::ops::{Deref, DerefMut}; use std::vec::Vec; +use crate::query::{BoolExpr, Expr, Order}; +use crate::{Result, SqlType, SqlVal, SqlValRef}; + /// Methods available on a database connection. Most users do not need /// to call these methods directly and will instead use methods on /// [DataObject][crate::DataObject] or the `query!` macro. This trait is diff --git a/butane_core/src/db/helper.rs b/butane_core/src/db/helper.rs index 0b4a0269..948d38b2 100644 --- a/butane_core/src/db/helper.rs +++ b/butane_core/src/db/helper.rs @@ -3,17 +3,18 @@ // may occur if no backends are selected #![allow(unused)] +use std::borrow::Cow; +use std::fmt::Write; + +#[cfg(feature = "datetime")] +use chrono::naive::NaiveDateTime; + use super::Column; use crate::migrations::adb::{AColumn, TypeIdentifier}; use crate::query::Expr::{Condition, Placeholder, Val}; use crate::query::{BoolExpr::*, Expr, Join, Order, OrderDirection}; use crate::Error; use crate::{query, Result, SqlType, SqlVal}; -use std::borrow::Cow; -use std::fmt::Write; - -#[cfg(feature = "datetime")] -use chrono::naive::NaiveDateTime; pub trait PlaceholderSource { fn next_placeholder(&mut self) -> Cow; diff --git a/butane_core/src/db/mod.rs b/butane_core/src/db/mod.rs index 94157222..3dbed5a0 100644 --- a/butane_core/src/db/mod.rs +++ b/butane_core/src/db/mod.rs @@ -12,9 +12,6 @@ //! what a `BackendConnection` can do, but allows using a single concrete type that is not tied to a particular //! database backend. It is returned by the `connect` method. -use crate::query::BoolExpr; -use crate::{migrations::adb, Error, Result, SqlVal, SqlValRef}; -use serde::{Deserialize, Serialize}; use std::borrow::Cow; use std::fmt::Debug; use std::fs; @@ -22,6 +19,11 @@ use std::io::Write; use std::ops::{Deref, DerefMut}; use std::path::Path; +use serde::{Deserialize, Serialize}; + +use crate::query::BoolExpr; +use crate::{migrations::adb, Error, Result, SqlVal, SqlValRef}; + mod connmethods; mod helper; mod macros; @@ -32,16 +34,15 @@ pub mod sqlite; #[cfg(feature = "r2d2")] pub mod r2; +pub use connmethods::{ + BackendRow, BackendRows, Column, ConnectionMethods, MapDeref, QueryResult, RawQueryResult, +}; #[cfg(feature = "r2d2")] pub use r2::ConnectionManager; // Macros are always exported at the root of the crate use crate::connection_method_wrapper; -pub use connmethods::{ - BackendRow, BackendRows, Column, ConnectionMethods, MapDeref, QueryResult, RawQueryResult, -}; - /// Database connection. pub trait BackendConnection: ConnectionMethods + Debug + Send + 'static { /// Begin a database transaction. The transaction object must be diff --git a/butane_core/src/db/pg.rs b/butane_core/src/db/pg.rs index 20dded9f..842afa01 100644 --- a/butane_core/src/db/pg.rs +++ b/butane_core/src/db/pg.rs @@ -1,4 +1,13 @@ //! Postgresql database backend +use std::cell::RefCell; +use std::fmt::Write; + +use bytes::BufMut; +#[cfg(feature = "datetime")] +use chrono::NaiveDateTime; +use postgres::fallible_iterator::FallibleIterator; +use postgres::GenericClient; + use super::connmethods::VecRows; use super::helper; use super::*; @@ -6,13 +15,6 @@ use crate::custom::{SqlTypeCustom, SqlValRefCustom}; use crate::migrations::adb::{AColumn, ATable, Operation, TypeIdentifier, ADB}; use crate::{debug, query}; use crate::{Result, SqlType, SqlVal, SqlValRef}; -use bytes::BufMut; -#[cfg(feature = "datetime")] -use chrono::NaiveDateTime; -use postgres::fallible_iterator::FallibleIterator; -use postgres::GenericClient; -use std::cell::RefCell; -use std::fmt::Write; /// The name of the postgres backend. pub const BACKEND_NAME: &str = "pg"; diff --git a/butane_core/src/db/r2.rs b/butane_core/src/db/r2.rs index e99afff5..e5f5a61f 100644 --- a/butane_core/src/db/r2.rs +++ b/butane_core/src/db/r2.rs @@ -1,7 +1,8 @@ +pub use r2d2::ManageConnection; + use super::connmethods::ConnectionMethodWrapper; use super::*; use crate::Result; -pub use r2d2::ManageConnection; /// R2D2 support for Butane. Implements [`r2d2::ManageConnection`]. #[derive(Clone, Debug)] diff --git a/butane_core/src/db/sqlite.rs b/butane_core/src/db/sqlite.rs index 46869a58..13a63ab9 100644 --- a/butane_core/src/db/sqlite.rs +++ b/butane_core/src/db/sqlite.rs @@ -1,7 +1,15 @@ //! SQLite database backend +use std::borrow::Cow; +use std::fmt::Write; +use std::pin::Pin; #[cfg(feature = "log")] use std::sync::Once; +#[cfg(feature = "datetime")] +use chrono::naive::NaiveDateTime; +use fallible_streaming_iterator::FallibleStreamingIterator; +use pin_project::pin_project; + use super::helper; use super::*; use crate::db::connmethods::BackendRows; @@ -10,13 +18,6 @@ use crate::migrations::adb::{AColumn, ATable, Operation, TypeIdentifier, ADB}; use crate::query; use crate::query::Order; use crate::{Result, SqlType, SqlVal, SqlValRef}; -#[cfg(feature = "datetime")] -use chrono::naive::NaiveDateTime; -use fallible_streaming_iterator::FallibleStreamingIterator; -use pin_project::pin_project; -use std::borrow::Cow; -use std::fmt::Write; -use std::pin::Pin; #[cfg(feature = "datetime")] const SQLITE_DT_FORMAT: &str = "%Y-%m-%d %H:%M:%S"; diff --git a/butane_core/src/fkey.rs b/butane_core/src/fkey.rs index 5ca011b2..b7ba4479 100644 --- a/butane_core/src/fkey.rs +++ b/butane_core/src/fkey.rs @@ -1,14 +1,15 @@ //! Implementation of foreign key relationships between models. #![deny(missing_docs)] -use crate::db::ConnectionMethods; -use crate::*; -use once_cell::unsync::OnceCell; -use serde::{Deserialize, Deserializer, Serialize, Serializer}; use std::borrow::Cow; use std::fmt::{Debug, Formatter}; #[cfg(feature = "fake")] use fake::{Dummy, Faker}; +use once_cell::unsync::OnceCell; +use serde::{Deserialize, Deserializer, Serialize, Serializer}; + +use crate::db::ConnectionMethods; +use crate::*; /// Used to implement a relationship between models. /// diff --git a/butane_core/src/lib.rs b/butane_core/src/lib.rs index 1d75c77c..ecf3a28a 100644 --- a/butane_core/src/lib.rs +++ b/butane_core/src/lib.rs @@ -1,9 +1,10 @@ #![allow(clippy::iter_nth_zero)] #![allow(clippy::upper_case_acronyms)] //grandfathered, not going to break API to rename -use serde::{Deserialize, Serialize}; use std::borrow::Borrow; use std::cmp::{Eq, PartialEq}; use std::default::Default; + +use serde::{Deserialize, Serialize}; use thiserror::Error as ThisError; pub mod codegen; @@ -18,12 +19,10 @@ pub mod sqlval; #[cfg(feature = "uuid")] pub mod uuid; +use custom::SqlTypeCustom; +use db::{BackendRow, Column, ConnectionMethods}; #[cfg(feature = "fake")] use fake::{Dummy, Faker}; - -use db::{BackendRow, Column, ConnectionMethods}; - -use custom::SqlTypeCustom; pub use query::Query; pub use sqlval::*; diff --git a/butane_core/src/many.rs b/butane_core/src/many.rs index 5f881b17..5a2cb05a 100644 --- a/butane_core/src/many.rs +++ b/butane_core/src/many.rs @@ -1,14 +1,15 @@ //! Implementation of many-to-many relationships between models. #![deny(missing_docs)] -use crate::db::{Column, ConnectionMethods}; -use crate::query::{BoolExpr, Expr, OrderDirection, Query}; -use crate::{DataObject, Error, FieldType, Result, SqlType, SqlVal, ToSql}; -use once_cell::unsync::OnceCell; -use serde::{Deserialize, Serialize}; use std::borrow::Cow; #[cfg(feature = "fake")] use fake::{Dummy, Faker}; +use once_cell::unsync::OnceCell; +use serde::{Deserialize, Serialize}; + +use crate::db::{Column, ConnectionMethods}; +use crate::query::{BoolExpr, Expr, OrderDirection, Query}; +use crate::{DataObject, Error, FieldType, Result, SqlType, SqlVal, ToSql}; fn default_oc() -> OnceCell> { OnceCell::default() diff --git a/butane_core/src/migrations/adb.rs b/butane_core/src/migrations/adb.rs index 553d443e..67c112bc 100644 --- a/butane_core/src/migrations/adb.rs +++ b/butane_core/src/migrations/adb.rs @@ -2,11 +2,13 @@ //! CLI tool, there is no need to use this module. Even if applying //! migrations without this tool, you are unlikely to need this module. -use crate::{Error, Result, SqlType, SqlVal}; -use serde::{de::Deserializer, de::Visitor, ser::Serializer, Deserialize, Serialize}; use std::cmp::Ordering; use std::collections::{HashMap, HashSet}; +use serde::{de::Deserializer, de::Visitor, ser::Serializer, Deserialize, Serialize}; + +use crate::{Error, Result, SqlType, SqlVal}; + /// Identifier for a type as used in a database column. Supports both /// [SqlType](crate::SqlType) and identifiers known only by name. The /// latter is used for custom types. `SqlType::Custom` cannot easily be used diff --git a/butane_core/src/migrations/fsmigrations.rs b/butane_core/src/migrations/fsmigrations.rs index f4eed768..022b7139 100644 --- a/butane_core/src/migrations/fsmigrations.rs +++ b/butane_core/src/migrations/fsmigrations.rs @@ -1,17 +1,18 @@ -use super::adb::{ATable, DeferredSqlType, TypeKey, ADB}; -use super::fs::{Filesystem, OsFilesystem}; -use super::{Migration, MigrationMut, Migrations, MigrationsMut}; -use crate::{ConnectionMethods, DataObject, Result}; -use fs2::FileExt; -use serde::{Deserialize, Serialize}; use std::borrow::Cow; use std::collections::BTreeMap; use std::fs::{File, OpenOptions}; - use std::io::{Read, Write}; use std::path::{Path, PathBuf}; use std::rc::Rc; +use fs2::FileExt; +use serde::{Deserialize, Serialize}; + +use super::adb::{ATable, DeferredSqlType, TypeKey, ADB}; +use super::fs::{Filesystem, OsFilesystem}; +use super::{Migration, MigrationMut, Migrations, MigrationsMut}; +use crate::{ConnectionMethods, DataObject, Result}; + type SqlTypeMap = BTreeMap; const TYPES_FILENAME: &str = "types.json"; diff --git a/butane_core/src/migrations/memmigrations.rs b/butane_core/src/migrations/memmigrations.rs index cd28871b..76102325 100644 --- a/butane_core/src/migrations/memmigrations.rs +++ b/butane_core/src/migrations/memmigrations.rs @@ -1,10 +1,12 @@ +use std::borrow::Cow; +use std::collections::HashMap; + +use serde::{Deserialize, Serialize}; + use super::adb::{ATable, DeferredSqlType, TypeKey, ADB}; use super::{ButaneMigration, Migration, MigrationMut, Migrations, MigrationsMut}; use crate::query::BoolExpr; use crate::{ConnectionMethods, DataObject, Result}; -use serde::{Deserialize, Serialize}; -use std::borrow::Cow; -use std::collections::HashMap; /// A migration stored in memory. #[derive(Clone, Debug, Deserialize, Serialize)] diff --git a/butane_core/src/migrations/migration.rs b/butane_core/src/migrations/migration.rs index e00a525c..ac6240f4 100644 --- a/butane_core/src/migrations/migration.rs +++ b/butane_core/src/migrations/migration.rs @@ -1,11 +1,12 @@ +use std::borrow::Cow; +use std::cmp::PartialEq; +use std::fmt::Debug; + use super::adb::{ATable, DeferredSqlType, TypeKey, ADB}; use super::ButaneMigration; use crate::db::ConnectionMethods; use crate::query::{BoolExpr, Expr}; use crate::{db, sqlval::ToSql, DataObject, DataResult, Error, Result}; -use std::borrow::Cow; -use std::cmp::PartialEq; -use std::fmt::Debug; /// Type representing a database migration. A migration describes how /// to bring the database from state A to state B. In general, the diff --git a/butane_core/src/migrations/mod.rs b/butane_core/src/migrations/mod.rs index 2fef93c8..3b6eea44 100644 --- a/butane_core/src/migrations/mod.rs +++ b/butane_core/src/migrations/mod.rs @@ -1,13 +1,14 @@ //! For working with migrations. If using the butane CLI tool, it is //! not necessary to use these types directly. +use std::path::Path; + +use fallible_iterator::FallibleIterator; + use crate::db::BackendRows; use crate::db::{Column, ConnectionMethods}; use crate::sqlval::{FromSql, SqlValRef, ToSql}; use crate::{db, query, DataObject, DataResult, Error, Result, SqlType}; -use fallible_iterator::FallibleIterator; -use std::path::Path; - pub mod adb; use adb::{AColumn, ATable, DeferredSqlType, Operation, TypeIdentifier, ADB}; diff --git a/butane_core/src/query/fieldexpr.rs b/butane_core/src/query/fieldexpr.rs index 2eebde7c..0f077fe0 100644 --- a/butane_core/src/query/fieldexpr.rs +++ b/butane_core/src/query/fieldexpr.rs @@ -1,12 +1,13 @@ //! Not expected to be used directly. +use std::borrow::{Borrow, Cow}; +use std::cmp::{PartialEq, PartialOrd}; +use std::marker::PhantomData; + use crate::fkey::ForeignKey; use crate::query::{BoolExpr, Column, Expr, Join}; use crate::sqlval::{FieldType, SqlVal, ToSql}; use crate::DataObject; -use std::borrow::{Borrow, Cow}; -use std::cmp::{PartialEq, PartialOrd}; -use std::marker::PhantomData; macro_rules! binary_op { ($func_name:ident, $bound:path, $cond:ident) => { diff --git a/butane_core/src/query/mod.rs b/butane_core/src/query/mod.rs index 6a38b568..6eea949e 100644 --- a/butane_core/src/query/mod.rs +++ b/butane_core/src/query/mod.rs @@ -2,12 +2,14 @@ //! the `query!`, `filter!`, and `find!` macros instead of using this //! module directly. -use crate::db::{BackendRows, ConnectionMethods, QueryResult}; -use crate::{DataResult, Result, SqlVal}; -use fallible_iterator::FallibleIterator; use std::borrow::Cow; use std::marker::PhantomData; +use fallible_iterator::FallibleIterator; + +use crate::db::{BackendRows, ConnectionMethods, QueryResult}; +use crate::{DataResult, Result, SqlVal}; + mod fieldexpr; pub use fieldexpr::{DataOrd, FieldExpr, ManyFieldExpr}; diff --git a/butane_core/src/sqlval.rs b/butane_core/src/sqlval.rs index c0a764f4..21ab2b72 100644 --- a/butane_core/src/sqlval.rs +++ b/butane_core/src/sqlval.rs @@ -1,18 +1,18 @@ //! Types and traits for interacting with a value that can be stored in the database. -use crate::custom::{SqlValCustom, SqlValRefCustom}; -use crate::{DataObject, Error::CannotConvertSqlVal, Result, SqlType}; -use serde::{Deserialize, Serialize}; use std::borrow::Cow; #[cfg(feature = "json")] use std::collections::HashMap; use std::fmt; -#[cfg(feature = "pg")] -use crate::custom::SqlTypeCustom; - #[cfg(feature = "datetime")] use chrono::{naive::NaiveDateTime, DateTime}; +use serde::{Deserialize, Serialize}; + +#[cfg(feature = "pg")] +use crate::custom::SqlTypeCustom; +use crate::custom::{SqlValCustom, SqlValRefCustom}; +use crate::{DataObject, Error::CannotConvertSqlVal, Result, SqlType}; #[derive(Clone, Debug)] pub enum SqlValRef<'a> { diff --git a/butane_core/src/uuid.rs b/butane_core/src/uuid.rs index afbac738..888e50de 100644 --- a/butane_core/src/uuid.rs +++ b/butane_core/src/uuid.rs @@ -1,11 +1,12 @@ //! Uuid support #![deny(missing_docs)] +use uuid::Uuid; + use crate::{ Error::CannotConvertSqlVal, FieldType, FromSql, PrimaryKeyType, Result, SqlType, SqlVal, SqlValRef, ToSql, }; -use uuid::Uuid; impl ToSql for Uuid { fn to_sql(&self) -> SqlVal { diff --git a/butane_core/tests/connection.rs b/butane_core/tests/connection.rs index e95fed43..b2f861c6 100644 --- a/butane_core/tests/connection.rs +++ b/butane_core/tests/connection.rs @@ -1,5 +1,4 @@ use butane_core::db::{connect, BackendConnection, Connection, ConnectionSpec}; - use butane_test_helper::*; fn connection_not_closed(conn: Connection) { diff --git a/butane_core/tests/transactions.rs b/butane_core/tests/transactions.rs index ff1ff179..c4369c71 100644 --- a/butane_core/tests/transactions.rs +++ b/butane_core/tests/transactions.rs @@ -1,5 +1,4 @@ use butane_core::db::{BackendConnection, Connection}; - use butane_test_helper::*; fn commit_empty_transaction(mut conn: Connection) { diff --git a/butane_test_helper/src/lib.rs b/butane_test_helper/src/lib.rs index 67e10ac5..8cbe6556 100644 --- a/butane_test_helper/src/lib.rs +++ b/butane_test_helper/src/lib.rs @@ -1,11 +1,12 @@ -use butane_core::db::{connect, get_backend, pg, sqlite, Backend, Connection, ConnectionSpec}; -use butane_core::migrations::{self, MemMigrations, Migration, Migrations, MigrationsMut}; -use once_cell::sync::Lazy; use std::io::{BufRead, BufReader, Read, Write}; use std::ops::Deref; use std::path::PathBuf; use std::process::{ChildStderr, Command, Stdio}; use std::sync::Mutex; + +use butane_core::db::{connect, get_backend, pg, sqlite, Backend, Connection, ConnectionSpec}; +use butane_core::migrations::{self, MemMigrations, Migration, Migrations, MigrationsMut}; +use once_cell::sync::Lazy; use uuid::Uuid; pub fn pg_connection() -> (Connection, PgSetupData) { diff --git a/example/src/main.rs b/example/src/main.rs index bd9d6e7e..ee85f24b 100644 --- a/example/src/main.rs +++ b/example/src/main.rs @@ -1,13 +1,12 @@ #![allow(dead_code)] use butane::db::{Connection, ConnectionSpec}; use butane::model; +use butane::prelude::*; use butane::Error; use butane::ObjectState; use butane::{find, query}; use butane::{ForeignKey, Many}; -use butane::prelude::*; - pub type Result = std::result::Result; #[model] diff --git a/examples/getting_started/src/bin/delete_post.rs b/examples/getting_started/src/bin/delete_post.rs index dc979464..d2705d64 100644 --- a/examples/getting_started/src/bin/delete_post.rs +++ b/examples/getting_started/src/bin/delete_post.rs @@ -1,7 +1,9 @@ -use self::models::Post; +use std::env::args; + use butane::query; use getting_started::*; -use std::env::args; + +use self::models::Post; fn main() { let target = args().nth(1).expect("Expected a target to match against"); diff --git a/examples/getting_started/src/bin/publish_post.rs b/examples/getting_started/src/bin/publish_post.rs index 0a8df84b..8c886324 100644 --- a/examples/getting_started/src/bin/publish_post.rs +++ b/examples/getting_started/src/bin/publish_post.rs @@ -1,8 +1,10 @@ #![allow(clippy::expect_fun_call)] -use self::models::Post; +use std::env::args; + use butane::prelude::*; use getting_started::*; -use std::env::args; + +use self::models::Post; fn main() { let id = args() diff --git a/examples/getting_started/src/bin/write_post.rs b/examples/getting_started/src/bin/write_post.rs index 6bdf6259..ad58b7cf 100644 --- a/examples/getting_started/src/bin/write_post.rs +++ b/examples/getting_started/src/bin/write_post.rs @@ -1,6 +1,7 @@ -use getting_started::*; use std::io::{stdin, Read}; +use getting_started::*; + fn main() { let conn = establish_connection();