pub trait Insertable<T> {
    type Values;

    fn values(self) -> Self::Values;

    fn insert_into(self, table: T) -> InsertStatement<T, Self::Values>
        T: Table,
        Self: Sized
, { ... } }
Expand description

Represents that a structure can be used to insert a new row into the database. This is automatically implemented for &[T] and &Vec<T> for inserting more than one record.

This trait can be derived

Required Associated Types

The VALUES clause to insert these records

The types used here are generally internal to Diesel. Implementations of this trait should use the Values type of other Insertable types. For example <diesel::dsl::Eq<column, &str> as Insertable<table>>::Values.

Required Methods

Construct Self::Values

Implementations of this trait typically call .values on other Insertable types.

Provided Methods

Insert self into a given table.

foo.insert_into(table) is identical to insert_into(table).values(foo). However, when inserting from a select statement, this form is generally preferred.

        users::name.concat("'s First Post"),
    .into_columns((posts::title, posts::user_id))

let inserted_posts = posts::table
let expected = vec!["Sean's First Post", "Tess's First Post"];
assert_eq!(expected, inserted_posts);

Implementations on Foreign Types