LoginSignup
0
0

[Diesel] schema.rs のカラムに対応するModelsのカラムの型

Last updated at Posted at 2024-01-11

Modelに何の型を設定すればいいのか悩んだため、探し方を備忘しておく

Module diesel::sql_typesstructs にある型のリンクを開いた先にある、The timestamp SQL type.の型を設定する

例:

diesel::table! {
    items (id) {
        id -> Text,
        title -> Text,
        created_at -> Timestamp,
        updated_at -> Timestamp,
    }
}

の場合、
feature = "chrono"を追加した上で、
diesel::sql_types::Timestampchrono::NaiveDateTimeを設定する

use chrono::NaiveDateTime;
use diesel::prelude::*;

#[derive(Queryable, Selectable)]
#[diesel(table_name = crate::schema::items)]
#[diesel(check_for_backend(diesel::sqlite::Sqlite))]
pub struct Item {
    pub id: String,
    pub title: String,
    pub created_at: NaiveDateTime,
    pub updated_at: NaiveDateTime,
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0