sea-orm
sea-orm copied to clipboard
DeriveColumn error
version: sea-orm 0.10.5
I tried to use custom select
#[derive(Copy, Clone, Debug, EnumIter, DeriveColumn)]
enum QueryAs {
CakeName,
}
but got some error for: no method named as_str found for reference &QueryAs in the current scope
Hey @ringrid, hi there. Could you upload a reproducible example to GitHub or pastebin?
I found this enum had no error when together with entity, but i did not know the reason....
entity.rs
use sea_orm::entity::prelude::*;
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)]
#[sea_orm(table_name = "pool")]
pub struct Model {
#[sea_orm(primary_key)]
pub id: i32,
pub name: String,
}
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {}
impl ActiveModelBehavior for ActiveModel {}
main.rs
use sea_orm::{
Database, DeriveColumn, EntityTrait, EnumIter, FromQueryResult, QuerySelect,
};
mod entity;
#[derive(Copy, Clone, Debug, EnumIter, DeriveColumn)]
enum QueryAs {
PoolName,
}
#[derive(Debug, FromQueryResult)]
struct PoolResult {
name: String,
}
#[tokio::main]
async fn main() {
let db = Database::connect("xxxx").await.unwrap();
let result1 = entity::Entity::find()
.select_only()
.column(entity::Column::Name)
.into_model::<PoolResult>()
.all(&db)
.await
.unwrap();
let result2: Vec<String> = entity::Entity::find()
.select_only()
.column_as(entity::Column::Name, QueryAs::PoolName)
.into_values::<_, QueryAs>()
.all(&db)
.await
.unwrap();
}
DeriveColumn has error, but when I put entity.rs into main.rs,it has no error