Skip to content

Commit 0a55556

Browse files
committed
feat(code): change function return types to use "diesel::" prefix"
and remove explicit import
1 parent 0008e4d commit 0a55556

File tree

35 files changed

+154
-192
lines changed

35 files changed

+154
-192
lines changed

src/code.rs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,7 @@ fn build_table_fns(
482482
buffer.push_str(&format!(
483483
r##"
484484
/// Insert a new row into `{table_name}` with a given [`{create_struct_identifier}`]
485-
pub{async_keyword} fn create(db: &mut ConnectionType, item: &{create_struct_identifier}) -> QueryResult<Self> {{
485+
pub{async_keyword} fn create(db: &mut ConnectionType, item: &{create_struct_identifier}) -> diesel::QueryResult<Self> {{
486486
use {schema_path}{table_name}::dsl::*;
487487
488488
diesel::insert_into({table_name}).values(item).get_result::<Self>(db){await_keyword}
@@ -493,7 +493,7 @@ fn build_table_fns(
493493
buffer.push_str(&format!(
494494
r##"
495495
/// Insert a new row into `{table_name}` with all default values
496-
pub{async_keyword} fn create(db: &mut ConnectionType) -> QueryResult<Self> {{
496+
pub{async_keyword} fn create(db: &mut ConnectionType) -> diesel::QueryResult<Self> {{
497497
use {schema_path}{table_name}::dsl::*;
498498
499499
diesel::insert_into({table_name}).default_values().get_result::<Self>(db){await_keyword}
@@ -513,7 +513,7 @@ fn build_table_fns(
513513
buffer.push_str(&format!(
514514
r##"
515515
/// Get a row from `{table_name}`, identified by the primary {key_maybe_multiple}
516-
pub{async_keyword} fn read(db: &mut ConnectionType, {item_id_params}) -> QueryResult<Self> {{
516+
pub{async_keyword} fn read(db: &mut ConnectionType, {item_id_params}) -> diesel::QueryResult<Self> {{
517517
use {schema_path}{table_name}::dsl::*;
518518
519519
{table_name}.{item_id_filters}.first::<Self>(db){await_keyword}
@@ -523,7 +523,7 @@ fn build_table_fns(
523523

524524
buffer.push_str(&format!(r##"
525525
/// Paginates through the table where page is a 0-based index (i.e. page 0 is the first page)
526-
pub{async_keyword} fn paginate(db: &mut ConnectionType, page: i64, page_size: i64) -> QueryResult<PaginationResult<Self>> {{
526+
pub{async_keyword} fn paginate(db: &mut ConnectionType, page: i64, page_size: i64) -> diesel::QueryResult<PaginationResult<Self>> {{
527527
use {schema_path}{table_name}::dsl::*;
528528
529529
let page_size = if page_size < 1 {{ 1 }} else {{ page_size }};
@@ -552,7 +552,7 @@ fn build_table_fns(
552552

553553
buffer.push_str(&format!(r##"
554554
/// Update a row in `{table_name}`, identified by the primary {key_maybe_multiple} with [`{update_struct_identifier}`]
555-
pub{async_keyword} fn update(db: &mut ConnectionType, {item_id_params}, item: &{update_struct_identifier}) -> QueryResult<Self> {{
555+
pub{async_keyword} fn update(db: &mut ConnectionType, {item_id_params}, item: &{update_struct_identifier}) -> diesel::QueryResult<Self> {{
556556
use {schema_path}{table_name}::dsl::*;
557557
558558
diesel::update({table_name}.{item_id_filters}).set(item).get_result(db){await_keyword}
@@ -564,7 +564,7 @@ fn build_table_fns(
564564
buffer.push_str(&format!(
565565
r##"
566566
/// Delete a row in `{table_name}`, identified by the primary {key_maybe_multiple}
567-
pub{async_keyword} fn delete(db: &mut ConnectionType, {item_id_params}) -> QueryResult<usize> {{
567+
pub{async_keyword} fn delete(db: &mut ConnectionType, {item_id_params}) -> diesel::QueryResult<usize> {{
568568
use {schema_path}{table_name}::dsl::*;
569569
570570
diesel::delete({table_name}.{item_id_filters}).execute(db){await_keyword}
@@ -646,10 +646,6 @@ fn build_imports(table: &ParsedTableMacro, config: &GenerationConfig) -> String
646646
// no "::" because that is already included in the schema_path
647647
imports_vec.push(format!("use {}*;", config.schema_path));
648648

649-
if table_options.get_fns() {
650-
imports_vec.push("use diesel::QueryResult;".into());
651-
};
652-
653649
if config.once_common_structs || config.once_connection_type {
654650
imports_vec.push(format!("use {}common::*;", config.model_path));
655651
};

test/autogenerated_all/models/todos/generated.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
use crate::diesel::*;
44
use crate::schema::*;
5-
use diesel::QueryResult;
65

76
pub type ConnectionType = diesel::r2d2::PooledConnection<diesel::r2d2::ConnectionManager<diesel::pg::PgConnection>>;
87

@@ -41,21 +40,21 @@ pub struct PaginationResult<T> {
4140

4241
impl Todos {
4342
/// Insert a new row into `todos` with all default values
44-
pub fn create(db: &mut ConnectionType) -> QueryResult<Self> {
43+
pub fn create(db: &mut ConnectionType) -> diesel::QueryResult<Self> {
4544
use crate::schema::todos::dsl::*;
4645

4746
diesel::insert_into(todos).default_values().get_result::<Self>(db)
4847
}
4948

5049
/// Get a row from `todos`, identified by the primary key
51-
pub fn read(db: &mut ConnectionType, param_id: i32) -> QueryResult<Self> {
50+
pub fn read(db: &mut ConnectionType, param_id: i32) -> diesel::QueryResult<Self> {
5251
use crate::schema::todos::dsl::*;
5352

5453
todos.filter(id.eq(param_id)).first::<Self>(db)
5554
}
5655

5756
/// Paginates through the table where page is a 0-based index (i.e. page 0 is the first page)
58-
pub fn paginate(db: &mut ConnectionType, page: i64, page_size: i64) -> QueryResult<PaginationResult<Self>> {
57+
pub fn paginate(db: &mut ConnectionType, page: i64, page_size: i64) -> diesel::QueryResult<PaginationResult<Self>> {
5958
use crate::schema::todos::dsl::*;
6059

6160
let page_size = if page_size < 1 { 1 } else { page_size };
@@ -73,14 +72,14 @@ impl Todos {
7372
}
7473

7574
/// Update a row in `todos`, identified by the primary key with [`UpdateTodos`]
76-
pub fn update(db: &mut ConnectionType, param_id: i32, item: &UpdateTodos) -> QueryResult<Self> {
75+
pub fn update(db: &mut ConnectionType, param_id: i32, item: &UpdateTodos) -> diesel::QueryResult<Self> {
7776
use crate::schema::todos::dsl::*;
7877

7978
diesel::update(todos.filter(id.eq(param_id))).set(item).get_result(db)
8079
}
8180

8281
/// Delete a row in `todos`, identified by the primary key
83-
pub fn delete(db: &mut ConnectionType, param_id: i32) -> QueryResult<usize> {
82+
pub fn delete(db: &mut ConnectionType, param_id: i32) -> diesel::QueryResult<usize> {
8483
use crate::schema::todos::dsl::*;
8584

8685
diesel::delete(todos.filter(id.eq(param_id))).execute(db)

test/autogenerated_attributes/models/todos/generated.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
use crate::diesel::*;
44
use crate::schema::*;
5-
use diesel::QueryResult;
65

76
pub type ConnectionType = diesel::r2d2::PooledConnection<diesel::r2d2::ConnectionManager<diesel::pg::PgConnection>>;
87

@@ -49,21 +48,21 @@ pub struct PaginationResult<T> {
4948

5049
impl Todos {
5150
/// Insert a new row into `todos` with a given [`CreateTodos`]
52-
pub fn create(db: &mut ConnectionType, item: &CreateTodos) -> QueryResult<Self> {
51+
pub fn create(db: &mut ConnectionType, item: &CreateTodos) -> diesel::QueryResult<Self> {
5352
use crate::schema::todos::dsl::*;
5453

5554
diesel::insert_into(todos).values(item).get_result::<Self>(db)
5655
}
5756

5857
/// Get a row from `todos`, identified by the primary key
59-
pub fn read(db: &mut ConnectionType, param_id: i32) -> QueryResult<Self> {
58+
pub fn read(db: &mut ConnectionType, param_id: i32) -> diesel::QueryResult<Self> {
6059
use crate::schema::todos::dsl::*;
6160

6261
todos.filter(id.eq(param_id)).first::<Self>(db)
6362
}
6463

6564
/// Paginates through the table where page is a 0-based index (i.e. page 0 is the first page)
66-
pub fn paginate(db: &mut ConnectionType, page: i64, page_size: i64) -> QueryResult<PaginationResult<Self>> {
65+
pub fn paginate(db: &mut ConnectionType, page: i64, page_size: i64) -> diesel::QueryResult<PaginationResult<Self>> {
6766
use crate::schema::todos::dsl::*;
6867

6968
let page_size = if page_size < 1 { 1 } else { page_size };
@@ -81,14 +80,14 @@ impl Todos {
8180
}
8281

8382
/// Update a row in `todos`, identified by the primary key with [`UpdateTodos`]
84-
pub fn update(db: &mut ConnectionType, param_id: i32, item: &UpdateTodos) -> QueryResult<Self> {
83+
pub fn update(db: &mut ConnectionType, param_id: i32, item: &UpdateTodos) -> diesel::QueryResult<Self> {
8584
use crate::schema::todos::dsl::*;
8685

8786
diesel::update(todos.filter(id.eq(param_id))).set(item).get_result(db)
8887
}
8988

9089
/// Delete a row in `todos`, identified by the primary key
91-
pub fn delete(db: &mut ConnectionType, param_id: i32) -> QueryResult<usize> {
90+
pub fn delete(db: &mut ConnectionType, param_id: i32) -> diesel::QueryResult<usize> {
9291
use crate::schema::todos::dsl::*;
9392

9493
diesel::delete(todos.filter(id.eq(param_id))).execute(db)

test/autogenerated_primary_keys/models/todos/generated.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
use crate::diesel::*;
44
use crate::schema::*;
5-
use diesel::QueryResult;
65

76
pub type ConnectionType = diesel::r2d2::PooledConnection<diesel::r2d2::ConnectionManager<diesel::pg::PgConnection>>;
87

@@ -49,21 +48,21 @@ pub struct PaginationResult<T> {
4948

5049
impl Todos {
5150
/// Insert a new row into `todos` with a given [`CreateTodos`]
52-
pub fn create(db: &mut ConnectionType, item: &CreateTodos) -> QueryResult<Self> {
51+
pub fn create(db: &mut ConnectionType, item: &CreateTodos) -> diesel::QueryResult<Self> {
5352
use crate::schema::todos::dsl::*;
5453

5554
diesel::insert_into(todos).values(item).get_result::<Self>(db)
5655
}
5756

5857
/// Get a row from `todos`, identified by the primary key
59-
pub fn read(db: &mut ConnectionType, param_id: i32) -> QueryResult<Self> {
58+
pub fn read(db: &mut ConnectionType, param_id: i32) -> diesel::QueryResult<Self> {
6059
use crate::schema::todos::dsl::*;
6160

6261
todos.filter(id.eq(param_id)).first::<Self>(db)
6362
}
6463

6564
/// Paginates through the table where page is a 0-based index (i.e. page 0 is the first page)
66-
pub fn paginate(db: &mut ConnectionType, page: i64, page_size: i64) -> QueryResult<PaginationResult<Self>> {
65+
pub fn paginate(db: &mut ConnectionType, page: i64, page_size: i64) -> diesel::QueryResult<PaginationResult<Self>> {
6766
use crate::schema::todos::dsl::*;
6867

6968
let page_size = if page_size < 1 { 1 } else { page_size };
@@ -81,14 +80,14 @@ impl Todos {
8180
}
8281

8382
/// Update a row in `todos`, identified by the primary key with [`UpdateTodos`]
84-
pub fn update(db: &mut ConnectionType, param_id: i32, item: &UpdateTodos) -> QueryResult<Self> {
83+
pub fn update(db: &mut ConnectionType, param_id: i32, item: &UpdateTodos) -> diesel::QueryResult<Self> {
8584
use crate::schema::todos::dsl::*;
8685

8786
diesel::update(todos.filter(id.eq(param_id))).set(item).get_result(db)
8887
}
8988

9089
/// Delete a row in `todos`, identified by the primary key
91-
pub fn delete(db: &mut ConnectionType, param_id: i32) -> QueryResult<usize> {
90+
pub fn delete(db: &mut ConnectionType, param_id: i32) -> diesel::QueryResult<usize> {
9291
use crate::schema::todos::dsl::*;
9392

9493
diesel::delete(todos.filter(id.eq(param_id))).execute(db)

test/cleanup_generated_content/models/todos/generated.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
use crate::diesel::*;
44
use crate::schema::*;
5-
use diesel::QueryResult;
65

76
pub type ConnectionType = diesel::r2d2::PooledConnection<diesel::r2d2::ConnectionManager<diesel::pg::PgConnection>>;
87

@@ -65,21 +64,21 @@ pub struct PaginationResult<T> {
6564

6665
impl Todos {
6766
/// Insert a new row into `todos` with a given [`CreateTodos`]
68-
pub fn create(db: &mut ConnectionType, item: &CreateTodos) -> QueryResult<Self> {
67+
pub fn create(db: &mut ConnectionType, item: &CreateTodos) -> diesel::QueryResult<Self> {
6968
use crate::schema::todos::dsl::*;
7069

7170
diesel::insert_into(todos).values(item).get_result::<Self>(db)
7271
}
7372

7473
/// Get a row from `todos`, identified by the primary key
75-
pub fn read(db: &mut ConnectionType, param_id: i32) -> QueryResult<Self> {
74+
pub fn read(db: &mut ConnectionType, param_id: i32) -> diesel::QueryResult<Self> {
7675
use crate::schema::todos::dsl::*;
7776

7877
todos.filter(id.eq(param_id)).first::<Self>(db)
7978
}
8079

8180
/// Paginates through the table where page is a 0-based index (i.e. page 0 is the first page)
82-
pub fn paginate(db: &mut ConnectionType, page: i64, page_size: i64) -> QueryResult<PaginationResult<Self>> {
81+
pub fn paginate(db: &mut ConnectionType, page: i64, page_size: i64) -> diesel::QueryResult<PaginationResult<Self>> {
8382
use crate::schema::todos::dsl::*;
8483

8584
let page_size = if page_size < 1 { 1 } else { page_size };
@@ -97,14 +96,14 @@ impl Todos {
9796
}
9897

9998
/// Update a row in `todos`, identified by the primary key with [`UpdateTodos`]
100-
pub fn update(db: &mut ConnectionType, param_id: i32, item: &UpdateTodos) -> QueryResult<Self> {
99+
pub fn update(db: &mut ConnectionType, param_id: i32, item: &UpdateTodos) -> diesel::QueryResult<Self> {
101100
use crate::schema::todos::dsl::*;
102101

103102
diesel::update(todos.filter(id.eq(param_id))).set(item).get_result(db)
104103
}
105104

106105
/// Delete a row in `todos`, identified by the primary key
107-
pub fn delete(db: &mut ConnectionType, param_id: i32) -> QueryResult<usize> {
106+
pub fn delete(db: &mut ConnectionType, param_id: i32) -> diesel::QueryResult<usize> {
108107
use crate::schema::todos::dsl::*;
109108

110109
diesel::delete(todos.filter(id.eq(param_id))).execute(db)

test/create_update_bytes_cow/models/todos/generated.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
use crate::diesel::*;
44
use crate::schema::*;
5-
use diesel::QueryResult;
65

76
pub type ConnectionType = diesel::r2d2::PooledConnection<diesel::r2d2::ConnectionManager<diesel::pg::PgConnection>>;
87

@@ -51,21 +50,21 @@ pub struct PaginationResult<T> {
5150

5251
impl Todos {
5352
/// Insert a new row into `todos` with a given [`CreateTodos`]
54-
pub fn create(db: &mut ConnectionType, item: &CreateTodos) -> QueryResult<Self> {
53+
pub fn create(db: &mut ConnectionType, item: &CreateTodos) -> diesel::QueryResult<Self> {
5554
use crate::schema::todos::dsl::*;
5655

5756
diesel::insert_into(todos).values(item).get_result::<Self>(db)
5857
}
5958

6059
/// Get a row from `todos`, identified by the primary key
61-
pub fn read(db: &mut ConnectionType, param_data: Vec<u8>) -> QueryResult<Self> {
60+
pub fn read(db: &mut ConnectionType, param_data: Vec<u8>) -> diesel::QueryResult<Self> {
6261
use crate::schema::todos::dsl::*;
6362

6463
todos.filter(data.eq(param_data)).first::<Self>(db)
6564
}
6665

6766
/// Paginates through the table where page is a 0-based index (i.e. page 0 is the first page)
68-
pub fn paginate(db: &mut ConnectionType, page: i64, page_size: i64) -> QueryResult<PaginationResult<Self>> {
67+
pub fn paginate(db: &mut ConnectionType, page: i64, page_size: i64) -> diesel::QueryResult<PaginationResult<Self>> {
6968
use crate::schema::todos::dsl::*;
7069

7170
let page_size = if page_size < 1 { 1 } else { page_size };
@@ -83,14 +82,14 @@ impl Todos {
8382
}
8483

8584
/// Update a row in `todos`, identified by the primary key with [`UpdateTodos`]
86-
pub fn update(db: &mut ConnectionType, param_data: Vec<u8>, item: &UpdateTodos) -> QueryResult<Self> {
85+
pub fn update(db: &mut ConnectionType, param_data: Vec<u8>, item: &UpdateTodos) -> diesel::QueryResult<Self> {
8786
use crate::schema::todos::dsl::*;
8887

8988
diesel::update(todos.filter(data.eq(param_data))).set(item).get_result(db)
9089
}
9190

9291
/// Delete a row in `todos`, identified by the primary key
93-
pub fn delete(db: &mut ConnectionType, param_data: Vec<u8>) -> QueryResult<usize> {
92+
pub fn delete(db: &mut ConnectionType, param_data: Vec<u8>) -> diesel::QueryResult<usize> {
9493
use crate::schema::todos::dsl::*;
9594

9695
diesel::delete(todos.filter(data.eq(param_data))).execute(db)

test/create_update_bytes_slice/models/todos/generated.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
use crate::diesel::*;
44
use crate::schema::*;
5-
use diesel::QueryResult;
65

76
pub type ConnectionType = diesel::r2d2::PooledConnection<diesel::r2d2::ConnectionManager<diesel::pg::PgConnection>>;
87

@@ -51,21 +50,21 @@ pub struct PaginationResult<T> {
5150

5251
impl Todos {
5352
/// Insert a new row into `todos` with a given [`CreateTodos`]
54-
pub fn create(db: &mut ConnectionType, item: &CreateTodos) -> QueryResult<Self> {
53+
pub fn create(db: &mut ConnectionType, item: &CreateTodos) -> diesel::QueryResult<Self> {
5554
use crate::schema::todos::dsl::*;
5655

5756
diesel::insert_into(todos).values(item).get_result::<Self>(db)
5857
}
5958

6059
/// Get a row from `todos`, identified by the primary key
61-
pub fn read(db: &mut ConnectionType, param_data: Vec<u8>) -> QueryResult<Self> {
60+
pub fn read(db: &mut ConnectionType, param_data: Vec<u8>) -> diesel::QueryResult<Self> {
6261
use crate::schema::todos::dsl::*;
6362

6463
todos.filter(data.eq(param_data)).first::<Self>(db)
6564
}
6665

6766
/// Paginates through the table where page is a 0-based index (i.e. page 0 is the first page)
68-
pub fn paginate(db: &mut ConnectionType, page: i64, page_size: i64) -> QueryResult<PaginationResult<Self>> {
67+
pub fn paginate(db: &mut ConnectionType, page: i64, page_size: i64) -> diesel::QueryResult<PaginationResult<Self>> {
6968
use crate::schema::todos::dsl::*;
7069

7170
let page_size = if page_size < 1 { 1 } else { page_size };
@@ -83,14 +82,14 @@ impl Todos {
8382
}
8483

8584
/// Update a row in `todos`, identified by the primary key with [`UpdateTodos`]
86-
pub fn update(db: &mut ConnectionType, param_data: Vec<u8>, item: &UpdateTodos) -> QueryResult<Self> {
85+
pub fn update(db: &mut ConnectionType, param_data: Vec<u8>, item: &UpdateTodos) -> diesel::QueryResult<Self> {
8786
use crate::schema::todos::dsl::*;
8887

8988
diesel::update(todos.filter(data.eq(param_data))).set(item).get_result(db)
9089
}
9190

9291
/// Delete a row in `todos`, identified by the primary key
93-
pub fn delete(db: &mut ConnectionType, param_data: Vec<u8>) -> QueryResult<usize> {
92+
pub fn delete(db: &mut ConnectionType, param_data: Vec<u8>) -> diesel::QueryResult<usize> {
9493
use crate::schema::todos::dsl::*;
9594

9695
diesel::delete(todos.filter(data.eq(param_data))).execute(db)

0 commit comments

Comments
 (0)