Giter Site home page Giter Site logo

`InsertModel` and `UpdateModel` about sea-orm HOT 6 CLOSED

seaql avatar seaql commented on May 6, 2024
`InsertModel` and `UpdateModel`

from sea-orm.

Comments (6)

tqwewe avatar tqwewe commented on May 6, 2024

I like what you've desribed here... looks promising.

I think this could be related to: #105 - perhaps a refactor to the API can be considered.

from sea-orm.

tyt2y3 avatar tyt2y3 commented on May 6, 2024

After #105, I think it will provide us some compile-time info to work with, i.e. the default_value and default_expr tags.

As such, we'd be able to generate two extra models InsertModel, UpdateModel along with ActiveModel, under the following rules:
For insert model, skip the 'auto_increment primary_key' columns. Fields without default will be wrapped with RequiredValue, ActiveValue otherwise.
For update model, the 'primary_key' columns will be wrapped with RequiredValue while all other fields will be wrapped with ActiveValue

from sea-orm.

billy1624 avatar billy1624 commented on May 6, 2024

Btw... why we cant set an value for primary key with auto_increment during insert?

from sea-orm.

tqwewe avatar tqwewe commented on May 6, 2024

It is possible to specify the primary key even if a primary key column is auto_increment, but I can't imagine many situations where that'd be useful to anyone.

I'm also thinking that the update and insert models can be used with async-graphql under a feature flag in the future, and you typically wouldn't allow the primary key to be set when inserting a new item. But for the async-graphql case, it could just add #[graphql(skip)] to the primary key on the insert model if it were to be kept.

from sea-orm.

nicoulaj avatar nicoulaj commented on May 6, 2024

Please also note all GENERATED ALWAYS columns should be excluded from insert/update queries or use DEFAULT as value. See for example Postgres or MySQL.

A generated column cannot be written to directly. In INSERT or UPDATE commands, a value cannot be specified for a generated column, but the keyword DEFAULT may be specified.

Maybe those could be directly excluded for InsertModel/UpdateModel ? In ActiveModel, maybe ActiveValue could be split into ReadableActiveValue + WritableActiveValue for these columns ?

from sea-orm.

tyt2y3 avatar tyt2y3 commented on May 6, 2024

Thanks @nicoulaj I think you raised a good point not yet considered.

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.