Trait SQLInsert

Source
pub trait SQLInsert<DB: Database> {
    // Required method
    fn sql_insert<'e, 'c, 'life0, 'async_trait, E>(
        &'life0 self,
        connection: E,
    ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
       where E: 'async_trait + 'e + Executor<'c, Database = DB>,
             Self: 'async_trait,
             'e: 'async_trait,
             'c: 'async_trait,
             'life0: 'async_trait;
}
Expand description

Trait for inserting a struct into a SQL database.

Example:

use sqlx::Postgres;
use sqlx::Sqlite;
use sqlx::PgConnection;
use sqlx_insert::SQLInsert;

#[derive(SQLInsert, Clone, Debug, PartialEq)]
#[sqlx_insert(database(Postgres, Sqlite))]
struct MyStruct {
    id: i32,
    name: String,
}

async fn insert_my_struct(connection: &mut PgConnection) -> sqlx::Result<()> {
    let my_struct = MyStruct { id: 1, name: "test".to_string() };
    my_struct.sql_insert(connection).await
}

Required Methods§

Source

fn sql_insert<'e, 'c, 'life0, 'async_trait, E>( &'life0 self, connection: E, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where E: 'async_trait + 'e + Executor<'c, Database = DB>, Self: 'async_trait, 'e: 'async_trait, 'c: 'async_trait, 'life0: 'async_trait,

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§