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)
- Generated Rust enum ordering does not match underlying database enum ordering HOT 1
- Postgres: SET TRANSACTION ISOLATION LEVEL & ACCESS MODE could be combined into a single statement
- SQLite: Format of DateTimeUtc is wrong HOT 14
- mismatched types, sqlx_postgres::types::oid::Oid>` (as SQL type `OID`) is not compatible with SQL type `INT4` in PostgreSQL
- Vulnerability in the `rsa` (a recursive dependency of SeaORM) HOT 1
- Issue when using `on_conflict` with sqlite HOT 1
- Syntax error when trying to drop multiple tables in migrations with SQLite HOT 1
- does postgres int8 work? HOT 2
- [Testing] Error: `A null value was encountered while decoding "num_items"` when testing pagination and counting HOT 1
- support sqlx v0.8 HOT 1
- sea-orm-cli 1.0 doesn't support mysql type: `bit` HOT 2
- VarBinary(16) column breaks DeriveEntityModel derive
- sea-orm-cli 1.0 generate entity from mysql generates String for MediumBlob fields
- Timezone offset information lost when reading a ChronoDateTimeWithTimeZone HOT 1
- Cannot run sea-orm-cli with feature codegen without sqlite as a dependency HOT 1
- `schema::custom()` requires `col` and `name` to be of same type
- Vec<RoleEnum> in SeaORM Entity Model Causes Compilation Error HOT 1
- No reference to features list or alternate DB connectors in docs.
- Support for `HashMap`
- `sea-orm-migration` is missing the `sqlx-all` feature
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.