NyxCode / ormx

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

Can not use sqlx FromRow or Encode with ormx #2

Closed dragonnn closed 3 years ago

dragonnn commented 3 years ago

Sorry for opening another issue :/ When I try add FromRow derive to my struct at the same time as Table from ormx I got:

error: proc-macro derive panicked
  --> src/models/users/list.rs:38:41
   |
38 | #[derive(Debug, Serialize, Deserialize, FromRow, ormx::Table, Clone, Eq, PartialEq)]
   |                                         ^^^^^^^
   |
   = help: message: called `Result::unwrap()` on an `Err` value: Error("expected literal")

And when I try add Encode I got:

error: expected literal
  --> src/models/users/list.rs:39:1
   |
39 | #[ormx(table = "users.list", id = id, insertable)]

Can sqlx and ormx coexist at the same time on the same struct?

NyxCode commented 3 years ago

No problem, I appreciate every issue you open, I'm sure there are a lot of edge-cases I missed. That's strange, I will have to investigate what's going on here. I don't see why it shouldn't work.

dragonnn commented 3 years ago

Thanks! If you need any addition info or a small test case I can create one.

NyxCode commented 3 years ago

Seems like sqlx does a poor job of parsing attributes. It seems like sqlx tries to pase #[ormx(..)].

NyxCode commented 3 years ago

Yeah, they parse every field attribute as meta: https://github.com/launchbadge/sqlx/blob/5f793c6e957d2b21ac3e1fe055f7c78274619b66/sqlx-macros/src/derives/attributes.rs#L128 While most macros only have meta attributes, I purposefully differentiated between #[ormx(key = "string")] and #[ormx(key = some::path)]. I'll open an issue on sqlx.

dragonnn commented 3 years ago

sqlx 0.4.1 is out :). Should have a fix for that included. Not sure if this is a problem in versions when I have in my project 0.4.1 and ormx tries to use beta version but I got this

58  |                       Self::$fi(x) => x.fetch(executor)
    |                                         ^^^^^ method not found in `sqlx::query::Map<'_, DB, F31, A31>`

When my project. Maybe just a version bump will fix that?

NyxCode commented 3 years ago

Sorry for the late reply, was pretty busy. Yes, sqlx::query::Map seems to have been changed. Just fixed it, 0.2 depends on sqlx 0.4 and should hopefully work.

NyxCode commented 3 years ago

If there are still problems, feel free to open another issue!

dragonnn commented 3 years ago

Works fine now :), thank you!