Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add serde skip options for hidden columns to the CLI #1171

Merged
merged 5 commits into from
Dec 19, 2022

Conversation

trueb2
Copy link
Contributor

@trueb2 trueb2 commented Oct 29, 2022

PR Info

New Features

  • Adds a new CLI option --serde-skip-hidden-columns that takes effect when used with --with-serde

Tests

Tested with sqlite

CREATE TABLE IF NOT EXISTS "cake" ( "id" integer NOT NULL PRIMARY KEY AUTOINCREMENT, "name" text , _hidden_name TEXT);
env  DATABASE_URL=sqlite://./test.db cargo run --bin sea-orm-cli -- generate entity  -o tmp --with-serde both --serde-skip-hidden-columns 
//! SeaORM Entity. Generated by sea-orm-codegen 0.10.1

use sea_orm::entity::prelude::*;
use serde::{Deserialize, Serialize};

#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize, Deserialize)]
#[sea_orm(table_name = "cake")]
pub struct Model {
    #[sea_orm(primary_key)]
    pub id: i32,
    pub name: Option<String>,
    #[serde(skip)]
    #[sea_orm(column_name = "_hidden_name")]
    pub hidden_name: Option<String>,
}

#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {}

impl ActiveModelBehavior for ActiveModel {}

The default behavior is the previous behavior, so no breaking changes here.

env  DATABASE_URL=sqlite://./test.db cargo run --bin sea-orm-cli -- generate entity  -o tmp --with-serde both
//! SeaORM Entity. Generated by sea-orm-codegen 0.10.1

use sea_orm::entity::prelude::*;
use serde::{Deserialize, Serialize};

#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize, Deserialize)]
#[sea_orm(table_name = "cake")]
pub struct Model {
    #[sea_orm(primary_key)]
    pub id: i32,
    pub name: Option<String>,
    #[sea_orm(column_name = "_hidden_name")]
    pub hidden_name: Option<String>,
}

#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {}

impl ActiveModelBehavior for ActiveModel {}
env  DATABASE_URL=sqlite://./test.db cargo run --bin sea-orm-cli -- generate entity  -o tmp
//! SeaORM Entity. Generated by sea-orm-codegen 0.10.1

use sea_orm::entity::prelude::*;

#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)]
#[sea_orm(table_name = "cake")]
pub struct Model {
    #[sea_orm(primary_key)]
    pub id: i32,
    pub name: Option<String>,
    #[sea_orm(column_name = "_hidden_name")]
    pub hidden_name: Option<String>,
}

#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {}

impl ActiveModelBehavior for ActiveModel {}

@trueb2
Copy link
Contributor Author

trueb2 commented Oct 29, 2022

I noticed some overlap with #961 and #1159. This implementation could be extended to resolve #1159 by adding another flag and putting more inside the SerdeDeriveOptions enum.

@trueb2
Copy link
Contributor Author

trueb2 commented Nov 5, 2022

Looks like #1186 conflicts

@billy1624 billy1624 changed the base branch from master to issues/961 December 19, 2022 14:21
Copy link
Member

@billy1624 billy1624 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @trueb2, sorry for the delay and thanks for the contributions!

I'd like to merge this into a local branch then refactor it :)

@billy1624 billy1624 merged commit 09075f5 into SeaQL:issues/961 Dec 19, 2022
billy1624 added a commit that referenced this pull request Dec 19, 2022
* Add serde skip options for hidden columns to the CLI (#1171)

* Add serde skip options for hidden columns to the CLI

* Resolve rustfmt and clippy issues

* Use SerdeDeriveOptions instead of WithSerde in tests

* Resolve upstream conflict

Co-authored-by: Billy Chan <ccw.billy.123@gmail.com>

* [CLI] serde_skip_hidden_column

* clippy

* clippy

Co-authored-by: Jacob Trueb <jtrueb@northwestern.edu>
billy1624 added a commit to SeaQL/seaql.github.io that referenced this pull request Feb 3, 2023
tyt2y3 added a commit to SeaQL/seaql.github.io that referenced this pull request Feb 3, 2023
* Update 02-writing-migration.md

* Update SeaORM/docs/03-migration/02-writing-migration.md

* Support various UUID formats that are available in `uuid::fmt` module (SeaQL/sea-orm#1325)

* Casting columns as a different data type on select, insert and update (SeaQL/sea-orm#1304)

* Methods of `ActiveModelBehavior` receive db connection as a parameter (SeaQL/sea-orm#1145, SeaQL/sea-orm#1328)

* Added `execute_unprepared` method to `DatabaseConnection` and `DatabaseTransaction` (SeaQL/sea-orm#1327)

* Added `Select::into_tuple` to select rows as tuples (instead of defining a custom Model) (SeaQL/sea-orm#1311)

* Generate `#[serde(skip)]` for hidden columns (SeaQL/sea-orm#1171, SeaQL/sea-orm#1320)

* Generate entity with extra derives and attributes for model struct (SeaQL/sea-orm#1124, SeaQL/sea-orm#1321)

* Generate entity with extra derives and attributes for model struct (SeaQL/sea-orm#1124, SeaQL/sea-orm#1321)

* async_trait

* Migrations are now performed inside a transaction for Postgres (SeaQL/sea-orm#1379)

* `MockDatabase::append_exec_results()`, `MockDatabase::append_query_results()`, `MockDatabase::append_exec_errors()` and `MockDatabase::append_query_errors()` take any types implemented `IntoIterator` trait (SeaQL/sea-orm#1367)

* Cleanup the use of `vec!` macros

* Added `DatabaseConnection::close` (SeaQL/sea-orm#1236)

* Added `ActiveValue::reset` to convert `Unchanged` into `Set` (SeaQL/sea-orm#1177)

* Added `QueryTrait::apply_if` to optionally apply a filter (SeaQL/sea-orm#1415)

* Added the `sea-orm-internal` feature flag to expose some SQLx types (SeaQL/sea-orm#1297, SeaQL/sea-orm#1434)

* Add `QuerySelect::columns` method - select multiple columns (SeaQL/sea-orm#1264)

* Edit

* Update SeaORM/docs/02-install-and-config/02-connection.md

Co-authored-by: Chris Tsang <chris.2y3@outlook.com>

* Update SeaORM/docs/05-basic-crud/03-insert.md

Co-authored-by: Chris Tsang <chris.2y3@outlook.com>

* fmt

* Edit

---------

Co-authored-by: Chris Tsang <chris.2y3@outlook.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[cli] Add #[serde(skip_serializing)] and #[serde(skip_deserializing)] to hidden collumns
2 participants