Skip to content

Commit a135dde

Browse files
committed
Apply cargo fmt for Rust 2024 edition import ordering
1 parent 8279ca7 commit a135dde

13 files changed

Lines changed: 52 additions & 68 deletions

File tree

crates/oxide-sql-core/examples/invoicing.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
//!
99
//! Run with: cargo run --example invoicing
1010
11-
use oxide_sql_core::builder::{col, Select};
11+
use oxide_sql_core::builder::{Select, col};
1212
use oxide_sql_derive::Table;
1313

1414
// =============================================================================

crates/oxide-sql-core/src/builder/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,13 @@ pub mod value;
5959

6060
// Dynamic (string-based) builders
6161
pub use delete::{DeleteDyn, SafeDeleteDyn, SafeDeleteDynWithWhere};
62-
pub use expr::{dyn_col, ColumnRef, ExprBuilder};
62+
pub use expr::{ColumnRef, ExprBuilder, dyn_col};
6363
pub use insert::InsertDyn;
6464
pub use select::SelectDyn;
6565
pub use update::UpdateDyn;
6666

6767
// Type-safe builders (recommended - these are the default names)
68-
pub use typed::{col, Delete, Insert, Select, Update};
68+
pub use typed::{Delete, Insert, Select, Update, col};
6969

7070
// Common types
7171
pub use value::{SqlValue, ToSqlValue};

crates/oxide-sql-core/src/lib.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -555,11 +555,10 @@ pub mod schema;
555555

556556
pub use ast::{Expr, Statement};
557557
pub use builder::{
558-
col, dyn_col, Delete, DeleteDyn, Insert, InsertDyn, Select, SelectDyn, Update, UpdateDyn,
558+
Delete, DeleteDyn, Insert, InsertDyn, Select, SelectDyn, Update, UpdateDyn, col, dyn_col,
559559
};
560560
pub use lexer::{Lexer, Token, TokenKind};
561561
pub use parser::{ParseError, Parser};
562562
pub use schema::{
563-
Column, ColumnSchema, RustTypeMapping, Selectable, Table,
564-
TableSchema, TypedColumn,
563+
Column, ColumnSchema, RustTypeMapping, Selectable, Table, TableSchema, TypedColumn,
565564
};

crates/oxide-sql-core/src/migrations/dialect/duckdb.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ use super::MigrationDialect;
44
use crate::ast::DataType;
55
use crate::migrations::column_builder::{ColumnDefinition, DefaultValue};
66
use crate::migrations::operation::{
7-
AlterColumnChange, AlterColumnOp, CreateTableOp, DropIndexOp,
8-
RenameColumnOp, RenameTableOp,
7+
AlterColumnChange, AlterColumnOp, CreateTableOp, DropIndexOp, RenameColumnOp, RenameTableOp,
98
};
109
use crate::schema::RustTypeMapping;
1110

