Giter VIP home page Giter VIP logo

Comments (12)

zhuxiujia avatar zhuxiujia commented on June 12, 2024

Todolist

Todolist 这个结构体 解析uint失败的column成员

from rbatis.

kggg avatar kggg commented on June 12, 2024

todolist中没有存在的记录就会报这个错, 有记录就没有问题,查询结果正常。

from rbatis.

Issues-translate-bot avatar Issues-translate-bot commented on June 12, 2024

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


If there is no record in the todolist, this error will be reported. If there is a record, there will be no problem and the query result will be normal.

from rbatis.

zhuxiujia avatar zhuxiujia commented on June 12, 2024

todolist中没有存在的记录就会报这个错, 有记录就没有问题,查询结果正常。

可以告诉我数据库类型,表结构体的定义,以及 数据库表的数据吗?

from rbatis.

Issues-translate-bot avatar Issues-translate-bot commented on June 12, 2024

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


If there is no record in the todolist, this error will be reported. If there is a record, there will be no problem and the query result will be normal.

Can you tell me the database type, the definition of the table structure, and the data of the database table?

from rbatis.

kggg avatar kggg commented on June 12, 2024

mysql 8

mysql> desc todolist;
+------------+-----------------+------+-----+---------+----------------+
| Field      | Type            | Null | Key | Default | Extra          |
+------------+-----------------+------+-----+---------+----------------+
| id         | bigint unsigned | NO   | PRI | NULL    | auto_increment |
| created_at | datetime(3)     | NO   |     | NULL    |                |
| updated_at | datetime(3)     | NO   |     | NULL    |                |
| deleted_at | datetime(3)     | YES  | MUL | NULL    |                |
| type_id    | bigint          | YES  |     | NULL    |                |
| user       | varchar(20)     | NO   |     | NULL    |                |
| title      | varchar(30)     | NO   |     | NULL    |                |
| status     | int             | NO   |     | 0       |                |
| level      | varchar(8)      | NO   |     | 一般    |                |
| content    | text            | NO   |     | NULL    |                |
+------------+-----------------+------+-----+---------+----------------+
10 rows in set (0.00 sec)

···
#[derive(Debug, Deserialize, PartialEq, Eq, Clone, Serialize)]
pub struct Todolist {
id: Option,
created_at: DateTime,
updated_at: DateTime,
deleted_at: Option,
type_id: u64,
user: String,
title: String,
status: u8,
level: String,
content: String,
}

from rbatis.

Issues-translate-bot avatar Issues-translate-bot commented on June 12, 2024

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


mysql 8

mysql> desc todolist;
+------------+-----------------+------+-----+---------+----------------+
| Field      | Type            | Null | Key | Default | Extra          |
+------------+-----------------+------+-----+---------+----------------+
| id         | bigint unsigned | NO   | PRI | NULL    | auto_increment |
| created_at | datetime(3)     | NO   |     | NULL    |                |
| updated_at | datetime(3)     | NO   |     | NULL    |                |
| deleted_at | datetime(3)     | YES  | MUL | NULL    |                |
| type_id    | bigint          | YES  |     | NULL    |                |
| user       | varchar(20)     | NO   |     | NULL    |                |
| title      | varchar(30)     | NO   |     | NULL    |                |
| status     | int             | NO   |     | 0       |                |
| level      | varchar(8)      | NO   |     | 一般    |                |
| content    | text            | NO   |     | NULL    |                |
+------------+-----------------+------+-----+---------+----------------+
10 rows in set (0.00 sec)

···
#[derive(Debug, Deserialize, PartialEq, Eq, Clone, Serialize)]
pub struct Todolist {
id: Option,
created_at: DateTime,
updated_at: DateTime,
deleted_at: Option,
type_id: u64,
user: String,
title: String,
status: u8,
level: String,
content: String,
}

      

from rbatis.

zhuxiujia avatar zhuxiujia commented on June 12, 2024

mysql 8

