Comments (6)
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.
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.
Btw... why we cant set an value for primary key with auto_increment during insert?
from sea-orm.
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.
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.
Thanks @nicoulaj I think you raised a good point not yet considered.
from sea-orm.
Related Issues (20)
- Joins from aliased tables: add a helper method or document my workaround
- Derive `Hash` on active enums HOT 2
- sea-orm Fails to Apply Default Value for 'created_at' Field in SQLite HOT 2
- [Feature] Add mock database testing examples
- add AutoMigrate
- Insert row with foreign key value and create foreign key if not exists
- IntoActiveValue is not implemented for Vec<String> HOT 1
- rename_to() error HOT 1
- 0.12.8 won't build? HOT 3
- Runtime error when saving entry using unsupported Model Column Type HOT 1
- debug log not work as expected HOT 2
- LoaderTrait: load_many fails in partial models
- Migrator does not exist HOT 3
- PostgresQL error `no schema has been selected to create in` HOT 1
- sea-orm-cli does not generate named relations
- `sea-orm-migration` CLI shouldn't always connect to a database
- FromJsonQueryResult should also work with generic types HOT 1
- sea-orm-cli generates uncompilable model from pre-existing autoincrement primary key in sqlite
- Surprising ordering of native MySQL enums
- Entity generation fails if `model-extra-attributes` include a comma surrounded by parentheses HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sea-orm.