Skip to content

Commit 2593230

Browse files
committed
feat(code): change function return types to use "diesel::" prefix"
and remove explicit import
1 parent 58f1f31 commit 2593230

File tree

33 files changed

+144
-180
lines changed

33 files changed

+144
-180
lines changed

src/code.rs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,7 @@ fn build_table_fns(
464464
buffer.push_str(&format!(
465465
r##"
466466
/// Insert a new row into `{table_name}` with a given [`{create_struct_identifier}`]
467-
pub{async_keyword} fn create(db: &mut ConnectionType, item: &{create_struct_identifier}) -> QueryResult<Self> {{
467+
pub{async_keyword} fn create(db: &mut ConnectionType, item: &{create_struct_identifier}) -> diesel::QueryResult<Self> {{
468468
use {schema_path}{table_name}::dsl::*;
469469
470470
diesel::insert_into({table_name}).values(item).get_result::<Self>(db){await_keyword}
@@ -475,7 +475,7 @@ fn build_table_fns(
475475
buffer.push_str(&format!(
476476
r##"
477477
/// Insert a new row into `{table_name}` with all default values
478-
pub{async_keyword} fn create(db: &mut ConnectionType) -> QueryResult<Self> {{
478+
pub{async_keyword} fn create(db: &mut ConnectionType) -> diesel::QueryResult<Self> {{
479479
use {schema_path}{table_name}::dsl::*;
480480
481481
diesel::insert_into({table_name}).default_values().get_result::<Self>(db){await_keyword}
@@ -495,7 +495,7 @@ fn build_table_fns(
495495
buffer.push_str(&format!(
496496
r##"
497497
/// Get a row from `{table_name}`, identified by the primary {key_maybe_multiple}
498-
pub{async_keyword} fn read(db: &mut ConnectionType, {item_id_params}) -> QueryResult<Self> {{
498+
pub{async_keyword} fn read(db: &mut ConnectionType, {item_id_params}) -> diesel::QueryResult<Self> {{
499499
use {schema_path}{table_name}::dsl::*;
500500
501501
{table_name}.{item_id_filters}.first::<Self>(db){await_keyword}
@@ -505,7 +505,7 @@ fn build_table_fns(
505505

506506
buffer.push_str(&format!(r##"
507507
/// Paginates through the table where page is a 0-based index (i.e. page 0 is the first page)
508-
pub{async_keyword} fn paginate(db: &mut ConnectionType, page: i64, page_size: i64) -> QueryResult<PaginationResult<Self>> {{
508+
pub{async_keyword} fn paginate(db: &mut ConnectionType, page: i64, page_size: i64) -> diesel::QueryResult<PaginationResult<Self>> {{
509509
use {schema_path}{table_name}::dsl::*;
510510
511511
let page_size = if page_size < 1 {{ 1 }} else {{ page_size }};
@@ -534,7 +534,7 @@ fn build_table_fns(
534534

535535
buffer.push_str(&format!(r##"
536536
/// Update a row in `{table_name}`, identified by the primary {key_maybe_multiple} with [`{update_struct_identifier}`]
537-
pub{async_keyword} fn update(db: &mut ConnectionType, {item_id_params}, item: &{update_struct_identifier}) -> QueryResult<Self> {{
537+
pub{async_keyword} fn update(db: &mut ConnectionType, {item_id_params}, item: &{update_struct_identifier}) -> diesel::QueryResult<Self> {{
538538
use {schema_path}{table_name}::dsl::*;
539539
540540
diesel::update({table_name}.{item_id_filters}).set(item).get_result(db){await_keyword}
@@ -546,7 +546,7 @@ fn build_table_fns(
546546
buffer.push_str(&format!(
547547
r##"
548548
/// Delete a row in `{table_name}`, identified by the primary {key_maybe_multiple}
549-
pub{async_keyword} fn delete(db: &mut ConnectionType, {item_id_params}) -> QueryResult<usize> {{
549+
pub{async_keyword} fn delete(db: &mut ConnectionType, {item_id_params}) -> diesel::QueryResult<usize> {{
550550
use {schema_path}{table_name}::dsl::*;
551551
552552
diesel::delete({table_name}.{item_id_filters}).execute(db){await_keyword}
@@ -628,10 +628,6 @@ fn build_imports(table: &ParsedTableMacro, config: &GenerationConfig) -> String
628628
// no "::" because that is already included in the schema_path
629629
imports_vec.push(format!("use {}*;", config.schema_path));
630630

631-
if table_options.get_fns() {
632-
imports_vec.push("use diesel::QueryResult;".into());
633-
};
634-
635631
if config.once_common_structs || config.once_connection_type {
636632
imports_vec.push(format!("use {}common::*;", config.model_path));
637633
};

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_str_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

@@ -63,21 +62,21 @@ pub struct PaginationResult<T> {
6362

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

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

7271
/// Get a row from `todos`, identified by the primary key
73-
pub fn read(db: &mut ConnectionType, param_text: String) -> QueryResult<Self> {
72+
pub fn read(db: &mut ConnectionType, param_text: String) -> diesel::QueryResult<Self> {
7473
use crate::schema::todos::dsl::*;
7574

7675
todos.filter(text.eq(param_text)).first::<Self>(db)
7776
}
7877

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

8382
let page_size = if page_size < 1 { 1 } else { page_size };
@@ -95,14 +94,14 @@ impl Todos {
9594
}
9695

9796
/// Update a row in `todos`, identified by the primary key with [`UpdateTodos`]
98-
pub fn update(db: &mut ConnectionType, param_text: String, item: &UpdateTodos) -> QueryResult<Self> {
97+
pub fn update(db: &mut ConnectionType, param_text: String, item: &UpdateTodos) -> diesel::QueryResult<Self> {
9998
use crate::schema::todos::dsl::*;
10099

101100
diesel::update(todos.filter(text.eq(param_text))).set(item).get_result(db)
102101
}
103102

104103
/// Delete a row in `todos`, identified by the primary key
105-
pub fn delete(db: &mut ConnectionType, param_text: String) -> QueryResult<usize> {
104+
pub fn delete(db: &mut ConnectionType, param_text: String) -> diesel::QueryResult<usize> {
106105
use crate::schema::todos::dsl::*;
107106

108107
diesel::delete(todos.filter(text.eq(param_text))).execute(db)

test/create_update_str_str/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

@@ -63,21 +62,21 @@ pub struct PaginationResult<T> {
6362

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

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

7271
/// Get a row from `todos`, identified by the primary key
73-
pub fn read(db: &mut ConnectionType, param_text: String) -> QueryResult<Self> {
72+
pub fn read(db: &mut ConnectionType, param_text: String) -> diesel::QueryResult<Self> {
7473
use crate::schema::todos::dsl::*;
7574

7675
todos.filter(text.eq(param_text)).first::<Self>(db)
7776
}
7877

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

8382
let page_size = if page_size < 1 { 1 } else { page_size };
@@ -95,14 +94,14 @@ impl Todos {
9594
}
9695

9796
/// Update a row in `todos`, identified by the primary key with [`UpdateTodos`]
98-
pub fn update(db: &mut ConnectionType, param_text: String, item: &UpdateTodos) -> QueryResult<Self> {
97+
pub fn update(db: &mut ConnectionType, param_text: String, item: &UpdateTodos) -> diesel::QueryResult<Self> {
9998
use crate::schema::todos::dsl::*;
10099

101100
diesel::update(todos.filter(text.eq(param_text))).set(item).get_result(db)
102101
}
103102

104103
/// Delete a row in `todos`, identified by the primary key
105-
pub fn delete(db: &mut ConnectionType, param_text: String) -> QueryResult<usize> {
104+
pub fn delete(db: &mut ConnectionType, param_text: String) -> diesel::QueryResult<usize> {
106105
use crate::schema::todos::dsl::*;
107106

108107
diesel::delete(todos.filter(text.eq(param_text))).execute(db)

0 commit comments

Comments
 (0)