Skip to content

Commit

Permalink
[issues] fully qualified IdenStatic::as_str() (#1280)
Browse files Browse the repository at this point in the history
  • Loading branch information
billy1624 authored Dec 6, 2022
1 parent ee2afc4 commit fa94521
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 3 deletions.
17 changes: 17 additions & 0 deletions issues/1278/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[workspace]
# A separate workspace

[package]
name = "sea-orm-issues-1278"
version = "0.1.0"
edition = "2021"
publish = false

[dependencies]
serde = "^1"
tokio = { version = "^1", features = ["rt", "rt-multi-thread", "macros"] }

[dependencies.sea-orm]
path = "../../"
default-features = false
features = ["macros", "runtime-tokio-native-tls"]
14 changes: 14 additions & 0 deletions issues/1278/src/entity.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
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 {}
36 changes: 36 additions & 0 deletions issues/1278/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
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();
}
2 changes: 1 addition & 1 deletion sea-orm-macros/src/derives/column.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ pub fn expand_derive_custom_column(ident: &Ident, data: &Data) -> syn::Result<To
#[automatically_derived]
impl sea_orm::Iden for #ident {
fn unquoted(&self, s: &mut dyn std::fmt::Write) {
write!(s, "{}", self.as_str()).unwrap();
write!(s, "{}", sea_orm::IdenStatic::as_str(self)).unwrap();
}
}
))
Expand Down
2 changes: 1 addition & 1 deletion sea-orm-macros/src/derives/entity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ impl DeriveEntity {
#[automatically_derived]
impl sea_orm::Iden for #ident {
fn unquoted(&self, s: &mut dyn std::fmt::Write) {
write!(s, "{}", self.as_str()).unwrap();
write!(s, "{}", sea_orm::IdenStatic::as_str(self)).unwrap();
}
}
)
Expand Down
2 changes: 1 addition & 1 deletion sea-orm-macros/src/derives/primary_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ pub fn expand_derive_primary_key(ident: Ident, data: Data) -> syn::Result<TokenS
#[automatically_derived]
impl sea_orm::Iden for #ident {
fn unquoted(&self, s: &mut dyn std::fmt::Write) {
write!(s, "{}", self.as_str()).unwrap();
write!(s, "{}", sea_orm::IdenStatic::as_str(self)).unwrap();
}
}

Expand Down

0 comments on commit fa94521

Please sign in to comment.