mysql> desc todolist;
+------------+-----------------+------+-----+---------+----------------+
| Field      | Type            | Null | Key | Default | Extra          |
+------------+-----------------+------+-----+---------+----------------+
| id         | bigint unsigned | NO   | PRI | NULL    | auto_increment |
| created_at | datetime(3)     | NO   |     | NULL    |                |
| updated_at | datetime(3)     | NO   |     | NULL    |                |
| deleted_at | datetime(3)     | YES  | MUL | NULL    |                |
| type_id    | bigint          | YES  |     | NULL    |                |
| user       | varchar(20)     | NO   |     | NULL    |                |
| title      | varchar(30)     | NO   |     | NULL    |                |
| status     | int             | NO   |     | 0       |                |
| level      | varchar(8)      | NO   |     | 一般    |                |
| content    | text            | NO   |     | NULL    |                |
+------------+-----------------+------+-----+---------+----------------+
10 rows in set (0.00 sec)

··· #[derive(Debug, Deserialize, PartialEq, Eq, Clone, Serialize)] pub struct Todolist { id: Option, created_at: DateTime, updated_at: DateTime, deleted_at: Option, type_id: u64, user: String, title: String, status: u8, level: String, content: String, }

todolist中没有存在的记录就会报这个错,
1 Result<Todolist, rbatis::rbdc::Error> 应该改成 Result<Option<Todolist>, rbatis::rbdc::Error>
这样查不到记录的时候是None才对
2 deleted_at 和type_id 在表里可以为null,那么这2个column 都应该用Option<xxx>才对

from rbatis.

kggg avatar kggg commented on June 12, 2024

谢谢, OK 了

from rbatis.

Issues-translate-bot avatar Issues-translate-bot commented on June 12, 2024

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


Thank you, OK

from rbatis.

zhuxiujia avatar zhuxiujia commented on June 12, 2024

谢谢, OK 了

我更新rbs序列化框架,提示更新为error while decoding value: invalid type: Option value, expected struct Activity 这样可读性更高。你可以使用cargo update命令更新依赖即可

from rbatis.

zhuxiujia avatar zhuxiujia commented on June 12, 2024

怎么判断select结果是no record found?

pub async fn select_todo_by_id(id: u64) -> Result<Todolist, rbatis::rbdc::Error> { let rs = RB .query_decode("select * from todolist where id = ?", vec![Value::U64(id)]) .await?; Ok(rs) } 现在错误打印出来的是以下信息 E("error while decoding value: invalid type: unit value, expected struct Todolist")

推荐使用crud! 宏内置的函数,更方便。

#[macro_use]
extern crate rbatis;

pub mod init;

use crate::init::init_db;
use rbatis::rbdc::datetime::DateTime;
use serde_json::json;

/// table
#[derive(Clone, Debug, serde::Serialize, serde::Deserialize)]
pub struct Activity {
    pub id: Option<String>,
    pub name: Option<String>,
    pub pc_link: Option<String>,
    pub h5_link: Option<String>,
    pub pc_banner_img: Option<String>,
    pub h5_banner_img: Option<String>,
    pub sort: Option<String>,
    pub status: Option<i32>,
    pub remark: Option<String>,
    pub create_time: Option<DateTime>,
    pub version: Option<i64>,
    pub delete_flag: Option<i32>,
}
crud!(Activity {});
impl_select!(Activity{select_all_by_id(id:&str,name:&str) => "`where id = #{id} and name = #{name}`"});
impl_select!(Activity{select_by_id(id:&str) -> Option => "`where id = #{id} limit 1`"});

#[tokio::main]
pub async fn main() {
    fast_log::init(
        fast_log::Config::new()
            .console()
            .level(log::LevelFilter::Debug),
    )
    .expect("rbatis init fail");
    let rb = init_db().await;

    let data = Activity::select_by_column(&rb, "id", "1").await;
    println!("select_by_id = {}", json!(data));

    let data = Activity::select_all_by_id(&rb, "1", "1").await;
    println!("select_all_by_id = {}", json!(data));

    let data = Activity::select_by_id(&rb, "1").await;
    println!("select_by_id = {}", json!(data));
}

from rbatis.

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.