Skip to content
This repository was archived by the owner on Jul 12, 2024. It is now read-only.
This repository was archived by the owner on Jul 12, 2024. It is now read-only.

dynamic Row #12

@soerenmeier

Description

@soerenmeier

This is ugly

let mut fields =
	String::from(r#""firstname" = $1, "lastname" = $2, "email" = $3"#);

let mut params: Vec<&(dyn ToSql + Sync)> =
	vec![firstname, lastname, &email];

let hashed_password;
if let Some(password) = password {
	hashed_password = hash(password, 12)?;
	fields.push_str(r#", "password" = $4"#);
	params.push(&hashed_password);
}

let raw_rights;
if let Some(rights) = rights {
	raw_rights = RawRights(rights.clone());
	fields.push_str(format!(r#", "rights" = {}"#, params.len() + 1));
	params.push(&raw_rights);
}

let sql = format!(
	"UPDATE \"{}\" SET {} WHERE \"id\" = ${}",
	self.table.name(),
	fields,
	params.len() + 1
);
params.push(id);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions