SeaQL / sea-orm

🐚 An async & dynamic ORM for Rust
https://www.sea-ql.org/SeaORM/
Apache License 2.0
7.31k stars 514 forks source link

How to generate `tinyint(1)` as `bool` in mysql. #1640

Closed thinkgos closed 1 year ago

thinkgos commented 1 year ago

Description

Steps to Reproduce

  1. I have a tinyint(1) type in mysql. I use sea-orm-cli v0.11.3
  2. generate below: ```rust

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

[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize, Deserialize)]

[sea_orm(table_name = "dict")]

pub struct Model {

[sea_orm(primary_key)]

pub id: i64,
#[sea_orm(unique)]
pub key: String,
pub name: String,
pub is_pin: i8,
pub remark: String,
pub created_at: DateTime,
pub updated_at: DateTime,

}

[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]

pub enum Relation {}

impl ActiveModelBehavior for ActiveModel {}

3.  `is_pin` should be `bool`. but it is `i8`.

### Expected Behavior

<!-- What is expected to happen? -->
 `is_pin` should be `bool`.
### Actual Behavior

`is_pin`  is   `i8`.
<!-- What actually happened? -->

### Reproduces How Often

<!-- Is it always reproducible? -->

### Workarounds

<!-- What experiments have you done to understand / workaround the bug? -->

## Reproducible Example

<!-- Please add a minimal reproducible example under https://github.com/SeaQL/sea-orm/tree/master/issues, and open a PR subsequently. -->

## Versions

<!-- You can get this information from the output of `cargo tree | grep sea-` from the console. Also, please include the database and OS that you are running. -->

Linux thinkgo 5.19.0-41-generic #42~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Tue Apr 18 17:40:00 UTC 2 x86_64 x86_64 x86_64 GNU/Linux

│ ├── sea-orm v0.11.3 │ │ ├── sea-orm-macros v0.11.3 (proc-macro) │ │ ├── sea-query v0.28.4 │ │ │ ├── sea-query-derive v0.3.0 (proc-macro) │ │ ├── sea-query-binder v0.3.0 │ │ │ ├── sea-query v0.28.4 () │ │ ├── sea-strum v0.23.0 │ │ │ └── sea-strum_macros v0.23.0 (proc-macro) ├── sea-orm v0.11.3 () ├── sea-query v0.28.4 (*)

tyt2y3 commented 1 year ago

Technically tinyint(1) is i8, and there is no (simple) way to determine that it is a bool.

https://stackoverflow.com/questions/12839927/mysql-tinyint-2-vs-tinyint1-what-is-the-difference