launchbadge/sqlx

Extend derive(FromRow) with additional features/attributes

Open

#156 opened on Mar 26, 2020

View on GitHub
 (2 comments) (19 reactions) (0 assignees)Rust (13,916 stars) (1,307 forks)batch import
E-mediumenhancementgood first issuehelp wanted

Description

  • Handle #[sqlx(rename = "new_name")] on a struct field

  • Support the derive on a tuple struct and use by ordinal retrieval from the row

  • Handle #[sqlx(ordinal = 3)] to use ordinal retrieval from the row ( row.get(3) )

  • Handle a field that is impl FromRow. A parallel from serde_json would perhaps make this #[sqlx(flatten)].

    #[derive(sqlx::FromRow)]
    struct Bar {
        baz: i32  // row.get("baz")
     }
    
    #[derive(sqlx::FromRow)]
    struct Foo {
        foo: i32, // row.get("foo")
        #[sqlx(flatten)]
        bar: Bar
    }
    

Contributor guide