From 0fc74b0804fd0e05be91272574eee1066228ef0c Mon Sep 17 00:00:00 2001 From: hasezoey Date: Tue, 31 Oct 2023 14:29:40 +0100 Subject: [PATCH 1/6] feat(parser): parse actual column name from diesel macro --- src/parser.rs | 99 ++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 86 insertions(+), 13 deletions(-) diff --git a/src/parser.rs b/src/parser.rs index e2c4d5f7..15ed5163 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -16,6 +16,8 @@ pub struct ParsedColumnMacro { pub ty: String, /// Rust ident for the field name pub name: Ident, + /// Actual column name, as parsed from the attributes, or the same as "name" + pub column_name: String, pub is_nullable: bool, pub is_unsigned: bool, } @@ -223,19 +225,37 @@ fn handle_table_macro( // columns group // println!("GROUP-cols {:#?}", group); - let mut column_name: Option = None; + // rust name parsed from the macro (the "HERE" in "HERE -> TYPE") + let mut rust_column_name: Option = None; + // actual column name, parsed from the attribute value, if any ("#[sql_name = "test"]") + let mut actual_column_name: Option = None; let mut column_type: Option = None; let mut column_nullable: bool = false; let mut column_unsigned: bool = false; + // track if the last loop was a "#" (start of a attribute) + let mut had_hashtag = false; for column_tokens in group.stream().into_iter() { + // reset "had_hastag" but still make it available for checking + let had_hashtag_last = had_hashtag; + had_hashtag = false; match column_tokens { - proc_macro2::TokenTree::Group(_) => { + proc_macro2::TokenTree::Group(group) => { + if had_hashtag_last { + // parse some extra information from the bracket group + // like the actual column name + if let Some((name, value)) = parse_diesel_attr_group(&group) { + if name == "sql_name" { + actual_column_name = Some(value); + } + } + } + continue; } proc_macro2::TokenTree::Ident(ident) => { - if column_name.is_none() { - column_name = Some(ident); + if rust_column_name.is_none() { + rust_column_name = Some(ident); } else if ident.to_string().eq_ignore_ascii_case("Nullable") { column_nullable = true; } else if ident.to_string().eq_ignore_ascii_case("Unsigned") { @@ -247,22 +267,29 @@ fn handle_table_macro( proc_macro2::TokenTree::Punct(punct) => { let char = punct.as_char(); - if char == '#' || char == '-' || char == '>' { + if char == '#' { + had_hashtag = true; + continue; + } else if char == '-' || char == '>' { // nothing for arrow or any additional #[] continue; } else if char == ',' - && column_name.is_some() + && rust_column_name.is_some() && column_type.is_some() { // end of column def! + let rust_column_name_checked = rust_column_name.ok_or( + Error::unsupported_schema_format( + "Invalid column name syntax", + ), + )?; + let column_name = actual_column_name + .unwrap_or(rust_column_name_checked.to_string()); + // add the column table_columns.push(ParsedColumnMacro { - name: column_name.ok_or( - Error::unsupported_schema_format( - "Invalid column name syntax", - ), - )?, + name: rust_column_name_checked, ty: schema_type_to_rust_type( column_type .ok_or(Error::unsupported_schema_format( @@ -273,10 +300,12 @@ fn handle_table_macro( )?, is_nullable: column_nullable, is_unsigned: column_unsigned, + column_name, }); // reset the properties - column_name = None; + rust_column_name = None; + actual_column_name = None; column_type = None; column_unsigned = false; column_nullable = false; @@ -290,7 +319,7 @@ fn handle_table_macro( } } - if column_name.is_some() + if rust_column_name.is_some() || column_type.is_some() || column_nullable || column_unsigned @@ -330,6 +359,50 @@ fn handle_table_macro( }) } +/// Parse a diesel schema attribute group +/// ```rs +/// #[attr = value] +/// ``` +/// into (attr, value) +fn parse_diesel_attr_group(group: &proc_macro2::Group) -> Option<(Ident, String)> { + // diesel only uses square brackets, so ignore other types + if group.delimiter() != proc_macro2::Delimiter::Bracket { + return None; + } + + let mut token_stream = group.stream().into_iter(); + // parse the attribute name, if it is anything else, return None + let attr_name = match token_stream.next()? { + proc_macro2::TokenTree::Ident(ident) => ident, + _ => return None, + }; + + // diesel always uses "=" for assignments + let punct = match token_stream.next()? { + proc_macro2::TokenTree::Punct(punct) => punct, + _ => return None, + }; + + if punct.as_char() != '=' { + return None; + } + + // diesel print-schema only uses literals currently, if anything else is used, it should be added here + let value = match token_stream.next()? { + proc_macro2::TokenTree::Literal(literal) => literal, + _ => return None, + }; + + let mut value = value.to_string(); + + // remove the starting and ending quotes + if value.starts_with('"') && value.ends_with('"') { + value = String::from(&value[1..value.len() - 1]); // safe char boundaries because '"' is only one byte long + } + + Some((attr_name, value)) +} + // A function to translate diesel schema types into rust types // // reference: https://github.com/diesel-rs/diesel/blob/master/diesel/src/sql_types/mod.rs From 11f18ec59970cea705e785754f6818d2094848f0 Mon Sep 17 00:00:00 2001 From: hasezoey Date: Tue, 31 Oct 2023 14:46:12 +0100 Subject: [PATCH 2/6] feat(code): add doccomments to generated structs --- src/code.rs | 18 ++++++++++++++++++ .../models/todos/generated.rs | 2 ++ .../models/todos/generated.rs | 3 +++ .../models/todos/generated.rs | 3 +++ .../models/todos/generated.rs | 3 +++ .../models/todos/generated.rs | 3 +++ .../models/todos/generated.rs | 3 +++ .../models/tableA/generated.rs | 2 ++ .../models/tableB/generated.rs | 3 +++ .../models/tableA/generated.rs | 2 ++ .../models/tableB/generated.rs | 3 +++ .../models/todos/generated.rs | 2 ++ .../models/users/generated.rs | 3 +++ .../models/table1/generated.rs | 1 + .../models/table2/generated.rs | 1 + .../models/table1/generated.rs | 1 + .../models/table2/generated.rs | 1 + .../models/table1.rs | 1 + .../models/table2.rs | 1 + .../models/table1/generated.rs | 1 + .../models/table2/generated.rs | 1 + test/readonly/models/normal/generated.rs | 3 +++ test/readonly/models/prefixTable/generated.rs | 1 + .../models/prefixTableSuffix/generated.rs | 1 + test/readonly/models/tableSuffix/generated.rs | 1 + test/simple_table/models/todos/generated.rs | 3 +++ .../models/todos/generated.rs | 3 +++ .../models/todos/generated.rs | 3 +++ .../models/todos/generated.rs | 3 +++ .../models/todos/generated.rs | 3 +++ test/single_model_file/models/table1.rs | 1 + test/single_model_file/models/table2.rs | 1 + .../models/fang_tasks/generated.rs | 3 +++ 33 files changed, 84 insertions(+) diff --git a/src/code.rs b/src/code.rs index 99f6dd35..a9fb6b73 100644 --- a/src/code.rs +++ b/src/code.rs @@ -316,8 +316,26 @@ impl<'a> Struct<'a> { lines.push(format!(r#" pub {field_name}: {field_type},"#)); } + let doccomment = match ty { + StructType::Read => format!( + "/// Struct representing a row in table `{table_name}`", + table_name = table.name + ), + StructType::Update => format!( + "/// Update Struct for a row in table `{table_name}` for [`{read_struct}`]", + table_name = table.name, + read_struct = table.struct_name + ), + StructType::Create => format!( + "/// Create Struct for a row in table `{table_name}` for [`{read_struct}`]", + table_name = table.name, + read_struct = table.struct_name + ), + }; + let struct_code = formatdoc!( r#" + {doccomment} {tsync_attr}{derive_attr} #[diesel(table_name={table_name}{primary_key}{belongs_to})] pub struct {struct_name}{lifetimes} {{ diff --git a/test/autogenerated_all/models/todos/generated.rs b/test/autogenerated_all/models/todos/generated.rs index 12e0530a..544de025 100644 --- a/test/autogenerated_all/models/todos/generated.rs +++ b/test/autogenerated_all/models/todos/generated.rs @@ -7,6 +7,7 @@ use diesel::QueryResult; type ConnectionType = diesel::r2d2::PooledConnection>; +/// Struct representing a row in table `todos` #[derive(Debug, Clone, Serialize, Deserialize, Queryable, Selectable)] #[diesel(table_name=todos, primary_key(id))] pub struct Todos { @@ -14,6 +15,7 @@ pub struct Todos { pub created_at: chrono::NaiveDateTime, } +/// Update Struct for a row in table `todos` for [`Todos`] #[derive(Debug, Clone, Serialize, Deserialize, AsChangeset, Default)] #[diesel(table_name=todos)] pub struct UpdateTodos { diff --git a/test/autogenerated_attributes/models/todos/generated.rs b/test/autogenerated_attributes/models/todos/generated.rs index 7af9c77e..5969679d 100644 --- a/test/autogenerated_attributes/models/todos/generated.rs +++ b/test/autogenerated_attributes/models/todos/generated.rs @@ -7,6 +7,7 @@ use diesel::QueryResult; type ConnectionType = diesel::r2d2::PooledConnection>; +/// Struct representing a row in table `todos` #[derive(Debug, Clone, Serialize, Deserialize, Queryable, Selectable)] #[diesel(table_name=todos, primary_key(id))] pub struct Todos { @@ -14,12 +15,14 @@ pub struct Todos { pub created_at: chrono::NaiveDateTime, } +/// Create Struct for a row in table `todos` for [`Todos`] #[derive(Debug, Clone, Serialize, Deserialize, Insertable)] #[diesel(table_name=todos)] pub struct CreateTodos { pub id: i32, } +/// Update Struct for a row in table `todos` for [`Todos`] #[derive(Debug, Clone, Serialize, Deserialize, AsChangeset, Default)] #[diesel(table_name=todos)] pub struct UpdateTodos { diff --git a/test/autogenerated_primary_keys/models/todos/generated.rs b/test/autogenerated_primary_keys/models/todos/generated.rs index 82d2f095..6586a45d 100644 --- a/test/autogenerated_primary_keys/models/todos/generated.rs +++ b/test/autogenerated_primary_keys/models/todos/generated.rs @@ -7,6 +7,7 @@ use diesel::QueryResult; type ConnectionType = diesel::r2d2::PooledConnection>; +/// Struct representing a row in table `todos` #[derive(Debug, Clone, Serialize, Deserialize, Queryable, Selectable)] #[diesel(table_name=todos, primary_key(id))] pub struct Todos { @@ -14,12 +15,14 @@ pub struct Todos { pub text: String, } +/// Create Struct for a row in table `todos` for [`Todos`] #[derive(Debug, Clone, Serialize, Deserialize, Insertable)] #[diesel(table_name=todos)] pub struct CreateTodos { pub text: String, } +/// Update Struct for a row in table `todos` for [`Todos`] #[derive(Debug, Clone, Serialize, Deserialize, AsChangeset, Default)] #[diesel(table_name=todos)] pub struct UpdateTodos { diff --git a/test/cleanup_generated_content/models/todos/generated.rs b/test/cleanup_generated_content/models/todos/generated.rs index e274198b..61bd082b 100644 --- a/test/cleanup_generated_content/models/todos/generated.rs +++ b/test/cleanup_generated_content/models/todos/generated.rs @@ -7,6 +7,7 @@ use diesel::QueryResult; type ConnectionType = diesel::r2d2::PooledConnection>; +/// Struct representing a row in table `todos` #[derive(Debug, Clone, Serialize, Deserialize, Queryable, Selectable)] #[diesel(table_name=todos, primary_key(id))] pub struct Todos { @@ -17,6 +18,7 @@ pub struct Todos { pub updated_at: chrono::DateTime, } +/// Create Struct for a row in table `todos` for [`Todos`] #[derive(Debug, Clone, Serialize, Deserialize, Insertable)] #[diesel(table_name=todos)] pub struct CreateTodos { @@ -25,6 +27,7 @@ pub struct CreateTodos { pub completed: bool, } +/// Update Struct for a row in table `todos` for [`Todos`] #[derive(Debug, Clone, Serialize, Deserialize, AsChangeset, Default)] #[diesel(table_name=todos)] pub struct UpdateTodos { diff --git a/test/create_update_str_cow/models/todos/generated.rs b/test/create_update_str_cow/models/todos/generated.rs index 0e6fd50c..61ca2bc6 100644 --- a/test/create_update_str_cow/models/todos/generated.rs +++ b/test/create_update_str_cow/models/todos/generated.rs @@ -7,6 +7,7 @@ use diesel::QueryResult; type ConnectionType = diesel::r2d2::PooledConnection>; +/// Struct representing a row in table `todos` #[derive(Debug, Clone, Serialize, Deserialize, Queryable, Selectable)] #[diesel(table_name=todos, primary_key(text))] pub struct Todos { @@ -16,6 +17,7 @@ pub struct Todos { pub varchar_nullable: Option, } +/// Create Struct for a row in table `todos` for [`Todos`] #[derive(Debug, Clone, Serialize, Deserialize, Insertable)] #[diesel(table_name=todos)] pub struct CreateTodos<'a> { @@ -25,6 +27,7 @@ pub struct CreateTodos<'a> { pub varchar_nullable: Option>, } +/// Update Struct for a row in table `todos` for [`Todos`] #[derive(Debug, Clone, Serialize, Deserialize, AsChangeset, Default)] #[diesel(table_name=todos)] pub struct UpdateTodos<'a> { diff --git a/test/create_update_str_str/models/todos/generated.rs b/test/create_update_str_str/models/todos/generated.rs index ddf9a95b..fad9458b 100644 --- a/test/create_update_str_str/models/todos/generated.rs +++ b/test/create_update_str_str/models/todos/generated.rs @@ -7,6 +7,7 @@ use diesel::QueryResult; type ConnectionType = diesel::r2d2::PooledConnection>; +/// Struct representing a row in table `todos` #[derive(Debug, Clone, Serialize, Deserialize, Queryable, Selectable)] #[diesel(table_name=todos, primary_key(text))] pub struct Todos { @@ -16,6 +17,7 @@ pub struct Todos { pub varchar_nullable: Option, } +/// Create Struct for a row in table `todos` for [`Todos`] #[derive(Debug, Clone, Serialize, Deserialize, Insertable)] #[diesel(table_name=todos)] pub struct CreateTodos<'a> { @@ -25,6 +27,7 @@ pub struct CreateTodos<'a> { pub varchar_nullable: Option<&'a str>, } +/// Update Struct for a row in table `todos` for [`Todos`] #[derive(Debug, Clone, Serialize, Deserialize, AsChangeset, Default)] #[diesel(table_name=todos)] pub struct UpdateTodos<'a> { diff --git a/test/custom_model_and_schema_path/models/tableA/generated.rs b/test/custom_model_and_schema_path/models/tableA/generated.rs index d45f94cd..7c9ec090 100644 --- a/test/custom_model_and_schema_path/models/tableA/generated.rs +++ b/test/custom_model_and_schema_path/models/tableA/generated.rs @@ -7,12 +7,14 @@ use diesel::QueryResult; type ConnectionType = diesel::r2d2::PooledConnection>; +/// Struct representing a row in table `tableA` #[derive(Debug, Clone, Serialize, Deserialize, Queryable, Selectable)] #[diesel(table_name=tableA, primary_key(_id))] pub struct TableA { pub _id: i32, } +/// Create Struct for a row in table `tableA` for [`TableA`] #[derive(Debug, Clone, Serialize, Deserialize, Insertable)] #[diesel(table_name=tableA)] pub struct CreateTableA { diff --git a/test/custom_model_and_schema_path/models/tableB/generated.rs b/test/custom_model_and_schema_path/models/tableB/generated.rs index f0e88858..ed613d1e 100644 --- a/test/custom_model_and_schema_path/models/tableB/generated.rs +++ b/test/custom_model_and_schema_path/models/tableB/generated.rs @@ -8,6 +8,7 @@ use diesel::QueryResult; type ConnectionType = diesel::r2d2::PooledConnection>; +/// Struct representing a row in table `tableB` #[derive(Debug, Clone, Serialize, Deserialize, Queryable, Selectable, Associations, Identifiable)] #[diesel(table_name=tableB, primary_key(_id), belongs_to(TableA, foreign_key=link))] pub struct TableB { @@ -15,6 +16,7 @@ pub struct TableB { pub link: i32, } +/// Create Struct for a row in table `tableB` for [`TableB`] #[derive(Debug, Clone, Serialize, Deserialize, Insertable)] #[diesel(table_name=tableB)] pub struct CreateTableB { @@ -22,6 +24,7 @@ pub struct CreateTableB { pub link: i32, } +/// Update Struct for a row in table `tableB` for [`TableB`] #[derive(Debug, Clone, Serialize, Deserialize, AsChangeset, Default)] #[diesel(table_name=tableB)] pub struct UpdateTableB { diff --git a/test/custom_model_path/models/tableA/generated.rs b/test/custom_model_path/models/tableA/generated.rs index 6cbc2247..53a08316 100644 --- a/test/custom_model_path/models/tableA/generated.rs +++ b/test/custom_model_path/models/tableA/generated.rs @@ -7,12 +7,14 @@ use diesel::QueryResult; type ConnectionType = diesel::r2d2::PooledConnection>; +/// Struct representing a row in table `tableA` #[derive(Debug, Clone, Serialize, Deserialize, Queryable, Selectable)] #[diesel(table_name=tableA, primary_key(_id))] pub struct TableA { pub _id: i32, } +/// Create Struct for a row in table `tableA` for [`TableA`] #[derive(Debug, Clone, Serialize, Deserialize, Insertable)] #[diesel(table_name=tableA)] pub struct CreateTableA { diff --git a/test/custom_model_path/models/tableB/generated.rs b/test/custom_model_path/models/tableB/generated.rs index 8e177ff9..a1b525be 100644 --- a/test/custom_model_path/models/tableB/generated.rs +++ b/test/custom_model_path/models/tableB/generated.rs @@ -8,6 +8,7 @@ use diesel::QueryResult; type ConnectionType = diesel::r2d2::PooledConnection>; +/// Struct representing a row in table `tableB` #[derive(Debug, Clone, Serialize, Deserialize, Queryable, Selectable, Associations, Identifiable)] #[diesel(table_name=tableB, primary_key(_id), belongs_to(TableA, foreign_key=link))] pub struct TableB { @@ -15,6 +16,7 @@ pub struct TableB { pub link: i32, } +/// Create Struct for a row in table `tableB` for [`TableB`] #[derive(Debug, Clone, Serialize, Deserialize, Insertable)] #[diesel(table_name=tableB)] pub struct CreateTableB { @@ -22,6 +24,7 @@ pub struct CreateTableB { pub link: i32, } +/// Update Struct for a row in table `tableB` for [`TableB`] #[derive(Debug, Clone, Serialize, Deserialize, AsChangeset, Default)] #[diesel(table_name=tableB)] pub struct UpdateTableB { diff --git a/test/manual_primary_keys/models/todos/generated.rs b/test/manual_primary_keys/models/todos/generated.rs index e0bb1e1e..5f3d0785 100644 --- a/test/manual_primary_keys/models/todos/generated.rs +++ b/test/manual_primary_keys/models/todos/generated.rs @@ -7,12 +7,14 @@ use diesel::QueryResult; type ConnectionType = diesel::r2d2::PooledConnection>; +/// Struct representing a row in table `todos` #[derive(Debug, Clone, Serialize, Deserialize, Queryable, Selectable)] #[diesel(table_name=todos, primary_key(id))] pub struct Todos { pub id: i32, } +/// Create Struct for a row in table `todos` for [`Todos`] #[derive(Debug, Clone, Serialize, Deserialize, Insertable)] #[diesel(table_name=todos)] pub struct CreateTodos { diff --git a/test/multiple_primary_keys/models/users/generated.rs b/test/multiple_primary_keys/models/users/generated.rs index 5379a456..1ecaf1e9 100644 --- a/test/multiple_primary_keys/models/users/generated.rs +++ b/test/multiple_primary_keys/models/users/generated.rs @@ -7,6 +7,7 @@ use diesel::QueryResult; type ConnectionType = diesel::r2d2::PooledConnection>; +/// Struct representing a row in table `users` #[derive(Debug, Clone, Serialize, Deserialize, Queryable, Selectable)] #[diesel(table_name=users, primary_key(name,address))] pub struct Users { @@ -15,6 +16,7 @@ pub struct Users { pub secret: String, } +/// Create Struct for a row in table `users` for [`Users`] #[derive(Debug, Clone, Serialize, Deserialize, Insertable)] #[diesel(table_name=users)] pub struct CreateUsers { @@ -23,6 +25,7 @@ pub struct CreateUsers { pub secret: String, } +/// Update Struct for a row in table `users` for [`Users`] #[derive(Debug, Clone, Serialize, Deserialize, AsChangeset, Default)] #[diesel(table_name=users)] pub struct UpdateUsers { diff --git a/test/once_common_structs/models/table1/generated.rs b/test/once_common_structs/models/table1/generated.rs index d69cd8f4..f191f20f 100644 --- a/test/once_common_structs/models/table1/generated.rs +++ b/test/once_common_structs/models/table1/generated.rs @@ -8,6 +8,7 @@ use crate::models::common::*; type ConnectionType = diesel::r2d2::PooledConnection>; +/// Struct representing a row in table `table1` #[derive(Debug, Clone, Serialize, Deserialize, Queryable, Selectable)] #[diesel(table_name=table1, primary_key(id))] pub struct Table1 { diff --git a/test/once_common_structs/models/table2/generated.rs b/test/once_common_structs/models/table2/generated.rs index b41d3635..ed8efc29 100644 --- a/test/once_common_structs/models/table2/generated.rs +++ b/test/once_common_structs/models/table2/generated.rs @@ -8,6 +8,7 @@ use crate::models::common::*; type ConnectionType = diesel::r2d2::PooledConnection>; +/// Struct representing a row in table `table2` #[derive(Debug, Clone, Serialize, Deserialize, Queryable, Selectable)] #[diesel(table_name=table2, primary_key(id))] pub struct Table2 { diff --git a/test/once_common_structs_once_connection_type/models/table1/generated.rs b/test/once_common_structs_once_connection_type/models/table1/generated.rs index 5e46bc54..52bf5ad1 100644 --- a/test/once_common_structs_once_connection_type/models/table1/generated.rs +++ b/test/once_common_structs_once_connection_type/models/table1/generated.rs @@ -6,6 +6,7 @@ use serde::{Deserialize, Serialize}; use diesel::QueryResult; use crate::models::common::*; +/// Struct representing a row in table `table1` #[derive(Debug, Clone, Serialize, Deserialize, Queryable, Selectable)] #[diesel(table_name=table1, primary_key(id))] pub struct Table1 { diff --git a/test/once_common_structs_once_connection_type/models/table2/generated.rs b/test/once_common_structs_once_connection_type/models/table2/generated.rs index 8cbee776..87839642 100644 --- a/test/once_common_structs_once_connection_type/models/table2/generated.rs +++ b/test/once_common_structs_once_connection_type/models/table2/generated.rs @@ -6,6 +6,7 @@ use serde::{Deserialize, Serialize}; use diesel::QueryResult; use crate::models::common::*; +/// Struct representing a row in table `table2` #[derive(Debug, Clone, Serialize, Deserialize, Queryable, Selectable)] #[diesel(table_name=table2, primary_key(id))] pub struct Table2 { diff --git a/test/once_common_structs_once_connection_type_single_file/models/table1.rs b/test/once_common_structs_once_connection_type_single_file/models/table1.rs index 5e46bc54..52bf5ad1 100644 --- a/test/once_common_structs_once_connection_type_single_file/models/table1.rs +++ b/test/once_common_structs_once_connection_type_single_file/models/table1.rs @@ -6,6 +6,7 @@ use serde::{Deserialize, Serialize}; use diesel::QueryResult; use crate::models::common::*; +/// Struct representing a row in table `table1` #[derive(Debug, Clone, Serialize, Deserialize, Queryable, Selectable)] #[diesel(table_name=table1, primary_key(id))] pub struct Table1 { diff --git a/test/once_common_structs_once_connection_type_single_file/models/table2.rs b/test/once_common_structs_once_connection_type_single_file/models/table2.rs index 8cbee776..87839642 100644 --- a/test/once_common_structs_once_connection_type_single_file/models/table2.rs +++ b/test/once_common_structs_once_connection_type_single_file/models/table2.rs @@ -6,6 +6,7 @@ use serde::{Deserialize, Serialize}; use diesel::QueryResult; use crate::models::common::*; +/// Struct representing a row in table `table2` #[derive(Debug, Clone, Serialize, Deserialize, Queryable, Selectable)] #[diesel(table_name=table2, primary_key(id))] pub struct Table2 { diff --git a/test/once_connection_type/models/table1/generated.rs b/test/once_connection_type/models/table1/generated.rs index 359be4f7..fafcc252 100644 --- a/test/once_connection_type/models/table1/generated.rs +++ b/test/once_connection_type/models/table1/generated.rs @@ -6,6 +6,7 @@ use serde::{Deserialize, Serialize}; use diesel::QueryResult; use crate::models::common::*; +/// Struct representing a row in table `table1` #[derive(Debug, Clone, Serialize, Deserialize, Queryable, Selectable)] #[diesel(table_name=table1, primary_key(id))] pub struct Table1 { diff --git a/test/once_connection_type/models/table2/generated.rs b/test/once_connection_type/models/table2/generated.rs index 4d8cfdf3..89f6dd00 100644 --- a/test/once_connection_type/models/table2/generated.rs +++ b/test/once_connection_type/models/table2/generated.rs @@ -6,6 +6,7 @@ use serde::{Deserialize, Serialize}; use diesel::QueryResult; use crate::models::common::*; +/// Struct representing a row in table `table2` #[derive(Debug, Clone, Serialize, Deserialize, Queryable, Selectable)] #[diesel(table_name=table2, primary_key(id))] pub struct Table2 { diff --git a/test/readonly/models/normal/generated.rs b/test/readonly/models/normal/generated.rs index 92fc6a53..15e179f0 100644 --- a/test/readonly/models/normal/generated.rs +++ b/test/readonly/models/normal/generated.rs @@ -7,6 +7,7 @@ use diesel::QueryResult; type ConnectionType = diesel::r2d2::PooledConnection>; +/// Struct representing a row in table `normal` #[derive(Debug, Clone, Serialize, Deserialize, Queryable, Selectable)] #[diesel(table_name=normal, primary_key(id))] pub struct Normal { @@ -14,12 +15,14 @@ pub struct Normal { pub testprop: i32, } +/// Create Struct for a row in table `normal` for [`Normal`] #[derive(Debug, Clone, Serialize, Deserialize, Insertable)] #[diesel(table_name=normal)] pub struct CreateNormal { pub testprop: i32, } +/// Update Struct for a row in table `normal` for [`Normal`] #[derive(Debug, Clone, Serialize, Deserialize, AsChangeset, Default)] #[diesel(table_name=normal)] pub struct UpdateNormal { diff --git a/test/readonly/models/prefixTable/generated.rs b/test/readonly/models/prefixTable/generated.rs index 74ea0f74..c045a78c 100644 --- a/test/readonly/models/prefixTable/generated.rs +++ b/test/readonly/models/prefixTable/generated.rs @@ -7,6 +7,7 @@ use diesel::QueryResult; type ConnectionType = diesel::r2d2::PooledConnection>; +/// Struct representing a row in table `prefixTable` #[derive(Debug, Clone, Serialize, Deserialize, Queryable, Selectable)] #[diesel(table_name=prefixTable, primary_key(id))] pub struct PrefixTable { diff --git a/test/readonly/models/prefixTableSuffix/generated.rs b/test/readonly/models/prefixTableSuffix/generated.rs index 7bce0a4e..52ce7397 100644 --- a/test/readonly/models/prefixTableSuffix/generated.rs +++ b/test/readonly/models/prefixTableSuffix/generated.rs @@ -7,6 +7,7 @@ use diesel::QueryResult; type ConnectionType = diesel::r2d2::PooledConnection>; +/// Struct representing a row in table `prefixTableSuffix` #[derive(Debug, Clone, Serialize, Deserialize, Queryable, Selectable)] #[diesel(table_name=prefixTableSuffix, primary_key(id))] pub struct PrefixTableSuffix { diff --git a/test/readonly/models/tableSuffix/generated.rs b/test/readonly/models/tableSuffix/generated.rs index ee4ee0fd..bbc64e62 100644 --- a/test/readonly/models/tableSuffix/generated.rs +++ b/test/readonly/models/tableSuffix/generated.rs @@ -7,6 +7,7 @@ use diesel::QueryResult; type ConnectionType = diesel::r2d2::PooledConnection>; +/// Struct representing a row in table `tableSuffix` #[derive(Debug, Clone, Serialize, Deserialize, Queryable, Selectable)] #[diesel(table_name=tableSuffix, primary_key(id))] pub struct TableSuffix { diff --git a/test/simple_table/models/todos/generated.rs b/test/simple_table/models/todos/generated.rs index 7ad5dd2e..8029df9f 100644 --- a/test/simple_table/models/todos/generated.rs +++ b/test/simple_table/models/todos/generated.rs @@ -7,6 +7,7 @@ use diesel::QueryResult; type ConnectionType = diesel::r2d2::PooledConnection>; +/// Struct representing a row in table `todos` #[derive(Debug, Clone, Serialize, Deserialize, Queryable, Selectable)] #[diesel(table_name=todos, primary_key(id))] pub struct Todos { @@ -20,6 +21,7 @@ pub struct Todos { pub updated_at: chrono::DateTime, } +/// Create Struct for a row in table `todos` for [`Todos`] #[derive(Debug, Clone, Serialize, Deserialize, Insertable)] #[diesel(table_name=todos)] pub struct CreateTodos { @@ -30,6 +32,7 @@ pub struct CreateTodos { pub type_: String, } +/// Update Struct for a row in table `todos` for [`Todos`] #[derive(Debug, Clone, Serialize, Deserialize, AsChangeset, Default)] #[diesel(table_name=todos)] pub struct UpdateTodos { diff --git a/test/simple_table_async/models/todos/generated.rs b/test/simple_table_async/models/todos/generated.rs index 2a2eca2d..cb4648e1 100644 --- a/test/simple_table_async/models/todos/generated.rs +++ b/test/simple_table_async/models/todos/generated.rs @@ -8,6 +8,7 @@ use diesel::QueryResult; type ConnectionType = diesel_async::pooled_connection::deadpool::Object; +/// Struct representing a row in table `todos` #[derive(Debug, Clone, Serialize, Deserialize, Queryable, Selectable)] #[diesel(table_name=todos, primary_key(id))] pub struct Todos { @@ -19,6 +20,7 @@ pub struct Todos { pub updated_at: chrono::DateTime, } +/// Create Struct for a row in table `todos` for [`Todos`] #[derive(Debug, Clone, Serialize, Deserialize, Insertable)] #[diesel(table_name=todos)] pub struct CreateTodos { @@ -27,6 +29,7 @@ pub struct CreateTodos { pub completed: bool, } +/// Update Struct for a row in table `todos` for [`Todos`] #[derive(Debug, Clone, Serialize, Deserialize, AsChangeset, Default)] #[diesel(table_name=todos)] pub struct UpdateTodos { diff --git a/test/simple_table_custom_schema_path/models/todos/generated.rs b/test/simple_table_custom_schema_path/models/todos/generated.rs index 3899a332..6c54c945 100644 --- a/test/simple_table_custom_schema_path/models/todos/generated.rs +++ b/test/simple_table_custom_schema_path/models/todos/generated.rs @@ -7,6 +7,7 @@ use diesel::QueryResult; type ConnectionType = diesel::r2d2::PooledConnection>; +/// Struct representing a row in table `todos` #[derive(Debug, Clone, Serialize, Deserialize, Queryable, Selectable)] #[diesel(table_name=todos, primary_key(id))] pub struct Todos { @@ -18,6 +19,7 @@ pub struct Todos { pub updated_at: chrono::DateTime, } +/// Create Struct for a row in table `todos` for [`Todos`] #[derive(Debug, Clone, Serialize, Deserialize, Insertable)] #[diesel(table_name=todos)] pub struct CreateTodos { @@ -26,6 +28,7 @@ pub struct CreateTodos { pub completed: bool, } +/// Update Struct for a row in table `todos` for [`Todos`] #[derive(Debug, Clone, Serialize, Deserialize, AsChangeset, Default)] #[diesel(table_name=todos)] pub struct UpdateTodos { diff --git a/test/simple_table_no_crud/models/todos/generated.rs b/test/simple_table_no_crud/models/todos/generated.rs index bf8379bb..461df952 100644 --- a/test/simple_table_no_crud/models/todos/generated.rs +++ b/test/simple_table_no_crud/models/todos/generated.rs @@ -4,6 +4,7 @@ use crate::diesel::*; use crate::schema::*; use serde::{Deserialize, Serialize}; +/// Struct representing a row in table `todos` #[derive(Debug, Clone, Serialize, Deserialize, Queryable, Selectable)] #[diesel(table_name=todos, primary_key(id))] pub struct Todos { @@ -15,6 +16,7 @@ pub struct Todos { pub updated_at: chrono::DateTime, } +/// Create Struct for a row in table `todos` for [`Todos`] #[derive(Debug, Clone, Serialize, Deserialize, Insertable)] #[diesel(table_name=todos)] pub struct CreateTodos { @@ -23,6 +25,7 @@ pub struct CreateTodos { pub completed: bool, } +/// Update Struct for a row in table `todos` for [`Todos`] #[derive(Debug, Clone, Serialize, Deserialize, AsChangeset, Default)] #[diesel(table_name=todos)] pub struct UpdateTodos { diff --git a/test/simple_table_no_serde/models/todos/generated.rs b/test/simple_table_no_serde/models/todos/generated.rs index 82f61f3b..2668f91d 100644 --- a/test/simple_table_no_serde/models/todos/generated.rs +++ b/test/simple_table_no_serde/models/todos/generated.rs @@ -6,6 +6,7 @@ use diesel::QueryResult; type ConnectionType = diesel::r2d2::PooledConnection>; +/// Struct representing a row in table `todos` #[derive(Debug, Clone, Queryable, Selectable)] #[diesel(table_name=todos, primary_key(id))] pub struct Todos { @@ -17,6 +18,7 @@ pub struct Todos { pub updated_at: chrono::DateTime, } +/// Create Struct for a row in table `todos` for [`Todos`] #[derive(Debug, Clone, Insertable)] #[diesel(table_name=todos)] pub struct CreateTodos { @@ -25,6 +27,7 @@ pub struct CreateTodos { pub completed: bool, } +/// Update Struct for a row in table `todos` for [`Todos`] #[derive(Debug, Clone, AsChangeset, Default)] #[diesel(table_name=todos)] pub struct UpdateTodos { diff --git a/test/single_model_file/models/table1.rs b/test/single_model_file/models/table1.rs index bd66bc49..577367c0 100644 --- a/test/single_model_file/models/table1.rs +++ b/test/single_model_file/models/table1.rs @@ -7,6 +7,7 @@ use diesel::QueryResult; type ConnectionType = diesel::r2d2::PooledConnection>; +/// Struct representing a row in table `table1` #[derive(Debug, Clone, Serialize, Deserialize, Queryable, Selectable)] #[diesel(table_name=table1, primary_key(id))] pub struct Table1 { diff --git a/test/single_model_file/models/table2.rs b/test/single_model_file/models/table2.rs index e6d4ac1c..fc9cea5f 100644 --- a/test/single_model_file/models/table2.rs +++ b/test/single_model_file/models/table2.rs @@ -7,6 +7,7 @@ use diesel::QueryResult; type ConnectionType = diesel::r2d2::PooledConnection>; +/// Struct representing a row in table `table2` #[derive(Debug, Clone, Serialize, Deserialize, Queryable, Selectable)] #[diesel(table_name=table2, primary_key(id))] pub struct Table2 { diff --git a/test/use_statements/models/fang_tasks/generated.rs b/test/use_statements/models/fang_tasks/generated.rs index 3114cd22..f54c4cb6 100644 --- a/test/use_statements/models/fang_tasks/generated.rs +++ b/test/use_statements/models/fang_tasks/generated.rs @@ -7,6 +7,7 @@ use diesel::QueryResult; type ConnectionType = diesel::r2d2::PooledConnection>; +/// Struct representing a row in table `fang_tasks` #[derive(Debug, Clone, Serialize, Deserialize, Queryable, Selectable)] #[diesel(table_name=fang_tasks, primary_key(id))] pub struct FangTasks { @@ -22,6 +23,7 @@ pub struct FangTasks { pub updated_at: chrono::DateTime, } +/// Create Struct for a row in table `fang_tasks` for [`FangTasks`] #[derive(Debug, Clone, Serialize, Deserialize, Insertable)] #[diesel(table_name=fang_tasks)] pub struct CreateFangTasks { @@ -37,6 +39,7 @@ pub struct CreateFangTasks { pub updated_at: chrono::DateTime, } +/// Update Struct for a row in table `fang_tasks` for [`FangTasks`] #[derive(Debug, Clone, Serialize, Deserialize, AsChangeset, Default)] #[diesel(table_name=fang_tasks)] pub struct UpdateFangTasks { From 533a472bc4f6662e89fe5e1cb2f887b7fd9c3ccf Mon Sep 17 00:00:00 2001 From: hasezoey Date: Tue, 31 Oct 2023 14:47:15 +0100 Subject: [PATCH 3/6] feat(code): add doccomments to generated fields of structs --- src/code.rs | 7 +++++ .../models/todos/generated.rs | 3 ++ .../models/todos/generated.rs | 4 +++ .../models/todos/generated.rs | 4 +++ .../models/todos/generated.rs | 12 ++++++++ .../models/todos/generated.rs | 11 +++++++ .../models/todos/generated.rs | 11 +++++++ .../models/tableA/generated.rs | 2 ++ .../models/tableB/generated.rs | 5 ++++ .../models/tableA/generated.rs | 2 ++ .../models/tableB/generated.rs | 5 ++++ .../models/todos/generated.rs | 2 ++ .../models/users/generated.rs | 7 +++++ .../models/table1/generated.rs | 1 + .../models/table2/generated.rs | 1 + .../models/table1/generated.rs | 1 + .../models/table2/generated.rs | 1 + .../models/table1.rs | 1 + .../models/table2.rs | 1 + .../models/table1/generated.rs | 1 + .../models/table2/generated.rs | 1 + test/readonly/models/normal/generated.rs | 4 +++ test/readonly/models/prefixTable/generated.rs | 2 ++ .../models/prefixTableSuffix/generated.rs | 2 ++ test/readonly/models/tableSuffix/generated.rs | 2 ++ test/simple_table/models/todos/generated.rs | 20 +++++++++++++ .../models/todos/generated.rs | 14 +++++++++ .../models/todos/generated.rs | 14 +++++++++ .../models/todos/generated.rs | 14 +++++++++ .../models/todos/generated.rs | 14 +++++++++ test/single_model_file/models/table1.rs | 1 + test/single_model_file/models/table2.rs | 1 + .../models/fang_tasks/generated.rs | 29 +++++++++++++++++++ 33 files changed, 200 insertions(+) diff --git a/src/code.rs b/src/code.rs index a9fb6b73..009a9204 100644 --- a/src/code.rs +++ b/src/code.rs @@ -74,6 +74,8 @@ pub struct StructField { /// Name for the field // TODO: should this be a Ident instead of a string? pub name: String, + /// Actual table column name + pub column_name: String, /// Base Rust type, like "String" or "i32" or "u32" pub base_type: String, /// Indicate that this field is optional @@ -105,6 +107,7 @@ impl From<&ParsedColumnMacro> for StructField { name, base_type, is_optional: value.is_nullable, + column_name: value.column_name.clone(), } } } @@ -313,6 +316,10 @@ impl<'a> Struct<'a> { field_type = format!("Option<{}>", field_type).into(); } + lines.push(format!( + " /// Field representing column `{column_name}`", + column_name = f.column_name + )); lines.push(format!(r#" pub {field_name}: {field_type},"#)); } diff --git a/test/autogenerated_all/models/todos/generated.rs b/test/autogenerated_all/models/todos/generated.rs index 544de025..5a19d65b 100644 --- a/test/autogenerated_all/models/todos/generated.rs +++ b/test/autogenerated_all/models/todos/generated.rs @@ -11,7 +11,9 @@ type ConnectionType = diesel::r2d2::PooledConnection, } diff --git a/test/autogenerated_attributes/models/todos/generated.rs b/test/autogenerated_attributes/models/todos/generated.rs index 5969679d..6dbe6fb5 100644 --- a/test/autogenerated_attributes/models/todos/generated.rs +++ b/test/autogenerated_attributes/models/todos/generated.rs @@ -11,7 +11,9 @@ type ConnectionType = diesel::r2d2::PooledConnection, } diff --git a/test/autogenerated_primary_keys/models/todos/generated.rs b/test/autogenerated_primary_keys/models/todos/generated.rs index 6586a45d..54817c6d 100644 --- a/test/autogenerated_primary_keys/models/todos/generated.rs +++ b/test/autogenerated_primary_keys/models/todos/generated.rs @@ -11,7 +11,9 @@ type ConnectionType = diesel::r2d2::PooledConnection, } diff --git a/test/cleanup_generated_content/models/todos/generated.rs b/test/cleanup_generated_content/models/todos/generated.rs index 61bd082b..ac034f63 100644 --- a/test/cleanup_generated_content/models/todos/generated.rs +++ b/test/cleanup_generated_content/models/todos/generated.rs @@ -11,10 +11,15 @@ type ConnectionType = diesel::r2d2::PooledConnection, + /// Field representing column `updated_at` pub updated_at: chrono::DateTime, } @@ -22,8 +27,11 @@ pub struct Todos { #[derive(Debug, Clone, Serialize, Deserialize, Insertable)] #[diesel(table_name=todos)] pub struct CreateTodos { + /// Field representing column `id` pub id: i32, + /// Field representing column `text` pub text: String, + /// Field representing column `completed` pub completed: bool, } @@ -31,9 +39,13 @@ pub struct CreateTodos { #[derive(Debug, Clone, Serialize, Deserialize, AsChangeset, Default)] #[diesel(table_name=todos)] pub struct UpdateTodos { + /// Field representing column `text` pub text: Option, + /// Field representing column `completed` pub completed: Option, + /// Field representing column `created_at` pub created_at: Option>, + /// Field representing column `updated_at` pub updated_at: Option>, } diff --git a/test/create_update_str_cow/models/todos/generated.rs b/test/create_update_str_cow/models/todos/generated.rs index 61ca2bc6..4f81b51e 100644 --- a/test/create_update_str_cow/models/todos/generated.rs +++ b/test/create_update_str_cow/models/todos/generated.rs @@ -11,9 +11,13 @@ type ConnectionType = diesel::r2d2::PooledConnection, + /// Field representing column `varchar` pub varchar: String, + /// Field representing column `varchar_nullable` pub varchar_nullable: Option, } @@ -21,9 +25,13 @@ pub struct Todos { #[derive(Debug, Clone, Serialize, Deserialize, Insertable)] #[diesel(table_name=todos)] pub struct CreateTodos<'a> { + /// Field representing column `text` pub text: Cow<'a, str>, + /// Field representing column `text_nullable` pub text_nullable: Option>, + /// Field representing column `varchar` pub varchar: Cow<'a, str>, + /// Field representing column `varchar_nullable` pub varchar_nullable: Option>, } @@ -31,8 +39,11 @@ pub struct CreateTodos<'a> { #[derive(Debug, Clone, Serialize, Deserialize, AsChangeset, Default)] #[diesel(table_name=todos)] pub struct UpdateTodos<'a> { + /// Field representing column `text_nullable` pub text_nullable: Option>>, + /// Field representing column `varchar` pub varchar: Option>, + /// Field representing column `varchar_nullable` pub varchar_nullable: Option>>, } diff --git a/test/create_update_str_str/models/todos/generated.rs b/test/create_update_str_str/models/todos/generated.rs index fad9458b..b72a50eb 100644 --- a/test/create_update_str_str/models/todos/generated.rs +++ b/test/create_update_str_str/models/todos/generated.rs @@ -11,9 +11,13 @@ type ConnectionType = diesel::r2d2::PooledConnection, + /// Field representing column `varchar` pub varchar: String, + /// Field representing column `varchar_nullable` pub varchar_nullable: Option, } @@ -21,9 +25,13 @@ pub struct Todos { #[derive(Debug, Clone, Serialize, Deserialize, Insertable)] #[diesel(table_name=todos)] pub struct CreateTodos<'a> { + /// Field representing column `text` pub text: &'a str, + /// Field representing column `text_nullable` pub text_nullable: Option<&'a str>, + /// Field representing column `varchar` pub varchar: &'a str, + /// Field representing column `varchar_nullable` pub varchar_nullable: Option<&'a str>, } @@ -31,8 +39,11 @@ pub struct CreateTodos<'a> { #[derive(Debug, Clone, Serialize, Deserialize, AsChangeset, Default)] #[diesel(table_name=todos)] pub struct UpdateTodos<'a> { + /// Field representing column `text_nullable` pub text_nullable: Option>, + /// Field representing column `varchar` pub varchar: Option<&'a str>, + /// Field representing column `varchar_nullable` pub varchar_nullable: Option>, } diff --git a/test/custom_model_and_schema_path/models/tableA/generated.rs b/test/custom_model_and_schema_path/models/tableA/generated.rs index 7c9ec090..d7cb833d 100644 --- a/test/custom_model_and_schema_path/models/tableA/generated.rs +++ b/test/custom_model_and_schema_path/models/tableA/generated.rs @@ -11,6 +11,7 @@ type ConnectionType = diesel::r2d2::PooledConnection, } diff --git a/test/custom_model_path/models/tableA/generated.rs b/test/custom_model_path/models/tableA/generated.rs index 53a08316..a042ce00 100644 --- a/test/custom_model_path/models/tableA/generated.rs +++ b/test/custom_model_path/models/tableA/generated.rs @@ -11,6 +11,7 @@ type ConnectionType = diesel::r2d2::PooledConnection, } diff --git a/test/manual_primary_keys/models/todos/generated.rs b/test/manual_primary_keys/models/todos/generated.rs index 5f3d0785..6656e541 100644 --- a/test/manual_primary_keys/models/todos/generated.rs +++ b/test/manual_primary_keys/models/todos/generated.rs @@ -11,6 +11,7 @@ type ConnectionType = diesel::r2d2::PooledConnection, } diff --git a/test/once_common_structs/models/table1/generated.rs b/test/once_common_structs/models/table1/generated.rs index f191f20f..229b8990 100644 --- a/test/once_common_structs/models/table1/generated.rs +++ b/test/once_common_structs/models/table1/generated.rs @@ -12,6 +12,7 @@ type ConnectionType = diesel::r2d2::PooledConnection, } diff --git a/test/readonly/models/prefixTable/generated.rs b/test/readonly/models/prefixTable/generated.rs index c045a78c..b9eec814 100644 --- a/test/readonly/models/prefixTable/generated.rs +++ b/test/readonly/models/prefixTable/generated.rs @@ -11,7 +11,9 @@ type ConnectionType = diesel::r2d2::PooledConnection, + /// Field representing column `text` pub text: String, + /// Field representing column `completed` pub completed: bool, + /// Field representing column `type` pub type_: String, + /// Field representing column `created_at` pub created_at: chrono::DateTime, + /// Field representing column `updated_at` pub updated_at: chrono::DateTime, } @@ -25,10 +33,15 @@ pub struct Todos { #[derive(Debug, Clone, Serialize, Deserialize, Insertable)] #[diesel(table_name=todos)] pub struct CreateTodos { + /// Field representing column `unsigned` pub unsigned: u32, + /// Field representing column `unsigned_nullable` pub unsigned_nullable: Option, + /// Field representing column `text` pub text: String, + /// Field representing column `completed` pub completed: bool, + /// Field representing column `type` pub type_: String, } @@ -36,12 +49,19 @@ pub struct CreateTodos { #[derive(Debug, Clone, Serialize, Deserialize, AsChangeset, Default)] #[diesel(table_name=todos)] pub struct UpdateTodos { + /// Field representing column `unsigned` pub unsigned: Option, + /// Field representing column `unsigned_nullable` pub unsigned_nullable: Option>, + /// Field representing column `text` pub text: Option, + /// Field representing column `completed` pub completed: Option, + /// Field representing column `type` pub type_: Option, + /// Field representing column `created_at` pub created_at: Option>, + /// Field representing column `updated_at` pub updated_at: Option>, } diff --git a/test/simple_table_async/models/todos/generated.rs b/test/simple_table_async/models/todos/generated.rs index cb4648e1..95fbaa41 100644 --- a/test/simple_table_async/models/todos/generated.rs +++ b/test/simple_table_async/models/todos/generated.rs @@ -12,11 +12,17 @@ type ConnectionType = diesel_async::pooled_connection::deadpool::Object, + /// Field representing column `updated_at` pub updated_at: chrono::DateTime, } @@ -24,8 +30,11 @@ pub struct Todos { #[derive(Debug, Clone, Serialize, Deserialize, Insertable)] #[diesel(table_name=todos)] pub struct CreateTodos { + /// Field representing column `unsigned` pub unsigned: u32, + /// Field representing column `text` pub text: String, + /// Field representing column `completed` pub completed: bool, } @@ -33,10 +42,15 @@ pub struct CreateTodos { #[derive(Debug, Clone, Serialize, Deserialize, AsChangeset, Default)] #[diesel(table_name=todos)] pub struct UpdateTodos { + /// Field representing column `unsigned` pub unsigned: Option, + /// Field representing column `text` pub text: Option, + /// Field representing column `completed` pub completed: Option, + /// Field representing column `created_at` pub created_at: Option>, + /// Field representing column `updated_at` pub updated_at: Option>, } diff --git a/test/simple_table_custom_schema_path/models/todos/generated.rs b/test/simple_table_custom_schema_path/models/todos/generated.rs index 6c54c945..096f58b0 100644 --- a/test/simple_table_custom_schema_path/models/todos/generated.rs +++ b/test/simple_table_custom_schema_path/models/todos/generated.rs @@ -11,11 +11,17 @@ type ConnectionType = diesel::r2d2::PooledConnection, + /// Field representing column `updated_at` pub updated_at: chrono::DateTime, } @@ -23,8 +29,11 @@ pub struct Todos { #[derive(Debug, Clone, Serialize, Deserialize, Insertable)] #[diesel(table_name=todos)] pub struct CreateTodos { + /// Field representing column `unsigned` pub unsigned: u32, + /// Field representing column `text` pub text: String, + /// Field representing column `completed` pub completed: bool, } @@ -32,10 +41,15 @@ pub struct CreateTodos { #[derive(Debug, Clone, Serialize, Deserialize, AsChangeset, Default)] #[diesel(table_name=todos)] pub struct UpdateTodos { + /// Field representing column `unsigned` pub unsigned: Option, + /// Field representing column `text` pub text: Option, + /// Field representing column `completed` pub completed: Option, + /// Field representing column `created_at` pub created_at: Option>, + /// Field representing column `updated_at` pub updated_at: Option>, } diff --git a/test/simple_table_no_crud/models/todos/generated.rs b/test/simple_table_no_crud/models/todos/generated.rs index 461df952..feca272e 100644 --- a/test/simple_table_no_crud/models/todos/generated.rs +++ b/test/simple_table_no_crud/models/todos/generated.rs @@ -8,11 +8,17 @@ use serde::{Deserialize, Serialize}; #[derive(Debug, Clone, Serialize, Deserialize, Queryable, Selectable)] #[diesel(table_name=todos, primary_key(id))] pub struct Todos { + /// Field representing column `id` pub id: i32, + /// Field representing column `unsigned` pub unsigned: u32, + /// Field representing column `text` pub text: String, + /// Field representing column `completed` pub completed: bool, + /// Field representing column `created_at` pub created_at: chrono::DateTime, + /// Field representing column `updated_at` pub updated_at: chrono::DateTime, } @@ -20,8 +26,11 @@ pub struct Todos { #[derive(Debug, Clone, Serialize, Deserialize, Insertable)] #[diesel(table_name=todos)] pub struct CreateTodos { + /// Field representing column `unsigned` pub unsigned: u32, + /// Field representing column `text` pub text: String, + /// Field representing column `completed` pub completed: bool, } @@ -29,10 +38,15 @@ pub struct CreateTodos { #[derive(Debug, Clone, Serialize, Deserialize, AsChangeset, Default)] #[diesel(table_name=todos)] pub struct UpdateTodos { + /// Field representing column `unsigned` pub unsigned: Option, + /// Field representing column `text` pub text: Option, + /// Field representing column `completed` pub completed: Option, + /// Field representing column `created_at` pub created_at: Option>, + /// Field representing column `updated_at` pub updated_at: Option>, } diff --git a/test/simple_table_no_serde/models/todos/generated.rs b/test/simple_table_no_serde/models/todos/generated.rs index 2668f91d..41fe734a 100644 --- a/test/simple_table_no_serde/models/todos/generated.rs +++ b/test/simple_table_no_serde/models/todos/generated.rs @@ -10,11 +10,17 @@ type ConnectionType = diesel::r2d2::PooledConnection, + /// Field representing column `updated_at` pub updated_at: chrono::DateTime, } @@ -22,8 +28,11 @@ pub struct Todos { #[derive(Debug, Clone, Insertable)] #[diesel(table_name=todos)] pub struct CreateTodos { + /// Field representing column `unsigned` pub unsigned: u32, + /// Field representing column `text` pub text: String, + /// Field representing column `completed` pub completed: bool, } @@ -31,10 +40,15 @@ pub struct CreateTodos { #[derive(Debug, Clone, AsChangeset, Default)] #[diesel(table_name=todos)] pub struct UpdateTodos { + /// Field representing column `unsigned` pub unsigned: Option, + /// Field representing column `text` pub text: Option, + /// Field representing column `completed` pub completed: Option, + /// Field representing column `created_at` pub created_at: Option>, + /// Field representing column `updated_at` pub updated_at: Option>, } diff --git a/test/single_model_file/models/table1.rs b/test/single_model_file/models/table1.rs index 577367c0..3d3a9ccb 100644 --- a/test/single_model_file/models/table1.rs +++ b/test/single_model_file/models/table1.rs @@ -11,6 +11,7 @@ type ConnectionType = diesel::r2d2::PooledConnection, + /// Field representing column `state` pub state: crate::schema::sql_types::FangTaskState, + /// Field representing column `task_type` pub task_type: String, + /// Field representing column `uniq_hash` pub uniq_hash: Option, + /// Field representing column `retries` pub retries: i32, + /// Field representing column `scheduled_at` pub scheduled_at: chrono::DateTime, + /// Field representing column `created_at` pub created_at: chrono::DateTime, + /// Field representing column `updated_at` pub updated_at: chrono::DateTime, } @@ -27,15 +37,25 @@ pub struct FangTasks { #[derive(Debug, Clone, Serialize, Deserialize, Insertable)] #[diesel(table_name=fang_tasks)] pub struct CreateFangTasks { + /// Field representing column `id` pub id: uuid::Uuid, + /// Field representing column `metadata` pub metadata: serde_json::Value, + /// Field representing column `error_message` pub error_message: Option, + /// Field representing column `state` pub state: crate::schema::sql_types::FangTaskState, + /// Field representing column `task_type` pub task_type: String, + /// Field representing column `uniq_hash` pub uniq_hash: Option, + /// Field representing column `retries` pub retries: i32, + /// Field representing column `scheduled_at` pub scheduled_at: chrono::DateTime, + /// Field representing column `created_at` pub created_at: chrono::DateTime, + /// Field representing column `updated_at` pub updated_at: chrono::DateTime, } @@ -43,14 +63,23 @@ pub struct CreateFangTasks { #[derive(Debug, Clone, Serialize, Deserialize, AsChangeset, Default)] #[diesel(table_name=fang_tasks)] pub struct UpdateFangTasks { + /// Field representing column `metadata` pub metadata: Option, + /// Field representing column `error_message` pub error_message: Option>, + /// Field representing column `state` pub state: Option, + /// Field representing column `task_type` pub task_type: Option, + /// Field representing column `uniq_hash` pub uniq_hash: Option>, + /// Field representing column `retries` pub retries: Option, + /// Field representing column `scheduled_at` pub scheduled_at: Option>, + /// Field representing column `created_at` pub created_at: Option>, + /// Field representing column `updated_at` pub updated_at: Option>, } From 7525cdafae9aae7be411c98bf125f35c1c488d17 Mon Sep 17 00:00:00 2001 From: hasezoey Date: Tue, 31 Oct 2023 14:48:08 +0100 Subject: [PATCH 4/6] feat(code): add doccomments to generated functions --- src/code.rs | 12 ++++++++++++ test/autogenerated_all/models/todos/generated.rs | 4 ++++ .../models/todos/generated.rs | 4 ++++ .../models/todos/generated.rs | 4 ++++ .../models/todos/generated.rs | 4 ++++ test/create_update_str_cow/models/todos/generated.rs | 4 ++++ test/create_update_str_str/models/todos/generated.rs | 4 ++++ .../models/tableA/generated.rs | 3 +++ .../models/tableB/generated.rs | 4 ++++ test/custom_model_path/models/tableA/generated.rs | 3 +++ test/custom_model_path/models/tableB/generated.rs | 4 ++++ test/manual_primary_keys/models/todos/generated.rs | 3 +++ test/multiple_primary_keys/models/users/generated.rs | 4 ++++ test/once_common_structs/models/table1/generated.rs | 3 +++ test/once_common_structs/models/table2/generated.rs | 3 +++ .../models/table1/generated.rs | 3 +++ .../models/table2/generated.rs | 3 +++ .../models/table1.rs | 3 +++ .../models/table2.rs | 3 +++ test/once_connection_type/models/table1/generated.rs | 3 +++ test/once_connection_type/models/table2/generated.rs | 3 +++ test/readonly/models/normal/generated.rs | 4 ++++ test/readonly/models/prefixTable/generated.rs | 1 + test/readonly/models/prefixTableSuffix/generated.rs | 1 + test/readonly/models/tableSuffix/generated.rs | 1 + test/simple_table/models/todos/generated.rs | 4 ++++ test/simple_table_async/models/todos/generated.rs | 4 ++++ .../models/todos/generated.rs | 4 ++++ test/simple_table_no_serde/models/todos/generated.rs | 4 ++++ test/single_model_file/models/table1.rs | 3 +++ test/single_model_file/models/table2.rs | 3 +++ test/use_statements/models/fang_tasks/generated.rs | 4 ++++ 32 files changed, 114 insertions(+) diff --git a/src/code.rs b/src/code.rs index 009a9204..aeb961ee 100644 --- a/src/code.rs +++ b/src/code.rs @@ -454,6 +454,7 @@ fn build_table_fns( if create_struct.has_fields() { buffer.push_str(&format!( r##" + /// Insert a new row into `{table_name}` with a given [`{create_struct_identifier}`] pub{async_keyword} fn create(db: &mut ConnectionType, item: &{create_struct_identifier}) -> QueryResult {{ use {schema_path}{table_name}::dsl::*; @@ -464,6 +465,7 @@ fn build_table_fns( } else { buffer.push_str(&format!( r##" + /// Insert a new row into `{table_name}` with all default values pub{async_keyword} fn create(db: &mut ConnectionType) -> QueryResult {{ use {schema_path}{table_name}::dsl::*; @@ -474,8 +476,16 @@ fn build_table_fns( } } + // this will also trigger for 0 primary keys, but diesel currently does not support that + let key_maybe_multiple = if primary_column_name_and_type.len() <= 1 { + "key" + } else { + "keys" + }; + buffer.push_str(&format!( r##" + /// Get a row from `{table_name}`, identified by the primary {key_maybe_multiple} pub{async_keyword} fn read(db: &mut ConnectionType, {item_id_params}) -> QueryResult {{ use {schema_path}{table_name}::dsl::*; @@ -514,6 +524,7 @@ fn build_table_fns( // we should generate an update() method. buffer.push_str(&format!(r##" + /// Update a row in `{table_name}`, identified by the primary {key_maybe_multiple} with [`{update_struct_identifier}`] pub{async_keyword} fn update(db: &mut ConnectionType, {item_id_params}, item: &{update_struct_identifier}) -> QueryResult {{ use {schema_path}{table_name}::dsl::*; @@ -525,6 +536,7 @@ fn build_table_fns( if !is_readonly { buffer.push_str(&format!( r##" + /// Delete a row in `{table_name}`, identified by the primary {key_maybe_multiple} pub{async_keyword} fn delete(db: &mut ConnectionType, {item_id_params}) -> QueryResult {{ use {schema_path}{table_name}::dsl::*; diff --git a/test/autogenerated_all/models/todos/generated.rs b/test/autogenerated_all/models/todos/generated.rs index 5a19d65b..bde26321 100644 --- a/test/autogenerated_all/models/todos/generated.rs +++ b/test/autogenerated_all/models/todos/generated.rs @@ -36,12 +36,14 @@ pub struct PaginationResult { } impl Todos { + /// Insert a new row into `todos` with all default values pub fn create(db: &mut ConnectionType) -> QueryResult { use crate::schema::todos::dsl::*; insert_into(todos).default_values().get_result::(db) } + /// Get a row from `todos`, identified by the primary key pub fn read(db: &mut ConnectionType, param_id: i32) -> QueryResult { use crate::schema::todos::dsl::*; @@ -66,12 +68,14 @@ impl Todos { }) } + /// Update a row in `todos`, identified by the primary key with [`UpdateTodos`] pub fn update(db: &mut ConnectionType, param_id: i32, item: &UpdateTodos) -> QueryResult { use crate::schema::todos::dsl::*; diesel::update(todos.filter(id.eq(param_id))).set(item).get_result(db) } + /// Delete a row in `todos`, identified by the primary key pub fn delete(db: &mut ConnectionType, param_id: i32) -> QueryResult { use crate::schema::todos::dsl::*; diff --git a/test/autogenerated_attributes/models/todos/generated.rs b/test/autogenerated_attributes/models/todos/generated.rs index 6dbe6fb5..cd36e192 100644 --- a/test/autogenerated_attributes/models/todos/generated.rs +++ b/test/autogenerated_attributes/models/todos/generated.rs @@ -44,12 +44,14 @@ pub struct PaginationResult { } impl Todos { + /// Insert a new row into `todos` with a given [`CreateTodos`] pub fn create(db: &mut ConnectionType, item: &CreateTodos) -> QueryResult { use crate::schema::todos::dsl::*; insert_into(todos).values(item).get_result::(db) } + /// Get a row from `todos`, identified by the primary key pub fn read(db: &mut ConnectionType, param_id: i32) -> QueryResult { use crate::schema::todos::dsl::*; @@ -74,12 +76,14 @@ impl Todos { }) } + /// Update a row in `todos`, identified by the primary key with [`UpdateTodos`] pub fn update(db: &mut ConnectionType, param_id: i32, item: &UpdateTodos) -> QueryResult { use crate::schema::todos::dsl::*; diesel::update(todos.filter(id.eq(param_id))).set(item).get_result(db) } + /// Delete a row in `todos`, identified by the primary key pub fn delete(db: &mut ConnectionType, param_id: i32) -> QueryResult { use crate::schema::todos::dsl::*; diff --git a/test/autogenerated_primary_keys/models/todos/generated.rs b/test/autogenerated_primary_keys/models/todos/generated.rs index 54817c6d..e14bb1c2 100644 --- a/test/autogenerated_primary_keys/models/todos/generated.rs +++ b/test/autogenerated_primary_keys/models/todos/generated.rs @@ -44,12 +44,14 @@ pub struct PaginationResult { } impl Todos { + /// Insert a new row into `todos` with a given [`CreateTodos`] pub fn create(db: &mut ConnectionType, item: &CreateTodos) -> QueryResult { use crate::schema::todos::dsl::*; insert_into(todos).values(item).get_result::(db) } + /// Get a row from `todos`, identified by the primary key pub fn read(db: &mut ConnectionType, param_id: i32) -> QueryResult { use crate::schema::todos::dsl::*; @@ -74,12 +76,14 @@ impl Todos { }) } + /// Update a row in `todos`, identified by the primary key with [`UpdateTodos`] pub fn update(db: &mut ConnectionType, param_id: i32, item: &UpdateTodos) -> QueryResult { use crate::schema::todos::dsl::*; diesel::update(todos.filter(id.eq(param_id))).set(item).get_result(db) } + /// Delete a row in `todos`, identified by the primary key pub fn delete(db: &mut ConnectionType, param_id: i32) -> QueryResult { use crate::schema::todos::dsl::*; diff --git a/test/cleanup_generated_content/models/todos/generated.rs b/test/cleanup_generated_content/models/todos/generated.rs index ac034f63..3d657ae1 100644 --- a/test/cleanup_generated_content/models/todos/generated.rs +++ b/test/cleanup_generated_content/models/todos/generated.rs @@ -60,12 +60,14 @@ pub struct PaginationResult { } impl Todos { + /// Insert a new row into `todos` with a given [`CreateTodos`] pub fn create(db: &mut ConnectionType, item: &CreateTodos) -> QueryResult { use crate::schema::todos::dsl::*; insert_into(todos).values(item).get_result::(db) } + /// Get a row from `todos`, identified by the primary key pub fn read(db: &mut ConnectionType, param_id: i32) -> QueryResult { use crate::schema::todos::dsl::*; @@ -90,12 +92,14 @@ impl Todos { }) } + /// Update a row in `todos`, identified by the primary key with [`UpdateTodos`] pub fn update(db: &mut ConnectionType, param_id: i32, item: &UpdateTodos) -> QueryResult { use crate::schema::todos::dsl::*; diesel::update(todos.filter(id.eq(param_id))).set(item).get_result(db) } + /// Delete a row in `todos`, identified by the primary key pub fn delete(db: &mut ConnectionType, param_id: i32) -> QueryResult { use crate::schema::todos::dsl::*; diff --git a/test/create_update_str_cow/models/todos/generated.rs b/test/create_update_str_cow/models/todos/generated.rs index 4f81b51e..5b733699 100644 --- a/test/create_update_str_cow/models/todos/generated.rs +++ b/test/create_update_str_cow/models/todos/generated.rs @@ -58,12 +58,14 @@ pub struct PaginationResult { } impl Todos { + /// Insert a new row into `todos` with a given [`CreateTodos`] pub fn create(db: &mut ConnectionType, item: &CreateTodos) -> QueryResult { use crate::schema::todos::dsl::*; insert_into(todos).values(item).get_result::(db) } + /// Get a row from `todos`, identified by the primary key pub fn read(db: &mut ConnectionType, param_text: String) -> QueryResult { use crate::schema::todos::dsl::*; @@ -88,12 +90,14 @@ impl Todos { }) } + /// Update a row in `todos`, identified by the primary key with [`UpdateTodos`] pub fn update(db: &mut ConnectionType, param_text: String, item: &UpdateTodos) -> QueryResult { use crate::schema::todos::dsl::*; diesel::update(todos.filter(text.eq(param_text))).set(item).get_result(db) } + /// Delete a row in `todos`, identified by the primary key pub fn delete(db: &mut ConnectionType, param_text: String) -> QueryResult { use crate::schema::todos::dsl::*; diff --git a/test/create_update_str_str/models/todos/generated.rs b/test/create_update_str_str/models/todos/generated.rs index b72a50eb..944be935 100644 --- a/test/create_update_str_str/models/todos/generated.rs +++ b/test/create_update_str_str/models/todos/generated.rs @@ -58,12 +58,14 @@ pub struct PaginationResult { } impl Todos { + /// Insert a new row into `todos` with a given [`CreateTodos`] pub fn create(db: &mut ConnectionType, item: &CreateTodos) -> QueryResult { use crate::schema::todos::dsl::*; insert_into(todos).values(item).get_result::(db) } + /// Get a row from `todos`, identified by the primary key pub fn read(db: &mut ConnectionType, param_text: String) -> QueryResult { use crate::schema::todos::dsl::*; @@ -88,12 +90,14 @@ impl Todos { }) } + /// Update a row in `todos`, identified by the primary key with [`UpdateTodos`] pub fn update(db: &mut ConnectionType, param_text: String, item: &UpdateTodos) -> QueryResult { use crate::schema::todos::dsl::*; diesel::update(todos.filter(text.eq(param_text))).set(item).get_result(db) } + /// Delete a row in `todos`, identified by the primary key pub fn delete(db: &mut ConnectionType, param_text: String) -> QueryResult { use crate::schema::todos::dsl::*; diff --git a/test/custom_model_and_schema_path/models/tableA/generated.rs b/test/custom_model_and_schema_path/models/tableA/generated.rs index d7cb833d..ea87f5fd 100644 --- a/test/custom_model_and_schema_path/models/tableA/generated.rs +++ b/test/custom_model_and_schema_path/models/tableA/generated.rs @@ -34,12 +34,14 @@ pub struct PaginationResult { } impl TableA { + /// Insert a new row into `tableA` with a given [`CreateTableA`] pub fn create(db: &mut ConnectionType, item: &CreateTableA) -> QueryResult { use crate::data::schema::tableA::dsl::*; insert_into(tableA).values(item).get_result::(db) } + /// Get a row from `tableA`, identified by the primary key pub fn read(db: &mut ConnectionType, param__id: i32) -> QueryResult { use crate::data::schema::tableA::dsl::*; @@ -64,6 +66,7 @@ impl TableA { }) } + /// Delete a row in `tableA`, identified by the primary key pub fn delete(db: &mut ConnectionType, param__id: i32) -> QueryResult { use crate::data::schema::tableA::dsl::*; diff --git a/test/custom_model_and_schema_path/models/tableB/generated.rs b/test/custom_model_and_schema_path/models/tableB/generated.rs index 9b2e5dee..d653d45d 100644 --- a/test/custom_model_and_schema_path/models/tableB/generated.rs +++ b/test/custom_model_and_schema_path/models/tableB/generated.rs @@ -47,12 +47,14 @@ pub struct PaginationResult { } impl TableB { + /// Insert a new row into `tableB` with a given [`CreateTableB`] pub fn create(db: &mut ConnectionType, item: &CreateTableB) -> QueryResult { use crate::data::schema::tableB::dsl::*; insert_into(tableB).values(item).get_result::(db) } + /// Get a row from `tableB`, identified by the primary key pub fn read(db: &mut ConnectionType, param__id: i32) -> QueryResult { use crate::data::schema::tableB::dsl::*; @@ -77,12 +79,14 @@ impl TableB { }) } + /// Update a row in `tableB`, identified by the primary key with [`UpdateTableB`] pub fn update(db: &mut ConnectionType, param__id: i32, item: &UpdateTableB) -> QueryResult { use crate::data::schema::tableB::dsl::*; diesel::update(tableB.filter(_id.eq(param__id))).set(item).get_result(db) } + /// Delete a row in `tableB`, identified by the primary key pub fn delete(db: &mut ConnectionType, param__id: i32) -> QueryResult { use crate::data::schema::tableB::dsl::*; diff --git a/test/custom_model_path/models/tableA/generated.rs b/test/custom_model_path/models/tableA/generated.rs index a042ce00..806a7178 100644 --- a/test/custom_model_path/models/tableA/generated.rs +++ b/test/custom_model_path/models/tableA/generated.rs @@ -34,12 +34,14 @@ pub struct PaginationResult { } impl TableA { + /// Insert a new row into `tableA` with a given [`CreateTableA`] pub fn create(db: &mut ConnectionType, item: &CreateTableA) -> QueryResult { use crate::schema::tableA::dsl::*; insert_into(tableA).values(item).get_result::(db) } + /// Get a row from `tableA`, identified by the primary key pub fn read(db: &mut ConnectionType, param__id: i32) -> QueryResult { use crate::schema::tableA::dsl::*; @@ -64,6 +66,7 @@ impl TableA { }) } + /// Delete a row in `tableA`, identified by the primary key pub fn delete(db: &mut ConnectionType, param__id: i32) -> QueryResult { use crate::schema::tableA::dsl::*; diff --git a/test/custom_model_path/models/tableB/generated.rs b/test/custom_model_path/models/tableB/generated.rs index 3ab17560..991abc14 100644 --- a/test/custom_model_path/models/tableB/generated.rs +++ b/test/custom_model_path/models/tableB/generated.rs @@ -47,12 +47,14 @@ pub struct PaginationResult { } impl TableB { + /// Insert a new row into `tableB` with a given [`CreateTableB`] pub fn create(db: &mut ConnectionType, item: &CreateTableB) -> QueryResult { use crate::schema::tableB::dsl::*; insert_into(tableB).values(item).get_result::(db) } + /// Get a row from `tableB`, identified by the primary key pub fn read(db: &mut ConnectionType, param__id: i32) -> QueryResult { use crate::schema::tableB::dsl::*; @@ -77,12 +79,14 @@ impl TableB { }) } + /// Update a row in `tableB`, identified by the primary key with [`UpdateTableB`] pub fn update(db: &mut ConnectionType, param__id: i32, item: &UpdateTableB) -> QueryResult { use crate::schema::tableB::dsl::*; diesel::update(tableB.filter(_id.eq(param__id))).set(item).get_result(db) } + /// Delete a row in `tableB`, identified by the primary key pub fn delete(db: &mut ConnectionType, param__id: i32) -> QueryResult { use crate::schema::tableB::dsl::*; diff --git a/test/manual_primary_keys/models/todos/generated.rs b/test/manual_primary_keys/models/todos/generated.rs index 6656e541..ac003634 100644 --- a/test/manual_primary_keys/models/todos/generated.rs +++ b/test/manual_primary_keys/models/todos/generated.rs @@ -34,12 +34,14 @@ pub struct PaginationResult { } impl Todos { + /// Insert a new row into `todos` with a given [`CreateTodos`] pub fn create(db: &mut ConnectionType, item: &CreateTodos) -> QueryResult { use crate::schema::todos::dsl::*; insert_into(todos).values(item).get_result::(db) } + /// Get a row from `todos`, identified by the primary key pub fn read(db: &mut ConnectionType, param_id: i32) -> QueryResult { use crate::schema::todos::dsl::*; @@ -64,6 +66,7 @@ impl Todos { }) } + /// Delete a row in `todos`, identified by the primary key pub fn delete(db: &mut ConnectionType, param_id: i32) -> QueryResult { use crate::schema::todos::dsl::*; diff --git a/test/multiple_primary_keys/models/users/generated.rs b/test/multiple_primary_keys/models/users/generated.rs index 88ac7562..1ffa1f2a 100644 --- a/test/multiple_primary_keys/models/users/generated.rs +++ b/test/multiple_primary_keys/models/users/generated.rs @@ -50,12 +50,14 @@ pub struct PaginationResult { } impl Users { + /// Insert a new row into `users` with a given [`CreateUsers`] pub fn create(db: &mut ConnectionType, item: &CreateUsers) -> QueryResult { use crate::schema::users::dsl::*; insert_into(users).values(item).get_result::(db) } + /// Get a row from `users`, identified by the primary keys pub fn read(db: &mut ConnectionType, param_name: String, param_address: String) -> QueryResult { use crate::schema::users::dsl::*; @@ -80,12 +82,14 @@ impl Users { }) } + /// Update a row in `users`, identified by the primary keys with [`UpdateUsers`] pub fn update(db: &mut ConnectionType, param_name: String, param_address: String, item: &UpdateUsers) -> QueryResult { use crate::schema::users::dsl::*; diesel::update(users.filter(name.eq(param_name)).filter(address.eq(param_address))).set(item).get_result(db) } + /// Delete a row in `users`, identified by the primary keys pub fn delete(db: &mut ConnectionType, param_name: String, param_address: String) -> QueryResult { use crate::schema::users::dsl::*; diff --git a/test/once_common_structs/models/table1/generated.rs b/test/once_common_structs/models/table1/generated.rs index 229b8990..ccbaa099 100644 --- a/test/once_common_structs/models/table1/generated.rs +++ b/test/once_common_structs/models/table1/generated.rs @@ -17,12 +17,14 @@ pub struct Table1 { } impl Table1 { + /// Insert a new row into `table1` with all default values pub fn create(db: &mut ConnectionType) -> QueryResult { use crate::schema::table1::dsl::*; insert_into(table1).default_values().get_result::(db) } + /// Get a row from `table1`, identified by the primary key pub fn read(db: &mut ConnectionType, param_id: i32) -> QueryResult { use crate::schema::table1::dsl::*; @@ -47,6 +49,7 @@ impl Table1 { }) } + /// Delete a row in `table1`, identified by the primary key pub fn delete(db: &mut ConnectionType, param_id: i32) -> QueryResult { use crate::schema::table1::dsl::*; diff --git a/test/once_common_structs/models/table2/generated.rs b/test/once_common_structs/models/table2/generated.rs index c202341c..6a772fee 100644 --- a/test/once_common_structs/models/table2/generated.rs +++ b/test/once_common_structs/models/table2/generated.rs @@ -17,12 +17,14 @@ pub struct Table2 { } impl Table2 { + /// Insert a new row into `table2` with all default values pub fn create(db: &mut ConnectionType) -> QueryResult { use crate::schema::table2::dsl::*; insert_into(table2).default_values().get_result::(db) } + /// Get a row from `table2`, identified by the primary key pub fn read(db: &mut ConnectionType, param_id: i32) -> QueryResult { use crate::schema::table2::dsl::*; @@ -47,6 +49,7 @@ impl Table2 { }) } + /// Delete a row in `table2`, identified by the primary key pub fn delete(db: &mut ConnectionType, param_id: i32) -> QueryResult { use crate::schema::table2::dsl::*; diff --git a/test/once_common_structs_once_connection_type/models/table1/generated.rs b/test/once_common_structs_once_connection_type/models/table1/generated.rs index f3700c38..72877763 100644 --- a/test/once_common_structs_once_connection_type/models/table1/generated.rs +++ b/test/once_common_structs_once_connection_type/models/table1/generated.rs @@ -15,12 +15,14 @@ pub struct Table1 { } impl Table1 { + /// Insert a new row into `table1` with all default values pub fn create(db: &mut ConnectionType) -> QueryResult { use crate::schema::table1::dsl::*; insert_into(table1).default_values().get_result::(db) } + /// Get a row from `table1`, identified by the primary key pub fn read(db: &mut ConnectionType, param_id: i32) -> QueryResult { use crate::schema::table1::dsl::*; @@ -45,6 +47,7 @@ impl Table1 { }) } + /// Delete a row in `table1`, identified by the primary key pub fn delete(db: &mut ConnectionType, param_id: i32) -> QueryResult { use crate::schema::table1::dsl::*; diff --git a/test/once_common_structs_once_connection_type/models/table2/generated.rs b/test/once_common_structs_once_connection_type/models/table2/generated.rs index 1180fbf5..83a919b8 100644 --- a/test/once_common_structs_once_connection_type/models/table2/generated.rs +++ b/test/once_common_structs_once_connection_type/models/table2/generated.rs @@ -15,12 +15,14 @@ pub struct Table2 { } impl Table2 { + /// Insert a new row into `table2` with all default values pub fn create(db: &mut ConnectionType) -> QueryResult { use crate::schema::table2::dsl::*; insert_into(table2).default_values().get_result::(db) } + /// Get a row from `table2`, identified by the primary key pub fn read(db: &mut ConnectionType, param_id: i32) -> QueryResult { use crate::schema::table2::dsl::*; @@ -45,6 +47,7 @@ impl Table2 { }) } + /// Delete a row in `table2`, identified by the primary key pub fn delete(db: &mut ConnectionType, param_id: i32) -> QueryResult { use crate::schema::table2::dsl::*; diff --git a/test/once_common_structs_once_connection_type_single_file/models/table1.rs b/test/once_common_structs_once_connection_type_single_file/models/table1.rs index f3700c38..72877763 100644 --- a/test/once_common_structs_once_connection_type_single_file/models/table1.rs +++ b/test/once_common_structs_once_connection_type_single_file/models/table1.rs @@ -15,12 +15,14 @@ pub struct Table1 { } impl Table1 { + /// Insert a new row into `table1` with all default values pub fn create(db: &mut ConnectionType) -> QueryResult { use crate::schema::table1::dsl::*; insert_into(table1).default_values().get_result::(db) } + /// Get a row from `table1`, identified by the primary key pub fn read(db: &mut ConnectionType, param_id: i32) -> QueryResult { use crate::schema::table1::dsl::*; @@ -45,6 +47,7 @@ impl Table1 { }) } + /// Delete a row in `table1`, identified by the primary key pub fn delete(db: &mut ConnectionType, param_id: i32) -> QueryResult { use crate::schema::table1::dsl::*; diff --git a/test/once_common_structs_once_connection_type_single_file/models/table2.rs b/test/once_common_structs_once_connection_type_single_file/models/table2.rs index 1180fbf5..83a919b8 100644 --- a/test/once_common_structs_once_connection_type_single_file/models/table2.rs +++ b/test/once_common_structs_once_connection_type_single_file/models/table2.rs @@ -15,12 +15,14 @@ pub struct Table2 { } impl Table2 { + /// Insert a new row into `table2` with all default values pub fn create(db: &mut ConnectionType) -> QueryResult { use crate::schema::table2::dsl::*; insert_into(table2).default_values().get_result::(db) } + /// Get a row from `table2`, identified by the primary key pub fn read(db: &mut ConnectionType, param_id: i32) -> QueryResult { use crate::schema::table2::dsl::*; @@ -45,6 +47,7 @@ impl Table2 { }) } + /// Delete a row in `table2`, identified by the primary key pub fn delete(db: &mut ConnectionType, param_id: i32) -> QueryResult { use crate::schema::table2::dsl::*; diff --git a/test/once_connection_type/models/table1/generated.rs b/test/once_connection_type/models/table1/generated.rs index 20341f48..e34c4efa 100644 --- a/test/once_connection_type/models/table1/generated.rs +++ b/test/once_connection_type/models/table1/generated.rs @@ -25,12 +25,14 @@ pub struct PaginationResult { } impl Table1 { + /// Insert a new row into `table1` with all default values pub fn create(db: &mut ConnectionType) -> QueryResult { use crate::schema::table1::dsl::*; insert_into(table1).default_values().get_result::(db) } + /// Get a row from `table1`, identified by the primary key pub fn read(db: &mut ConnectionType, param_id: i32) -> QueryResult { use crate::schema::table1::dsl::*; @@ -55,6 +57,7 @@ impl Table1 { }) } + /// Delete a row in `table1`, identified by the primary key pub fn delete(db: &mut ConnectionType, param_id: i32) -> QueryResult { use crate::schema::table1::dsl::*; diff --git a/test/once_connection_type/models/table2/generated.rs b/test/once_connection_type/models/table2/generated.rs index 2edaf81c..c919d56a 100644 --- a/test/once_connection_type/models/table2/generated.rs +++ b/test/once_connection_type/models/table2/generated.rs @@ -25,12 +25,14 @@ pub struct PaginationResult { } impl Table2 { + /// Insert a new row into `table2` with all default values pub fn create(db: &mut ConnectionType) -> QueryResult { use crate::schema::table2::dsl::*; insert_into(table2).default_values().get_result::(db) } + /// Get a row from `table2`, identified by the primary key pub fn read(db: &mut ConnectionType, param_id: i32) -> QueryResult { use crate::schema::table2::dsl::*; @@ -55,6 +57,7 @@ impl Table2 { }) } + /// Delete a row in `table2`, identified by the primary key pub fn delete(db: &mut ConnectionType, param_id: i32) -> QueryResult { use crate::schema::table2::dsl::*; diff --git a/test/readonly/models/normal/generated.rs b/test/readonly/models/normal/generated.rs index 8be73ace..12e73d3a 100644 --- a/test/readonly/models/normal/generated.rs +++ b/test/readonly/models/normal/generated.rs @@ -44,12 +44,14 @@ pub struct PaginationResult { } impl Normal { + /// Insert a new row into `normal` with a given [`CreateNormal`] pub fn create(db: &mut ConnectionType, item: &CreateNormal) -> QueryResult { use crate::schema::normal::dsl::*; insert_into(normal).values(item).get_result::(db) } + /// Get a row from `normal`, identified by the primary key pub fn read(db: &mut ConnectionType, param_id: i32) -> QueryResult { use crate::schema::normal::dsl::*; @@ -74,12 +76,14 @@ impl Normal { }) } + /// Update a row in `normal`, identified by the primary key with [`UpdateNormal`] pub fn update(db: &mut ConnectionType, param_id: i32, item: &UpdateNormal) -> QueryResult { use crate::schema::normal::dsl::*; diesel::update(normal.filter(id.eq(param_id))).set(item).get_result(db) } + /// Delete a row in `normal`, identified by the primary key pub fn delete(db: &mut ConnectionType, param_id: i32) -> QueryResult { use crate::schema::normal::dsl::*; diff --git a/test/readonly/models/prefixTable/generated.rs b/test/readonly/models/prefixTable/generated.rs index b9eec814..51dae75c 100644 --- a/test/readonly/models/prefixTable/generated.rs +++ b/test/readonly/models/prefixTable/generated.rs @@ -28,6 +28,7 @@ pub struct PaginationResult { } impl PrefixTable { + /// Get a row from `prefixTable`, identified by the primary key pub fn read(db: &mut ConnectionType, param_id: i32) -> QueryResult { use crate::schema::prefixTable::dsl::*; diff --git a/test/readonly/models/prefixTableSuffix/generated.rs b/test/readonly/models/prefixTableSuffix/generated.rs index ba5cb942..6ee56337 100644 --- a/test/readonly/models/prefixTableSuffix/generated.rs +++ b/test/readonly/models/prefixTableSuffix/generated.rs @@ -28,6 +28,7 @@ pub struct PaginationResult { } impl PrefixTableSuffix { + /// Get a row from `prefixTableSuffix`, identified by the primary key pub fn read(db: &mut ConnectionType, param_id: i32) -> QueryResult { use crate::schema::prefixTableSuffix::dsl::*; diff --git a/test/readonly/models/tableSuffix/generated.rs b/test/readonly/models/tableSuffix/generated.rs index 23c80d38..5846d1e2 100644 --- a/test/readonly/models/tableSuffix/generated.rs +++ b/test/readonly/models/tableSuffix/generated.rs @@ -28,6 +28,7 @@ pub struct PaginationResult { } impl TableSuffix { + /// Get a row from `tableSuffix`, identified by the primary key pub fn read(db: &mut ConnectionType, param_id: i32) -> QueryResult { use crate::schema::tableSuffix::dsl::*; diff --git a/test/simple_table/models/todos/generated.rs b/test/simple_table/models/todos/generated.rs index 708ac442..d6ee2166 100644 --- a/test/simple_table/models/todos/generated.rs +++ b/test/simple_table/models/todos/generated.rs @@ -76,12 +76,14 @@ pub struct PaginationResult { } impl Todos { + /// Insert a new row into `todos` with a given [`CreateTodos`] pub fn create(db: &mut ConnectionType, item: &CreateTodos) -> QueryResult { use crate::schema::todos::dsl::*; insert_into(todos).values(item).get_result::(db) } + /// Get a row from `todos`, identified by the primary key pub fn read(db: &mut ConnectionType, param_id: i32) -> QueryResult { use crate::schema::todos::dsl::*; @@ -106,12 +108,14 @@ impl Todos { }) } + /// Update a row in `todos`, identified by the primary key with [`UpdateTodos`] pub fn update(db: &mut ConnectionType, param_id: i32, item: &UpdateTodos) -> QueryResult { use crate::schema::todos::dsl::*; diesel::update(todos.filter(id.eq(param_id))).set(item).get_result(db) } + /// Delete a row in `todos`, identified by the primary key pub fn delete(db: &mut ConnectionType, param_id: i32) -> QueryResult { use crate::schema::todos::dsl::*; diff --git a/test/simple_table_async/models/todos/generated.rs b/test/simple_table_async/models/todos/generated.rs index 95fbaa41..305e5818 100644 --- a/test/simple_table_async/models/todos/generated.rs +++ b/test/simple_table_async/models/todos/generated.rs @@ -65,12 +65,14 @@ pub struct PaginationResult { } impl Todos { + /// Insert a new row into `todos` with a given [`CreateTodos`] pub async fn create(db: &mut ConnectionType, item: &CreateTodos) -> QueryResult { use crate::schema::todos::dsl::*; insert_into(todos).values(item).get_result::(db).await } + /// Get a row from `todos`, identified by the primary key pub async fn read(db: &mut ConnectionType, param_id: i32) -> QueryResult { use crate::schema::todos::dsl::*; @@ -95,12 +97,14 @@ impl Todos { }) } + /// Update a row in `todos`, identified by the primary key with [`UpdateTodos`] pub async fn update(db: &mut ConnectionType, param_id: i32, item: &UpdateTodos) -> QueryResult { use crate::schema::todos::dsl::*; diesel::update(todos.filter(id.eq(param_id))).set(item).get_result(db).await } + /// Delete a row in `todos`, identified by the primary key pub async fn delete(db: &mut ConnectionType, param_id: i32) -> QueryResult { use crate::schema::todos::dsl::*; diff --git a/test/simple_table_custom_schema_path/models/todos/generated.rs b/test/simple_table_custom_schema_path/models/todos/generated.rs index 096f58b0..44775506 100644 --- a/test/simple_table_custom_schema_path/models/todos/generated.rs +++ b/test/simple_table_custom_schema_path/models/todos/generated.rs @@ -64,12 +64,14 @@ pub struct PaginationResult { } impl Todos { + /// Insert a new row into `todos` with a given [`CreateTodos`] pub fn create(db: &mut ConnectionType, item: &CreateTodos) -> QueryResult { use crate::data::schema::todos::dsl::*; insert_into(todos).values(item).get_result::(db) } + /// Get a row from `todos`, identified by the primary key pub fn read(db: &mut ConnectionType, param_id: i32) -> QueryResult { use crate::data::schema::todos::dsl::*; @@ -94,12 +96,14 @@ impl Todos { }) } + /// Update a row in `todos`, identified by the primary key with [`UpdateTodos`] pub fn update(db: &mut ConnectionType, param_id: i32, item: &UpdateTodos) -> QueryResult { use crate::data::schema::todos::dsl::*; diesel::update(todos.filter(id.eq(param_id))).set(item).get_result(db) } + /// Delete a row in `todos`, identified by the primary key pub fn delete(db: &mut ConnectionType, param_id: i32) -> QueryResult { use crate::data::schema::todos::dsl::*; diff --git a/test/simple_table_no_serde/models/todos/generated.rs b/test/simple_table_no_serde/models/todos/generated.rs index 41fe734a..666cdb42 100644 --- a/test/simple_table_no_serde/models/todos/generated.rs +++ b/test/simple_table_no_serde/models/todos/generated.rs @@ -63,12 +63,14 @@ pub struct PaginationResult { } impl Todos { + /// Insert a new row into `todos` with a given [`CreateTodos`] pub fn create(db: &mut ConnectionType, item: &CreateTodos) -> QueryResult { use crate::schema::todos::dsl::*; insert_into(todos).values(item).get_result::(db) } + /// Get a row from `todos`, identified by the primary key pub fn read(db: &mut ConnectionType, param_id: i32) -> QueryResult { use crate::schema::todos::dsl::*; @@ -93,12 +95,14 @@ impl Todos { }) } + /// Update a row in `todos`, identified by the primary key with [`UpdateTodos`] pub fn update(db: &mut ConnectionType, param_id: i32, item: &UpdateTodos) -> QueryResult { use crate::schema::todos::dsl::*; diesel::update(todos.filter(id.eq(param_id))).set(item).get_result(db) } + /// Delete a row in `todos`, identified by the primary key pub fn delete(db: &mut ConnectionType, param_id: i32) -> QueryResult { use crate::schema::todos::dsl::*; diff --git a/test/single_model_file/models/table1.rs b/test/single_model_file/models/table1.rs index 3d3a9ccb..4de3e8bb 100644 --- a/test/single_model_file/models/table1.rs +++ b/test/single_model_file/models/table1.rs @@ -26,12 +26,14 @@ pub struct PaginationResult { } impl Table1 { + /// Insert a new row into `table1` with all default values pub fn create(db: &mut ConnectionType) -> QueryResult { use crate::schema::table1::dsl::*; insert_into(table1).default_values().get_result::(db) } + /// Get a row from `table1`, identified by the primary key pub fn read(db: &mut ConnectionType, param_id: i32) -> QueryResult { use crate::schema::table1::dsl::*; @@ -56,6 +58,7 @@ impl Table1 { }) } + /// Delete a row in `table1`, identified by the primary key pub fn delete(db: &mut ConnectionType, param_id: i32) -> QueryResult { use crate::schema::table1::dsl::*; diff --git a/test/single_model_file/models/table2.rs b/test/single_model_file/models/table2.rs index 706bf280..973dc05a 100644 --- a/test/single_model_file/models/table2.rs +++ b/test/single_model_file/models/table2.rs @@ -26,12 +26,14 @@ pub struct PaginationResult { } impl Table2 { + /// Insert a new row into `table2` with all default values pub fn create(db: &mut ConnectionType) -> QueryResult { use crate::schema::table2::dsl::*; insert_into(table2).default_values().get_result::(db) } + /// Get a row from `table2`, identified by the primary key pub fn read(db: &mut ConnectionType, param_id: i32) -> QueryResult { use crate::schema::table2::dsl::*; @@ -56,6 +58,7 @@ impl Table2 { }) } + /// Delete a row in `table2`, identified by the primary key pub fn delete(db: &mut ConnectionType, param_id: i32) -> QueryResult { use crate::schema::table2::dsl::*; diff --git a/test/use_statements/models/fang_tasks/generated.rs b/test/use_statements/models/fang_tasks/generated.rs index fce6e9a9..64b3a8a7 100644 --- a/test/use_statements/models/fang_tasks/generated.rs +++ b/test/use_statements/models/fang_tasks/generated.rs @@ -94,12 +94,14 @@ pub struct PaginationResult { } impl FangTasks { + /// Insert a new row into `fang_tasks` with a given [`CreateFangTasks`] pub fn create(db: &mut ConnectionType, item: &CreateFangTasks) -> QueryResult { use crate::schema::fang_tasks::dsl::*; insert_into(fang_tasks).values(item).get_result::(db) } + /// Get a row from `fang_tasks`, identified by the primary key pub fn read(db: &mut ConnectionType, param_id: uuid::Uuid) -> QueryResult { use crate::schema::fang_tasks::dsl::*; @@ -124,12 +126,14 @@ impl FangTasks { }) } + /// Update a row in `fang_tasks`, identified by the primary key with [`UpdateFangTasks`] pub fn update(db: &mut ConnectionType, param_id: uuid::Uuid, item: &UpdateFangTasks) -> QueryResult { use crate::schema::fang_tasks::dsl::*; diesel::update(fang_tasks.filter(id.eq(param_id))).set(item).get_result(db) } + /// Delete a row in `fang_tasks`, identified by the primary key pub fn delete(db: &mut ConnectionType, param_id: uuid::Uuid) -> QueryResult { use crate::schema::fang_tasks::dsl::*; From d6a764e114ec0d33de344bfc45f319511896a309 Mon Sep 17 00:00:00 2001 From: hasezoey Date: Tue, 31 Oct 2023 14:51:53 +0100 Subject: [PATCH 5/6] feat(code): add doccomments to "PaginationResult" structs --- src/code.rs | 7 ++++++- test/autogenerated_all/models/todos/generated.rs | 7 ++++++- test/autogenerated_attributes/models/todos/generated.rs | 7 ++++++- test/autogenerated_primary_keys/models/todos/generated.rs | 7 ++++++- test/cleanup_generated_content/models/todos/generated.rs | 7 ++++++- test/create_update_str_cow/models/todos/generated.rs | 7 ++++++- test/create_update_str_str/models/todos/generated.rs | 7 ++++++- .../models/tableA/generated.rs | 7 ++++++- .../models/tableB/generated.rs | 7 ++++++- test/custom_model_path/models/tableA/generated.rs | 7 ++++++- test/custom_model_path/models/tableB/generated.rs | 7 ++++++- test/manual_primary_keys/models/todos/generated.rs | 7 ++++++- test/multiple_primary_keys/models/users/generated.rs | 7 ++++++- test/once_common_structs/models/common.rs | 7 ++++++- .../models/common.rs | 7 ++++++- .../models/common.rs | 7 ++++++- test/once_connection_type/models/table1/generated.rs | 7 ++++++- test/once_connection_type/models/table2/generated.rs | 7 ++++++- test/readonly/models/normal/generated.rs | 7 ++++++- test/readonly/models/prefixTable/generated.rs | 7 ++++++- test/readonly/models/prefixTableSuffix/generated.rs | 7 ++++++- test/readonly/models/tableSuffix/generated.rs | 7 ++++++- test/simple_table/models/todos/generated.rs | 7 ++++++- test/simple_table_async/models/todos/generated.rs | 7 ++++++- .../models/todos/generated.rs | 7 ++++++- test/simple_table_no_serde/models/todos/generated.rs | 7 ++++++- test/single_model_file/models/table1.rs | 7 ++++++- test/single_model_file/models/table2.rs | 7 ++++++- test/use_statements/models/fang_tasks/generated.rs | 7 ++++++- 29 files changed, 174 insertions(+), 29 deletions(-) diff --git a/src/code.rs b/src/code.rs index aeb961ee..8debfdd2 100644 --- a/src/code.rs +++ b/src/code.rs @@ -563,13 +563,18 @@ pub fn generate_common_structs(table_options: &TableOptions<'_>) -> String { formatdoc!( r##" + /// Result of a `.paginate` function {tsync}#[derive({debug_derive}, {serde_derive})] pub struct PaginationResult {{ + /// Resulting items that are from the current page pub items: Vec, + /// The count of total items there are pub total_items: i64, - /// 0-based index + /// Current page, 0-based index pub page: i64, + /// Size of a page pub page_size: i64, + /// Number of total possible pages, given the `page_size` and `total_items` pub num_pages: i64, }} "##, diff --git a/test/autogenerated_all/models/todos/generated.rs b/test/autogenerated_all/models/todos/generated.rs index bde26321..adbccd9b 100644 --- a/test/autogenerated_all/models/todos/generated.rs +++ b/test/autogenerated_all/models/todos/generated.rs @@ -25,13 +25,18 @@ pub struct UpdateTodos { pub created_at: Option, } +/// Result of a `.paginate` function #[derive(Debug, Serialize)] pub struct PaginationResult { + /// Resulting items that are from the current page pub items: Vec, + /// The count of total items there are pub total_items: i64, - /// 0-based index + /// Current page, 0-based index pub page: i64, + /// Size of a page pub page_size: i64, + /// Number of total possible pages, given the `page_size` and `total_items` pub num_pages: i64, } diff --git a/test/autogenerated_attributes/models/todos/generated.rs b/test/autogenerated_attributes/models/todos/generated.rs index cd36e192..0e2e164d 100644 --- a/test/autogenerated_attributes/models/todos/generated.rs +++ b/test/autogenerated_attributes/models/todos/generated.rs @@ -33,13 +33,18 @@ pub struct UpdateTodos { pub created_at: Option, } +/// Result of a `.paginate` function #[derive(Debug, Serialize)] pub struct PaginationResult { + /// Resulting items that are from the current page pub items: Vec, + /// The count of total items there are pub total_items: i64, - /// 0-based index + /// Current page, 0-based index pub page: i64, + /// Size of a page pub page_size: i64, + /// Number of total possible pages, given the `page_size` and `total_items` pub num_pages: i64, } diff --git a/test/autogenerated_primary_keys/models/todos/generated.rs b/test/autogenerated_primary_keys/models/todos/generated.rs index e14bb1c2..ae3eb3ae 100644 --- a/test/autogenerated_primary_keys/models/todos/generated.rs +++ b/test/autogenerated_primary_keys/models/todos/generated.rs @@ -33,13 +33,18 @@ pub struct UpdateTodos { pub text: Option, } +/// Result of a `.paginate` function #[derive(Debug, Serialize)] pub struct PaginationResult { + /// Resulting items that are from the current page pub items: Vec, + /// The count of total items there are pub total_items: i64, - /// 0-based index + /// Current page, 0-based index pub page: i64, + /// Size of a page pub page_size: i64, + /// Number of total possible pages, given the `page_size` and `total_items` pub num_pages: i64, } diff --git a/test/cleanup_generated_content/models/todos/generated.rs b/test/cleanup_generated_content/models/todos/generated.rs index 3d657ae1..11a804a4 100644 --- a/test/cleanup_generated_content/models/todos/generated.rs +++ b/test/cleanup_generated_content/models/todos/generated.rs @@ -49,13 +49,18 @@ pub struct UpdateTodos { pub updated_at: Option>, } +/// Result of a `.paginate` function #[derive(Debug, Serialize)] pub struct PaginationResult { + /// Resulting items that are from the current page pub items: Vec, + /// The count of total items there are pub total_items: i64, - /// 0-based index + /// Current page, 0-based index pub page: i64, + /// Size of a page pub page_size: i64, + /// Number of total possible pages, given the `page_size` and `total_items` pub num_pages: i64, } diff --git a/test/create_update_str_cow/models/todos/generated.rs b/test/create_update_str_cow/models/todos/generated.rs index 5b733699..289a359f 100644 --- a/test/create_update_str_cow/models/todos/generated.rs +++ b/test/create_update_str_cow/models/todos/generated.rs @@ -47,13 +47,18 @@ pub struct UpdateTodos<'a> { pub varchar_nullable: Option>>, } +/// Result of a `.paginate` function #[derive(Debug, Serialize)] pub struct PaginationResult { + /// Resulting items that are from the current page pub items: Vec, + /// The count of total items there are pub total_items: i64, - /// 0-based index + /// Current page, 0-based index pub page: i64, + /// Size of a page pub page_size: i64, + /// Number of total possible pages, given the `page_size` and `total_items` pub num_pages: i64, } diff --git a/test/create_update_str_str/models/todos/generated.rs b/test/create_update_str_str/models/todos/generated.rs index 944be935..c8e95974 100644 --- a/test/create_update_str_str/models/todos/generated.rs +++ b/test/create_update_str_str/models/todos/generated.rs @@ -47,13 +47,18 @@ pub struct UpdateTodos<'a> { pub varchar_nullable: Option>, } +/// Result of a `.paginate` function #[derive(Debug, Serialize)] pub struct PaginationResult { + /// Resulting items that are from the current page pub items: Vec, + /// The count of total items there are pub total_items: i64, - /// 0-based index + /// Current page, 0-based index pub page: i64, + /// Size of a page pub page_size: i64, + /// Number of total possible pages, given the `page_size` and `total_items` pub num_pages: i64, } diff --git a/test/custom_model_and_schema_path/models/tableA/generated.rs b/test/custom_model_and_schema_path/models/tableA/generated.rs index ea87f5fd..e2d95938 100644 --- a/test/custom_model_and_schema_path/models/tableA/generated.rs +++ b/test/custom_model_and_schema_path/models/tableA/generated.rs @@ -23,13 +23,18 @@ pub struct CreateTableA { pub _id: i32, } +/// Result of a `.paginate` function #[derive(Debug, Serialize)] pub struct PaginationResult { + /// Resulting items that are from the current page pub items: Vec, + /// The count of total items there are pub total_items: i64, - /// 0-based index + /// Current page, 0-based index pub page: i64, + /// Size of a page pub page_size: i64, + /// Number of total possible pages, given the `page_size` and `total_items` pub num_pages: i64, } diff --git a/test/custom_model_and_schema_path/models/tableB/generated.rs b/test/custom_model_and_schema_path/models/tableB/generated.rs index d653d45d..010cb357 100644 --- a/test/custom_model_and_schema_path/models/tableB/generated.rs +++ b/test/custom_model_and_schema_path/models/tableB/generated.rs @@ -36,13 +36,18 @@ pub struct UpdateTableB { pub link: Option, } +/// Result of a `.paginate` function #[derive(Debug, Serialize)] pub struct PaginationResult { + /// Resulting items that are from the current page pub items: Vec, + /// The count of total items there are pub total_items: i64, - /// 0-based index + /// Current page, 0-based index pub page: i64, + /// Size of a page pub page_size: i64, + /// Number of total possible pages, given the `page_size` and `total_items` pub num_pages: i64, } diff --git a/test/custom_model_path/models/tableA/generated.rs b/test/custom_model_path/models/tableA/generated.rs index 806a7178..0669502a 100644 --- a/test/custom_model_path/models/tableA/generated.rs +++ b/test/custom_model_path/models/tableA/generated.rs @@ -23,13 +23,18 @@ pub struct CreateTableA { pub _id: i32, } +/// Result of a `.paginate` function #[derive(Debug, Serialize)] pub struct PaginationResult { + /// Resulting items that are from the current page pub items: Vec, + /// The count of total items there are pub total_items: i64, - /// 0-based index + /// Current page, 0-based index pub page: i64, + /// Size of a page pub page_size: i64, + /// Number of total possible pages, given the `page_size` and `total_items` pub num_pages: i64, } diff --git a/test/custom_model_path/models/tableB/generated.rs b/test/custom_model_path/models/tableB/generated.rs index 991abc14..f18ae275 100644 --- a/test/custom_model_path/models/tableB/generated.rs +++ b/test/custom_model_path/models/tableB/generated.rs @@ -36,13 +36,18 @@ pub struct UpdateTableB { pub link: Option, } +/// Result of a `.paginate` function #[derive(Debug, Serialize)] pub struct PaginationResult { + /// Resulting items that are from the current page pub items: Vec, + /// The count of total items there are pub total_items: i64, - /// 0-based index + /// Current page, 0-based index pub page: i64, + /// Size of a page pub page_size: i64, + /// Number of total possible pages, given the `page_size` and `total_items` pub num_pages: i64, } diff --git a/test/manual_primary_keys/models/todos/generated.rs b/test/manual_primary_keys/models/todos/generated.rs index ac003634..42ca0fa3 100644 --- a/test/manual_primary_keys/models/todos/generated.rs +++ b/test/manual_primary_keys/models/todos/generated.rs @@ -23,13 +23,18 @@ pub struct CreateTodos { pub id: i32, } +/// Result of a `.paginate` function #[derive(Debug, Serialize)] pub struct PaginationResult { + /// Resulting items that are from the current page pub items: Vec, + /// The count of total items there are pub total_items: i64, - /// 0-based index + /// Current page, 0-based index pub page: i64, + /// Size of a page pub page_size: i64, + /// Number of total possible pages, given the `page_size` and `total_items` pub num_pages: i64, } diff --git a/test/multiple_primary_keys/models/users/generated.rs b/test/multiple_primary_keys/models/users/generated.rs index 1ffa1f2a..d7c5a8a5 100644 --- a/test/multiple_primary_keys/models/users/generated.rs +++ b/test/multiple_primary_keys/models/users/generated.rs @@ -39,13 +39,18 @@ pub struct UpdateUsers { pub secret: Option, } +/// Result of a `.paginate` function #[derive(Debug, Serialize)] pub struct PaginationResult { + /// Resulting items that are from the current page pub items: Vec, + /// The count of total items there are pub total_items: i64, - /// 0-based index + /// Current page, 0-based index pub page: i64, + /// Size of a page pub page_size: i64, + /// Number of total possible pages, given the `page_size` and `total_items` pub num_pages: i64, } diff --git a/test/once_common_structs/models/common.rs b/test/once_common_structs/models/common.rs index f47c7b10..a892e81e 100644 --- a/test/once_common_structs/models/common.rs +++ b/test/once_common_structs/models/common.rs @@ -1,10 +1,15 @@ /* @generated and managed by dsync */ +/// Result of a `.paginate` function #[derive(Debug, Serialize)] pub struct PaginationResult { + /// Resulting items that are from the current page pub items: Vec, + /// The count of total items there are pub total_items: i64, - /// 0-based index + /// Current page, 0-based index pub page: i64, + /// Size of a page pub page_size: i64, + /// Number of total possible pages, given the `page_size` and `total_items` pub num_pages: i64, } diff --git a/test/once_common_structs_once_connection_type/models/common.rs b/test/once_common_structs_once_connection_type/models/common.rs index 443b4c03..dcec353a 100644 --- a/test/once_common_structs_once_connection_type/models/common.rs +++ b/test/once_common_structs_once_connection_type/models/common.rs @@ -1,11 +1,16 @@ /* @generated and managed by dsync */ +/// Result of a `.paginate` function #[derive(Debug, Serialize)] pub struct PaginationResult { + /// Resulting items that are from the current page pub items: Vec, + /// The count of total items there are pub total_items: i64, - /// 0-based index + /// Current page, 0-based index pub page: i64, + /// Size of a page pub page_size: i64, + /// Number of total possible pages, given the `page_size` and `total_items` pub num_pages: i64, } diff --git a/test/once_common_structs_once_connection_type_single_file/models/common.rs b/test/once_common_structs_once_connection_type_single_file/models/common.rs index 443b4c03..dcec353a 100644 --- a/test/once_common_structs_once_connection_type_single_file/models/common.rs +++ b/test/once_common_structs_once_connection_type_single_file/models/common.rs @@ -1,11 +1,16 @@ /* @generated and managed by dsync */ +/// Result of a `.paginate` function #[derive(Debug, Serialize)] pub struct PaginationResult { + /// Resulting items that are from the current page pub items: Vec, + /// The count of total items there are pub total_items: i64, - /// 0-based index + /// Current page, 0-based index pub page: i64, + /// Size of a page pub page_size: i64, + /// Number of total possible pages, given the `page_size` and `total_items` pub num_pages: i64, } diff --git a/test/once_connection_type/models/table1/generated.rs b/test/once_connection_type/models/table1/generated.rs index e34c4efa..6d2f5af9 100644 --- a/test/once_connection_type/models/table1/generated.rs +++ b/test/once_connection_type/models/table1/generated.rs @@ -14,13 +14,18 @@ pub struct Table1 { pub id: i32, } +/// Result of a `.paginate` function #[derive(Debug, Serialize)] pub struct PaginationResult { + /// Resulting items that are from the current page pub items: Vec, + /// The count of total items there are pub total_items: i64, - /// 0-based index + /// Current page, 0-based index pub page: i64, + /// Size of a page pub page_size: i64, + /// Number of total possible pages, given the `page_size` and `total_items` pub num_pages: i64, } diff --git a/test/once_connection_type/models/table2/generated.rs b/test/once_connection_type/models/table2/generated.rs index c919d56a..3181676e 100644 --- a/test/once_connection_type/models/table2/generated.rs +++ b/test/once_connection_type/models/table2/generated.rs @@ -14,13 +14,18 @@ pub struct Table2 { pub id: i32, } +/// Result of a `.paginate` function #[derive(Debug, Serialize)] pub struct PaginationResult { + /// Resulting items that are from the current page pub items: Vec, + /// The count of total items there are pub total_items: i64, - /// 0-based index + /// Current page, 0-based index pub page: i64, + /// Size of a page pub page_size: i64, + /// Number of total possible pages, given the `page_size` and `total_items` pub num_pages: i64, } diff --git a/test/readonly/models/normal/generated.rs b/test/readonly/models/normal/generated.rs index 12e73d3a..44a2bae6 100644 --- a/test/readonly/models/normal/generated.rs +++ b/test/readonly/models/normal/generated.rs @@ -33,13 +33,18 @@ pub struct UpdateNormal { pub testprop: Option, } +/// Result of a `.paginate` function #[derive(Debug, Serialize)] pub struct PaginationResult { + /// Resulting items that are from the current page pub items: Vec, + /// The count of total items there are pub total_items: i64, - /// 0-based index + /// Current page, 0-based index pub page: i64, + /// Size of a page pub page_size: i64, + /// Number of total possible pages, given the `page_size` and `total_items` pub num_pages: i64, } diff --git a/test/readonly/models/prefixTable/generated.rs b/test/readonly/models/prefixTable/generated.rs index 51dae75c..56b87e86 100644 --- a/test/readonly/models/prefixTable/generated.rs +++ b/test/readonly/models/prefixTable/generated.rs @@ -17,13 +17,18 @@ pub struct PrefixTable { pub testprop: i32, } +/// Result of a `.paginate` function #[derive(Debug, Serialize)] pub struct PaginationResult { + /// Resulting items that are from the current page pub items: Vec, + /// The count of total items there are pub total_items: i64, - /// 0-based index + /// Current page, 0-based index pub page: i64, + /// Size of a page pub page_size: i64, + /// Number of total possible pages, given the `page_size` and `total_items` pub num_pages: i64, } diff --git a/test/readonly/models/prefixTableSuffix/generated.rs b/test/readonly/models/prefixTableSuffix/generated.rs index 6ee56337..4afe4571 100644 --- a/test/readonly/models/prefixTableSuffix/generated.rs +++ b/test/readonly/models/prefixTableSuffix/generated.rs @@ -17,13 +17,18 @@ pub struct PrefixTableSuffix { pub testprop: i32, } +/// Result of a `.paginate` function #[derive(Debug, Serialize)] pub struct PaginationResult { + /// Resulting items that are from the current page pub items: Vec, + /// The count of total items there are pub total_items: i64, - /// 0-based index + /// Current page, 0-based index pub page: i64, + /// Size of a page pub page_size: i64, + /// Number of total possible pages, given the `page_size` and `total_items` pub num_pages: i64, } diff --git a/test/readonly/models/tableSuffix/generated.rs b/test/readonly/models/tableSuffix/generated.rs index 5846d1e2..f6a378e7 100644 --- a/test/readonly/models/tableSuffix/generated.rs +++ b/test/readonly/models/tableSuffix/generated.rs @@ -17,13 +17,18 @@ pub struct TableSuffix { pub testprop: i32, } +/// Result of a `.paginate` function #[derive(Debug, Serialize)] pub struct PaginationResult { + /// Resulting items that are from the current page pub items: Vec, + /// The count of total items there are pub total_items: i64, - /// 0-based index + /// Current page, 0-based index pub page: i64, + /// Size of a page pub page_size: i64, + /// Number of total possible pages, given the `page_size` and `total_items` pub num_pages: i64, } diff --git a/test/simple_table/models/todos/generated.rs b/test/simple_table/models/todos/generated.rs index d6ee2166..43b0369d 100644 --- a/test/simple_table/models/todos/generated.rs +++ b/test/simple_table/models/todos/generated.rs @@ -65,13 +65,18 @@ pub struct UpdateTodos { pub updated_at: Option>, } +/// Result of a `.paginate` function #[derive(Debug, Serialize)] pub struct PaginationResult { + /// Resulting items that are from the current page pub items: Vec, + /// The count of total items there are pub total_items: i64, - /// 0-based index + /// Current page, 0-based index pub page: i64, + /// Size of a page pub page_size: i64, + /// Number of total possible pages, given the `page_size` and `total_items` pub num_pages: i64, } diff --git a/test/simple_table_async/models/todos/generated.rs b/test/simple_table_async/models/todos/generated.rs index 305e5818..27258c3b 100644 --- a/test/simple_table_async/models/todos/generated.rs +++ b/test/simple_table_async/models/todos/generated.rs @@ -54,13 +54,18 @@ pub struct UpdateTodos { pub updated_at: Option>, } +/// Result of a `.paginate` function #[derive(Debug, Serialize)] pub struct PaginationResult { + /// Resulting items that are from the current page pub items: Vec, + /// The count of total items there are pub total_items: i64, - /// 0-based index + /// Current page, 0-based index pub page: i64, + /// Size of a page pub page_size: i64, + /// Number of total possible pages, given the `page_size` and `total_items` pub num_pages: i64, } diff --git a/test/simple_table_custom_schema_path/models/todos/generated.rs b/test/simple_table_custom_schema_path/models/todos/generated.rs index 44775506..1be97c0d 100644 --- a/test/simple_table_custom_schema_path/models/todos/generated.rs +++ b/test/simple_table_custom_schema_path/models/todos/generated.rs @@ -53,13 +53,18 @@ pub struct UpdateTodos { pub updated_at: Option>, } +/// Result of a `.paginate` function #[derive(Debug, Serialize)] pub struct PaginationResult { + /// Resulting items that are from the current page pub items: Vec, + /// The count of total items there are pub total_items: i64, - /// 0-based index + /// Current page, 0-based index pub page: i64, + /// Size of a page pub page_size: i64, + /// Number of total possible pages, given the `page_size` and `total_items` pub num_pages: i64, } diff --git a/test/simple_table_no_serde/models/todos/generated.rs b/test/simple_table_no_serde/models/todos/generated.rs index 666cdb42..00e3851c 100644 --- a/test/simple_table_no_serde/models/todos/generated.rs +++ b/test/simple_table_no_serde/models/todos/generated.rs @@ -52,13 +52,18 @@ pub struct UpdateTodos { pub updated_at: Option>, } +/// Result of a `.paginate` function #[derive(Debug, )] pub struct PaginationResult { + /// Resulting items that are from the current page pub items: Vec, + /// The count of total items there are pub total_items: i64, - /// 0-based index + /// Current page, 0-based index pub page: i64, + /// Size of a page pub page_size: i64, + /// Number of total possible pages, given the `page_size` and `total_items` pub num_pages: i64, } diff --git a/test/single_model_file/models/table1.rs b/test/single_model_file/models/table1.rs index 4de3e8bb..f50f1aff 100644 --- a/test/single_model_file/models/table1.rs +++ b/test/single_model_file/models/table1.rs @@ -15,13 +15,18 @@ pub struct Table1 { pub id: i32, } +/// Result of a `.paginate` function #[derive(Debug, Serialize)] pub struct PaginationResult { + /// Resulting items that are from the current page pub items: Vec, + /// The count of total items there are pub total_items: i64, - /// 0-based index + /// Current page, 0-based index pub page: i64, + /// Size of a page pub page_size: i64, + /// Number of total possible pages, given the `page_size` and `total_items` pub num_pages: i64, } diff --git a/test/single_model_file/models/table2.rs b/test/single_model_file/models/table2.rs index 973dc05a..7d2a1b82 100644 --- a/test/single_model_file/models/table2.rs +++ b/test/single_model_file/models/table2.rs @@ -15,13 +15,18 @@ pub struct Table2 { pub id: i32, } +/// Result of a `.paginate` function #[derive(Debug, Serialize)] pub struct PaginationResult { + /// Resulting items that are from the current page pub items: Vec, + /// The count of total items there are pub total_items: i64, - /// 0-based index + /// Current page, 0-based index pub page: i64, + /// Size of a page pub page_size: i64, + /// Number of total possible pages, given the `page_size` and `total_items` pub num_pages: i64, } diff --git a/test/use_statements/models/fang_tasks/generated.rs b/test/use_statements/models/fang_tasks/generated.rs index 64b3a8a7..f5db8ed5 100644 --- a/test/use_statements/models/fang_tasks/generated.rs +++ b/test/use_statements/models/fang_tasks/generated.rs @@ -83,13 +83,18 @@ pub struct UpdateFangTasks { pub updated_at: Option>, } +/// Result of a `.paginate` function #[derive(Debug, Serialize)] pub struct PaginationResult { + /// Resulting items that are from the current page pub items: Vec, + /// The count of total items there are pub total_items: i64, - /// 0-based index + /// Current page, 0-based index pub page: i64, + /// Size of a page pub page_size: i64, + /// Number of total possible pages, given the `page_size` and `total_items` pub num_pages: i64, } From 6d6a4e2134965618755354cc677b8abecd576cdc Mon Sep 17 00:00:00 2001 From: hasezoey Date: Tue, 31 Oct 2023 14:53:07 +0100 Subject: [PATCH 6/6] docs(CHANGELOG): add entry for generated doc-comments --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 46a8e489..44362cdf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,7 @@ - rename `type Connection =` to `type ConnectionType =` to lessen naming conflicts - add many doc-comments to fields and functions - list changes to files (unchanged, modified, deleted) +- generate doc-comments for generated structs, fields and functions ## 0.0.17 (yanked)