@@ -266,9 +265,7 @@ impl RustTypeMapping for DuckDbDialect {
266265
"bool" => DataType::Boolean,
267266
"i8" | "i16" | "u8" | "u16" => DataType::Smallint,
268267
"i32" | "u32" => DataType::Integer,
269-
"i64" | "u64" | "i128" | "u128" | "isize" | "usize" => {
270-
DataType::Bigint
271-
}
268+
"i64" | "u64" | "i128" | "u128" | "isize" | "usize" => DataType::Bigint,
272269
"f32" => DataType::Real,
273270
"f64" => DataType::Double,
274271
"String" => DataType::Varchar(None),

crates/oxide-sql-core/src/migrations/dialect/postgres.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ use super::MigrationDialect;
44
use crate::ast::DataType;
55
use crate::migrations::column_builder::{ColumnDefinition, DefaultValue};
66
use crate::migrations::operation::{
7-
AlterColumnChange, AlterColumnOp, DropIndexOp, RenameColumnOp,
8-
RenameTableOp,
7+
AlterColumnChange, AlterColumnOp, DropIndexOp, RenameColumnOp, RenameTableOp,
98
};
109
use crate::schema::RustTypeMapping;
1110

@@ -225,9 +224,7 @@ impl RustTypeMapping for PostgresDialect {
225224
"bool" => DataType::Boolean,
226225
"i8" | "i16" | "u8" | "u16" => DataType::Smallint,
227226
"i32" | "u32" => DataType::Integer,
228-
"i64" | "u64" | "i128" | "u128" | "isize" | "usize" => {
229-
DataType::Bigint
230-
}
227+
"i64" | "u64" | "i128" | "u128" | "isize" | "usize" => DataType::Bigint,
231228
"f32" => DataType::Real,
232229
"f64" => DataType::Double,
233230
"String" => DataType::Varchar(Some(255)),

crates/oxide-sql-core/src/migrations/dialect/sqlite.rs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
use super::MigrationDialect;
44
use crate::ast::DataType;
55
use crate::migrations::operation::{
6-
AlterColumnChange, AlterColumnOp, DropIndexOp, RenameColumnOp,
7-
RenameTableOp,
6+
AlterColumnChange, AlterColumnOp, DropIndexOp, RenameColumnOp, RenameTableOp,
87
};
98
use crate::schema::RustTypeMapping;
109

@@ -126,12 +125,8 @@ impl RustTypeMapping for SqliteDialect {
126125
fn map_type(&self, rust_type: &str) -> DataType {
127126
match rust_type {
128127
"bool" => DataType::Integer,
129-
"i8" | "i16" | "u8" | "u16" | "i32" | "u32" => {
130-
DataType::Integer
131-
}
132-
"i64" | "u64" | "i128" | "u128" | "isize" | "usize" => {
133-
DataType::Bigint
134-
}
128+
"i8" | "i16" | "u8" | "u16" | "i32" | "u32" => DataType::Integer,
129+
"i64" | "u64" | "i128" | "u128" | "isize" | "usize" => DataType::Bigint,
135130
"f32" => DataType::Real,
136131
"f64" => DataType::Double,
137132
"String" => DataType::Text,

crates/oxide-sql-core/src/migrations/migration.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -379,12 +379,14 @@ mod tests {
379379
impl Migration for Migration0001 {
380380
const ID: &'static str = "0001_initial";
381381
fn up() -> Vec<Operation> {
382-
vec![CreateTableBuilder::new()
383-
.name("users")
384-
.column(bigint("id").primary_key().autoincrement().build())
385-
.column(varchar("username", 255).not_null().build())
386-
.build()
387-
.into()]
382+
vec![
383+
CreateTableBuilder::new()
384+
.name("users")
385+
.column(bigint("id").primary_key().autoincrement().build())
386+
.column(varchar("username", 255).not_null().build())
387+
.build()
388+
.into(),
389+
]
388390
}
389391
fn down() -> Vec<Operation> {
390392
vec![Operation::drop_table("users")]

crates/oxide-sql-core/src/migrations/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@ mod state;
4848
mod table_builder;
4949

5050
pub use column_builder::{
51-
bigint, binary, blob, boolean, char, date, datetime, decimal, double, integer, numeric, real,
52-
smallint, text, time, timestamp, varbinary, varchar, ColumnBuilder, ColumnDefinition,
53-
DefaultValue, ForeignKeyRef,
51+
ColumnBuilder, ColumnDefinition, DefaultValue, ForeignKeyRef, bigint, binary, blob, boolean,
52+
char, date, datetime, decimal, double, integer, numeric, real, smallint, text, time, timestamp,
53+
varbinary, varchar,
5454
};
5555
pub use dialect::{DuckDbDialect, MigrationDialect, PostgresDialect, SqliteDialect};
5656
pub use migration::{Migration, MigrationRunner, MigrationStatus};

crates/oxide-sql-core/src/migrations/operation.rs

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -173,24 +173,19 @@ pub struct CreateTableOp {
173173
impl CreateTableOp {
174174
/// Builds a `CreateTableOp` from a `#[derive(Table)]` struct
175175
/// using the given dialect for Rust-to-SQL type mapping.
176-
pub fn from_table<T: TableSchema>(
177-
dialect: &impl RustTypeMapping,
178-
) -> Self {
176+
pub fn from_table<T: TableSchema>(dialect: &impl RustTypeMapping) -> Self {
179177
let columns = T::SCHEMA
180178
.iter()
181179
.map(|col| {
182180
let inner = strip_option(col.rust_type);
183181
let data_type = dialect.map_type(inner);
184-
let mut def =
185-
ColumnDefinition::new(col.name, data_type);
182+
let mut def = ColumnDefinition::new(col.name, data_type);
186183
def.nullable = col.nullable;
187184
def.primary_key = col.primary_key;
188185
def.unique = col.unique;
189186
def.autoincrement = col.autoincrement;
190187
if let Some(expr) = col.default_expr {
191-
def.default = Some(
192-
DefaultValue::Expression(expr.to_string()),
193-
);
188+
def.default = Some(DefaultValue::Expression(expr.to_string()));
194189
}
195190
def
196191
})
@@ -204,9 +199,7 @@ impl CreateTableOp {
204199
}
205200

206201
/// Same as `from_table` but with `IF NOT EXISTS`.
207-
pub fn from_table_if_not_exists<T: TableSchema>(
208-
dialect: &impl RustTypeMapping,
209-
) -> Self {
202+
pub fn from_table_if_not_exists<T: TableSchema>(dialect: &impl RustTypeMapping) -> Self {
210203
let mut op = Self::from_table::<T>(dialect);
211204
op.if_not_exists = true;
212205
op
@@ -493,7 +486,7 @@ impl From<RawSqlOp> for Operation {
493486
#[cfg(test)]
494487
mod tests {
495488
use super::*;
496-
use crate::migrations::column_builder::{bigint, varchar, ForeignKeyAction};
489+
use crate::migrations::column_builder::{ForeignKeyAction, bigint, varchar};
497490

498491
#[test]
499492
fn test_drop_table_operation() {

crates/oxide-sql-core/tests/derive_table.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@
88
99
use oxide_sql_core::ast::DataType;
1010
use oxide_sql_core::migrations::{
11-
CreateTableOp, DefaultValue, DuckDbDialect, MigrationDialect,
12-
PostgresDialect, SqliteDialect,
11+
CreateTableOp, DefaultValue, DuckDbDialect, MigrationDialect, PostgresDialect, SqliteDialect,
1312
};
1413
use oxide_sql_core::schema::{Column, Table, TableSchema};
1514
use oxide_sql_derive::Table;
@@ -526,10 +525,7 @@ fn test_from_table_duckdb() {
526525
#[test]
527526
fn test_from_table_if_not_exists() {
528527
let dialect = SqliteDialect::new();
529-
let op =
530-
CreateTableOp::from_table_if_not_exists::<UserFullTable>(
531-
&dialect,
532-
);
528+
let op = CreateTableOp::from_table_if_not_exists::<UserFullTable>(&dialect);
533529
assert!(op.if_not_exists);
534530
assert_eq!(op.name, "users_full");
535531
}

0 commit comments

Comments
 (0)