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) diff --git a/src/code.rs b/src/code.rs index 99f6dd35..8debfdd2 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,11 +316,33 @@ 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},"#)); } + 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} {{ @@ -429,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::*; @@ -439,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::*; @@ -449,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::*; @@ -489,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::*; @@ -500,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::*; @@ -526,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/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 diff --git a/test/autogenerated_all/models/todos/generated.rs b/test/autogenerated_all/models/todos/generated.rs index 12e0530a..adbccd9b 100644 --- a/test/autogenerated_all/models/todos/generated.rs +++ b/test/autogenerated_all/models/todos/generated.rs @@ -7,36 +7,48 @@ 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 { + /// Field representing column `id` pub id: i32, + /// Field representing column `created_at` 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 { + /// Field representing column `created_at` 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, } 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::*; @@ -61,12 +73,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 7af9c77e..0e2e164d 100644 --- a/test/autogenerated_attributes/models/todos/generated.rs +++ b/test/autogenerated_attributes/models/todos/generated.rs @@ -7,42 +7,56 @@ 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 { + /// Field representing column `id` pub id: i32, + /// Field representing column `created_at` 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 { + /// Field representing column `id` 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 { + /// Field representing column `created_at` 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, } 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::*; @@ -67,12 +81,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 82d2f095..ae3eb3ae 100644 --- a/test/autogenerated_primary_keys/models/todos/generated.rs +++ b/test/autogenerated_primary_keys/models/todos/generated.rs @@ -7,42 +7,56 @@ 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 { + /// Field representing column `id` pub id: i32, + /// Field representing column `text` 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 { + /// Field representing column `text` 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 { + /// Field representing column `text` 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, } 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::*; @@ -67,12 +81,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 e274198b..11a804a4 100644 --- a/test/cleanup_generated_content/models/todos/generated.rs +++ b/test/cleanup_generated_content/models/todos/generated.rs @@ -7,50 +7,72 @@ 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 { + /// Field representing column `id` pub id: i32, + /// 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, } +/// Create Struct for a row in table `todos` for [`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, } +/// Update Struct for a row in table `todos` for [`Todos`] #[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>, } +/// 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, } 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::*; @@ -75,12 +97,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 0e6fd50c..289a359f 100644 --- a/test/create_update_str_cow/models/todos/generated.rs +++ b/test/create_update_str_cow/models/todos/generated.rs @@ -7,49 +7,70 @@ 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 { + /// Field representing column `text` pub text: String, + /// Field representing column `text_nullable` pub text_nullable: Option, + /// Field representing column `varchar` pub varchar: String, + /// Field representing column `varchar_nullable` 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> { + /// 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>, } +/// 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> { + /// 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>>, } +/// 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, } 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::*; @@ -74,12 +95,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 ddf9a95b..c8e95974 100644 --- a/test/create_update_str_str/models/todos/generated.rs +++ b/test/create_update_str_str/models/todos/generated.rs @@ -7,49 +7,70 @@ 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 { + /// Field representing column `text` pub text: String, + /// Field representing column `text_nullable` pub text_nullable: Option, + /// Field representing column `varchar` pub varchar: String, + /// Field representing column `varchar_nullable` 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> { + /// 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>, } +/// 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> { + /// 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>, } +/// 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, } 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::*; @@ -74,12 +95,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 d45f94cd..e2d95938 100644 --- a/test/custom_model_and_schema_path/models/tableA/generated.rs +++ b/test/custom_model_and_schema_path/models/tableA/generated.rs @@ -7,35 +7,46 @@ 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 { + /// Field representing column `_id` 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 { + /// Field representing column `_id` 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, } 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::*; @@ -60,6 +71,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 f0e88858..010cb357 100644 --- a/test/custom_model_and_schema_path/models/tableB/generated.rs +++ b/test/custom_model_and_schema_path/models/tableB/generated.rs @@ -8,43 +8,58 @@ 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 { + /// Field representing column `_id` pub _id: i32, + /// Field representing column `link` 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 { + /// Field representing column `_id` pub _id: i32, + /// Field representing column `link` 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 { + /// Field representing column `link` 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, } 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::*; @@ -69,12 +84,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 6cbc2247..0669502a 100644 --- a/test/custom_model_path/models/tableA/generated.rs +++ b/test/custom_model_path/models/tableA/generated.rs @@ -7,35 +7,46 @@ 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 { + /// Field representing column `_id` 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 { + /// Field representing column `_id` 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, } 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::*; @@ -60,6 +71,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 8e177ff9..f18ae275 100644 --- a/test/custom_model_path/models/tableB/generated.rs +++ b/test/custom_model_path/models/tableB/generated.rs @@ -8,43 +8,58 @@ 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 { + /// Field representing column `_id` pub _id: i32, + /// Field representing column `link` 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 { + /// Field representing column `_id` pub _id: i32, + /// Field representing column `link` 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 { + /// Field representing column `link` 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, } 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::*; @@ -69,12 +84,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 e0bb1e1e..42ca0fa3 100644 --- a/test/manual_primary_keys/models/todos/generated.rs +++ b/test/manual_primary_keys/models/todos/generated.rs @@ -7,35 +7,46 @@ 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 { + /// Field representing column `id` 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 { + /// Field representing column `id` 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, } 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::*; @@ -60,6 +71,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 5379a456..d7c5a8a5 100644 --- a/test/multiple_primary_keys/models/users/generated.rs +++ b/test/multiple_primary_keys/models/users/generated.rs @@ -7,45 +7,62 @@ 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 { + /// Field representing column `name` pub name: String, + /// Field representing column `address` pub address: String, + /// Field representing column `secret` 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 { + /// Field representing column `name` pub name: String, + /// Field representing column `address` pub address: String, + /// Field representing column `secret` 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 { + /// Field representing column `secret` 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, } 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::*; @@ -70,12 +87,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/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/models/table1/generated.rs b/test/once_common_structs/models/table1/generated.rs index d69cd8f4..ccbaa099 100644 --- a/test/once_common_structs/models/table1/generated.rs +++ b/test/once_common_structs/models/table1/generated.rs @@ -8,19 +8,23 @@ 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 { + /// Field representing column `id` pub id: i32, } 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 +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 b41d3635..6a772fee 100644 --- a/test/once_common_structs/models/table2/generated.rs +++ b/test/once_common_structs/models/table2/generated.rs @@ -8,19 +8,23 @@ 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 { + /// Field representing column `id` pub id: i32, } 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 +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/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/models/table1/generated.rs b/test/once_common_structs_once_connection_type/models/table1/generated.rs index 5e46bc54..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 @@ -6,19 +6,23 @@ 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 { + /// Field representing column `id` pub id: i32, } 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::*; @@ -43,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 8cbee776..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 @@ -6,19 +6,23 @@ 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 { + /// Field representing column `id` pub id: i32, } 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::*; @@ -43,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/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_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..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 @@ -6,19 +6,23 @@ 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 { + /// Field representing column `id` pub id: i32, } 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::*; @@ -43,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 8cbee776..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 @@ -6,19 +6,23 @@ 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 { + /// Field representing column `id` pub id: i32, } 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::*; @@ -43,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 359be4f7..6d2f5af9 100644 --- a/test/once_connection_type/models/table1/generated.rs +++ b/test/once_connection_type/models/table1/generated.rs @@ -6,29 +6,38 @@ 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 { + /// Field representing column `id` 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, } 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::*; @@ -53,6 +62,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 4d8cfdf3..3181676e 100644 --- a/test/once_connection_type/models/table2/generated.rs +++ b/test/once_connection_type/models/table2/generated.rs @@ -6,29 +6,38 @@ 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 { + /// Field representing column `id` 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, } 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::*; @@ -53,6 +62,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 92fc6a53..44a2bae6 100644 --- a/test/readonly/models/normal/generated.rs +++ b/test/readonly/models/normal/generated.rs @@ -7,42 +7,56 @@ 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 { + /// Field representing column `id` pub id: i32, + /// Field representing column `testprop` 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 { + /// Field representing column `testprop` 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 { + /// Field representing column `testprop` 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, } 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::*; @@ -67,12 +81,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 74ea0f74..56b87e86 100644 --- a/test/readonly/models/prefixTable/generated.rs +++ b/test/readonly/models/prefixTable/generated.rs @@ -7,24 +7,33 @@ 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 { + /// Field representing column `id` pub id: i32, + /// Field representing column `testprop` 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, } 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 7bce0a4e..4afe4571 100644 --- a/test/readonly/models/prefixTableSuffix/generated.rs +++ b/test/readonly/models/prefixTableSuffix/generated.rs @@ -7,24 +7,33 @@ 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 { + /// Field representing column `id` pub id: i32, + /// Field representing column `testprop` 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, } 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 ee4ee0fd..f6a378e7 100644 --- a/test/readonly/models/tableSuffix/generated.rs +++ b/test/readonly/models/tableSuffix/generated.rs @@ -7,24 +7,33 @@ 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 { + /// Field representing column `id` pub id: i32, + /// Field representing column `testprop` 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, } 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 7ad5dd2e..43b0369d 100644 --- a/test/simple_table/models/todos/generated.rs +++ b/test/simple_table/models/todos/generated.rs @@ -7,58 +7,88 @@ 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 { + /// Field representing column `id` pub id: i32, + /// 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, + /// Field representing column `created_at` pub created_at: chrono::DateTime, + /// Field representing column `updated_at` 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 { + /// 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, } +/// Update Struct for a row in table `todos` for [`Todos`] #[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>, } +/// 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, } 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::*; @@ -83,12 +113,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 2a2eca2d..27258c3b 100644 --- a/test/simple_table_async/models/todos/generated.rs +++ b/test/simple_table_async/models/todos/generated.rs @@ -8,52 +8,76 @@ 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 { + /// 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, } +/// Create Struct for a row in table `todos` for [`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, } +/// Update Struct for a row in table `todos` for [`Todos`] #[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>, } +/// 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, } 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::*; @@ -78,12 +102,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 3899a332..1be97c0d 100644 --- a/test/simple_table_custom_schema_path/models/todos/generated.rs +++ b/test/simple_table_custom_schema_path/models/todos/generated.rs @@ -7,52 +7,76 @@ 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 { + /// 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, } +/// Create Struct for a row in table `todos` for [`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, } +/// Update Struct for a row in table `todos` for [`Todos`] #[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>, } +/// 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, } 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::*; @@ -77,12 +101,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_crud/models/todos/generated.rs b/test/simple_table_no_crud/models/todos/generated.rs index bf8379bb..feca272e 100644 --- a/test/simple_table_no_crud/models/todos/generated.rs +++ b/test/simple_table_no_crud/models/todos/generated.rs @@ -4,32 +4,49 @@ 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 { + /// 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, } +/// Create Struct for a row in table `todos` for [`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, } +/// Update Struct for a row in table `todos` for [`Todos`] #[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 82f61f3b..00e3851c 100644 --- a/test/simple_table_no_serde/models/todos/generated.rs +++ b/test/simple_table_no_serde/models/todos/generated.rs @@ -6,52 +6,76 @@ 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 { + /// 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, } +/// Create Struct for a row in table `todos` for [`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, } +/// Update Struct for a row in table `todos` for [`Todos`] #[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>, } +/// 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, } 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::*; @@ -76,12 +100,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 bd66bc49..f50f1aff 100644 --- a/test/single_model_file/models/table1.rs +++ b/test/single_model_file/models/table1.rs @@ -7,29 +7,38 @@ 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 { + /// Field representing column `id` 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, } 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::*; @@ -54,6 +63,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 e6d4ac1c..7d2a1b82 100644 --- a/test/single_model_file/models/table2.rs +++ b/test/single_model_file/models/table2.rs @@ -7,29 +7,38 @@ 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 { + /// Field representing column `id` 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, } 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::*; @@ -54,6 +63,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 3114cd22..f5db8ed5 100644 --- a/test/use_statements/models/fang_tasks/generated.rs +++ b/test/use_statements/models/fang_tasks/generated.rs @@ -7,67 +7,106 @@ 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 { + /// 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, } +/// 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 { + /// 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, } +/// 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 { + /// 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>, } +/// 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, } 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::*; @@ -92,12 +131,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::*;