Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DateTime Example Available #362

Open
writeDavid opened this issue Oct 21, 2024 · 0 comments
Open

DateTime Example Available #362

writeDavid opened this issue Oct 21, 2024 · 0 comments

Comments

@writeDavid
Copy link

Is there another example available that goes over pulling a MSSQL DateTime type from the DB, and serializing it? Here is the structure I am using atm:

`

#[derive(Serialize)]
pub struct Device {
    device_id: String,
    device_device_id: String,
    device_display_name: String,
    device_enrollment_profile: String,
    device_operating_system: String,
    device_operating_system_version: String,
    device_last_signin_date: String,
    device_owner_user_id: String,
}

let mut devices: Vec<Device> = Vec::new();

while let Some(item) = stream.try_next().await? {
    match item {
        QueryItem::Metadata(_meta) => {
            // do nothing
        }
        QueryItem::Row(row) => {
            let mut device: Device = Device {
                device_id: String::new(),
                device_device_id: String::new(),
                device_display_name: String::new(),
                device_enrollment_profile: String::new(),
                device_operating_system: String::new(),
                device_operating_system_version: String::new(),
                device_last_signin_date: String::new(),
                device_owner_user_id: String::new(),
            };

            let device_id: Option<&str> = row.get(0);
            let device_device_id: Option<&str> = row.get(1);
            let device_display_name: Option<&str> = row.get(2);
            let device_enrollment_profile: Option<&str> = row.get(3);
            let device_operating_system: Option<&str> = row.get(4);
            let device_operating_system_version: Option<&str> = row.get(5);
            let device_last_signin_date: Option<&str> = row.get(6);
            let device_owner_user_id: Option<&str> = row.get(7);

            if let Some(value) = device_id {
                device.device_id = value.to_string();
            } else {
                println!("device id is missing");
            }

            if let Some(value) = device_device_id {
                device.device_device_id = value.to_string();
            } else {
                println!("device deviceId is missing");
            }

            if let Some(value) = device_display_name {
                device.device_display_name = value.to_string();
            } else {
                println!("device display name is missing");
            }

            if let Some(value) = device_enrollment_profile {
                device.device_enrollment_profile = value.to_string();
            } else {
                println!("device enrollment profile is missing");
            }

            if let Some(value) = device_operating_system {
                device.device_operating_system = value.to_string();
            } else {
                println!("device operating system is missing");
            }

            if let Some(value) = device_operating_system_version {
                device.device_operating_system_version = value.to_string();
            } else {
                println!("device operating system version is missing");
            }

            if let Some(value) = device_last_signin_date {
                device.device_last_signin_date = value.to_string();
            } else {
                println!("device last signin date is missing");
            }

            if let Some(value) = device_owner_user_id {
                device.device_owner_user_id = value.to_string();
            } else {
                println!("device owner user id is missing");
            }

            devices.push(device);
        }
    }
}

let json: String = serde_json::to_string(&devices)?;

`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant