Code Monkey home page Code Monkey logo

Comments (7)

tyt2y3 avatar tyt2y3 commented on July 17, 2024

I got you. The DeriveIden macro comes from SeaQuery's Iden macro, so it has to match the behaviour for backwards compatibility reasons.

I think we can 1) remove it in all examples and use Alias::new instead or 2) design a new macro for a specific purpose or 3) add one more special case (which might be more confusing) or 4) use unit struct instead i.e DeriveIden on struct Something; which has no special treatment

Can you share the pieces of code you end up with, so we can brainstorm how to make it more concise?

from sea-orm.

tyt2y3 avatar tyt2y3 commented on July 17, 2024

Thank you for the feedback. The blog post https://cprimozic.net/notes/posts/trying-out-sea-orm/ is definitely insightful, and we will be able to improve on a few of the problems.

I have addressed some of the confusion by editing the doc https://www.sea-ql.org/SeaORM/docs/generate-entity/enumeration/#native-database-enum and https://www.sea-ql.org/SeaORM/docs/migration/writing-migration/#seaquery

If you have more suggestions, just let us know!

from sea-orm.

hut8 avatar hut8 commented on July 17, 2024

Wow, that was incredibly fast. Thanks so much for your hard work @tyt2y3

from sea-orm.

JMartinCollins avatar JMartinCollins commented on July 17, 2024

Referencing this commit

Another major issue with this approach is that you're unable to use this enum to add entries to the database. Simply put, if the enum is declared using DeriveIden alone, then one can't use this enum to populate the database in a later migration, unless you impl something simliar to as_enum as impl Into<SimpleExpr> for Tea method yourself. That being the case it seems better that the primary example for adding a Postgres enum should use DeriveActiveEnum, unless there's some issue that I'm not aware of with that approach.

Here are the two approaches:

// InsertStatement
      .values_panic([
          // ...some other column values
          // ⚠ This needs to be implemented if only using DeriveIden
          Tea::BreakfastTea.into(),
          // This is provided by DeriveActiveEnum
          Tea::BreakfastTea.as_enum(),
      ])

from sea-orm.

tyt2y3 avatar tyt2y3 commented on July 17, 2024

Not sure if that's been mentioned, but using the create_enum_from_active_enum helper function is probably the easiest way.

from sea-orm.

JMartinCollins avatar JMartinCollins commented on July 17, 2024

Not sure if that's been mentioned, but using the create_enum_from_active_enum helper function is probably the easiest way.

Just a suggestion: If that's the recommended way, maybe it would be best to have that be the first example here and also have it link to an example. Examples maybe should also include examples of using the enum to populate data in a migration using Tea::BreakfastTea.as_enum().

from sea-orm.

tyt2y3 avatar tyt2y3 commented on July 17, 2024

Can you open a PR on https://github.com/SeaQL/seaql.github.io/ ?

from sea-orm.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.