gpt4 book ai didi

mysql - 如何在柴油模型.rs中用空格写列名?

转载 作者:行者123 更新时间:2023-12-03 11:43:11 25 4
gpt4 key购买 nike

我正在尝试使用Diesel来管理我的数据库,以便与Rocket一起使用,但是我被困在为表编写models.rs的过程中:

CREATE TABLE `problemSet` (
`id` varchar(10) NOT NULL,
`contestId` int DEFAULT NULL,
`difficulty` varchar(10) DEFAULT NULL,
`title` varchar(300) DEFAULT NULL,
`rating` int DEFAULT NULL,
`link` varchar(300) DEFAULT NULL,
`binary search` tinyint(1) DEFAULT '0',
`chinese remainder theorem` tinyint(1) DEFAULT '0',
`constructive algorithms` tinyint(1) DEFAULT '0',
`data structures` tinyint(1) DEFAULT '0',
`dfs and similar` tinyint(1) DEFAULT '0',
`divide and conquer` tinyint(1) DEFAULT '0',
PRIMARY KEY(`id`)
);

在这里,我对于如何在models.rs的结构中为带有空格的column_names编写标识符感到困惑。

我指的是Diesel和RUST的官方指南。

最佳答案

定义模式时,可以使用sql_name属性为列名指定一个与该名称不同的名称,因为该名称将出现在rust代码中:

diesel::table! {
problemSet {
...
#[sql_name = "divide and conquer"]
divide_and_conquer -> Text,
...
}
}

另请: documentation for the table! macro

话虽如此,我的首选是避免列名中的空格。

关于mysql - 如何在柴油模型.rs中用空格写列名?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61814016/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com