2 个版本
| 0.1.1 | 2024年2月15日 |
|---|---|
| 0.1.0 | 2024年2月15日 |
#1519 在 数据库接口
每月 25 次下载
6KB
68 行
diesel-point —

Postgres 中 Point 类型的 Diesel 支持
使用示例
在你的 sql 架构中,你有一个列 some_point_field Point not null。当 Diesel 生成架构时(使用 table! {}),此列将看起来像 some_point_field -> Point。为确保 Point 类型在作用域内,阅读 此指南 并将 use diesel_point::sql_types::* 添加到你的 diesel.toml 文件的 import_types 键中。
例如,它将看起来像这样
[print_schema]
file = "src/schema.rs"
import_types = ["diesel::sql_types::*", "diesel_point::sql_types::*"]
在你的 ORM 结构体中,编写 some_point_field: PointXy。
现在你可以在 diesel 查询中使用此结构体/表。
如果你的表已经创建,首先运行 diesel 迁移回退。在 ORM 结构体中使用 PointXy,然后再次运行迁移。
示例
#[derive(Insertable, Queryable, Identifiable, Serialize, PartialEq, Debug, Clone, AsChangeset)]
#[diesel(primary_key(model_id))]
#[diesel(table_name = my_table)]
pub struct Mytable{
pub model_id: Uuid,
pub some_point_field: PointXy,
}
依赖项
~3.5MB
~73K SLoC