Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Update

The Update trait allows you to read entities from rows in your table. Here is an example of how to create a user, given that you have it annotated with table:

extern crate atmosphere;
extern crate sqlx;
extern crate tokio;
use atmosphere::prelude::*;
#[derive(Debug, PartialEq)]
#[table(schema = "public", name = "user")]
struct User {
    #[sql(pk)]
    id: i32,
    name: String,
    #[sql(unique)]
    email: String,
}

async fn test() -> std::result::Result<(), Box<dyn std::error::Error>> {
let database = std::env::var("DATABASE_URL").unwrap();
let pool = atmosphere::Pool::connect(&database).await?;

// find user by primary key
let mut user = User::find(&pool, &0).await?;

user.email = "joe@example.com".into();

// update user data
user.update(&pool).await?;
Ok(())
}
fn main() {}