Comments (12)
Todolist
Todolist 这个结构体 解析uint失败的column成员
from rbatis.
todolist中没有存在的记录就会报这个错, 有记录就没有问题,查询结果正常。
from rbatis.
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.
todolist中没有存在的记录就会报这个错, 有记录就没有问题,查询结果正常。
可以告诉我数据库类型,表结构体的定义,以及 数据库表的数据吗?
from rbatis.
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.
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.
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.
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.
谢谢, OK 了
from rbatis.
Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑🤝🧑👫🧑🏿🤝🧑🏻👩🏾🤝👨🏿👬🏿
Thank you, OK
from rbatis.
谢谢, OK 了
我更新rbs序列化框架,提示更新为error while decoding value: invalid type: Option value, expected struct Activity
这样可读性更高。你可以使用cargo update
命令更新依赖即可
from rbatis.
怎么判断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)
- After using rbatis 4, it was found that it is not compatible with the criterion bench HOT 3
- How to use the function that supports sqlite to set password? HOT 1
- How to use the function that supports sqlite to set password? HOT 7
- Transactton Token error: 'Incorrect syntax near 'begin'.' on server HOT 5
- Removed local dependencies. Re-cargo build reports an error! Version rbatis: 4.5.11 HOT 5
- method `set_timeout` is not a member of trait `Pool` HOT 17
- add duckdb support HOT 4
- Hello, I have encountered a question: functions in traits cannot be declared `async` HOT 2
- When using enumeration, can it support automatic conversion to integer when saving or updating, and automatically convert integer to enumeration when selecting? HOT 2
- Intermittent Delays in Query Execution After Periods of Inactivity HOT 4
- MSSQL using transactions error: token error: 'Incorrect syntax near 'begin'.' on server MSSQL2016 executing on line 1 (code: 102, state: 1, class: 15) HOT 2
- crud insert is error when the primary key column name is not id
- html_sql can't trim uppercase "and|or" after where HOT 1
- htmlsql_select_page field is filtered problem HOT 2
- The json field of the database is returned as an escaped string HOT 2
- Setting result error using py_sql with single result HOT 1
- Is there any synchronized Chinese document? HOT 3
- Unable to update column to null.
- Prior code to get SQLite version using sqlite_version() works. Now broken. [Solved Manually. See comments] HOT 2
- test_decode_time_zone error
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 rbatis.