#[derive(Entity)]
{
// Attributes available to this derive:
#[sqlx]
#[column]
#[postgres]
#[sqlite]
#[mysql]
}
Expand description
Derive macro to automatically derive the Schema and Bind traits.
§The column directive
The schema for the column can provided using the column directive:
use miniorm::prelude::*;
use sqlx::FromRow;
#[derive(Debug, Clone, Eq, PartialEq, FromRow, Entity)]
struct Todo {
#[column(TEXT NOT NULL)]
description: String,
#[column(BOOLEAN NOT NULL DEFAULT false)]
done: bool,
}in which case the Schema and Bind trait will be derived for all
supported database types.
| Requires the full feature flag. |
§The backend-specific directive
If only a specific backend is necessary, one of the dedicated backend-specific
directive should be used instead. For instance, if Schema and Bind should
only be derived for postgres:
use miniorm::prelude::*;
use sqlx::FromRow;
#[derive(Debug, Clone, Eq, PartialEq, FromRow, Entity)]
struct Todo {
#[postgres(TEXT NOT NULL)]
description: String,
#[postgres(BOOLEAN NOT NULL DEFAULT false)]
done: bool,
}| This example requires the postgres feature flag. |
§The sqlx directive
At the moment, only the following sqlx directives for FromRow are supported:
skiprenamejson
use miniorm::prelude::*;
use sqlx::FromRow;
#[derive(Debug, Clone, Eq, PartialEq, FromRow, Entity)]
struct Todo {
#[postgres(TEXT NOT NULL)]
description: String,
#[postgres(BOOLEAN NOT NULL DEFAULT false)]
#[sqlx(rename = "DONE")]
done: bool,
#[sqlx(skip)]
metadata: String,
}