NyxCode / ormx

bringing orm-like features to sqlx
MIT License
287 stars 32 forks source link

syntax error at or near "desc" #1

Closed dragonnn closed 3 years ago

dragonnn commented 3 years ago

Hi! Why I try to use ormx with my model:

#[derive(Debug, Serialize, Deserialize, FromRow, Encode, Eq, PartialEq, Clone, ormx::Table)]
#[ormx(table = "users.list", id = id, insertable)]
pub struct User {
    #[serde(default)]
    pub id: i32,
    pub login: Option<String>,
    // #[serde(skip)]
    pub password: Option<String>,
    pub name: Option<String>,
    pub subname: Option<String>,
    pub phone: Option<String>,
    pub desc: Option<String>,
    pub access_card: Option<i32>,
    pub owner_id: Option<i32>,
    pub register_date: Option<chrono::NaiveDateTime>,
}

I got an error:

error: error returned from database: syntax error at or near "desc"

I think the problem is that you don't escape columns names and desc is a keyword in PostgreSQL :/. I think this should be easy to fix?

NyxCode commented 3 years ago

Yes, column names are currently not escaped. I'll escape them when I detect a keyword, thanks for raising the issue!

NyxCode commented 3 years ago

Fixed now. ormx still emits a warning when a reserved identifier is used since there are some things to keep in mind when using reserved keywords as identifier

dragonnn commented 3 years ago

Nice! Thank you :)