标签: rust-diesel

不支持 PostgreSQL 身份验证方法 10

我正在尝试使用 PostgreSQL 遵循diesel.rs 教程。当我进入 Diesel 设置步骤时,收到“不支持身份验证方法 10”错误。我该如何解决?

postgresql rust rust-diesel

19
推荐指数
2
解决办法
11万
查看次数

Rust的柴油图书馆与Postgres的时间戳

今天我一直在看看Rust的Diesel ORM,继续这个演练,我无法Timestamp上班.

Cargo.toml

[dependencies]
diesel = { version = "0.6.2", features = ["chrono"] }
diesel_codegen = { version = "0.6.2", default-features = false, features = ["nightly", "postgres"] }
dotenv = "0.8.0"
dotenv_macros = "0.8.0"
Run Code Online (Sandbox Code Playgroud)

models.rs

#[derive(Queryable)]

pub struct Author {
    pub id: i32,
    pub first_name: String,
    pub last_name: String,
    pub email: String
}

pub struct Post {
    pub id: i32,
    pub author: Author,
    pub title: String,
    pub body: String,
    pub published: bool,
    pub created: …
Run Code Online (Sandbox Code Playgroud)

postgresql rust rust-diesel

18
推荐指数
1
解决办法
4455
查看次数

如何在Diesel中为自定义字段类型实现Queryable和Insertable?

我有一个我希望通过Diesel使用的SQL表:

CREATE TABLE records (
    id BIGSERIAL PRIMARY KEY,
    record_type SMALLINT NOT NULL,
    value DECIMAL(10, 10) NOT NULL
)
Run Code Online (Sandbox Code Playgroud)

该表生成以下模式:

table! {
    records (id) {
        id -> Int8,
        record_type -> Int2,
        value -> Numeric,
    }
}
Run Code Online (Sandbox Code Playgroud)

Diesel将小数字输出为bigdecimal::BigDecimal,但我想decimal::d128改为使用.我也想映射record_type到枚举,所以我声明我的模型如下:

use decimal::d128;

pub enum RecordType {
    A,
    B,
}

pub struct Record {
    pub id: i64,
    pub record_type: RecordType,
    pub value: d128,
}
Run Code Online (Sandbox Code Playgroud)

我不能使用#derive(Queryable, Insertable)因为非标准类型映射,所以我尝试自己实现这些特征:

impl Queryable<records::SqlType, Pg> for Record {
    type Row = (i64, …
Run Code Online (Sandbox Code Playgroud)

rust rust-diesel

14
推荐指数
2
解决办法
1754
查看次数

如何制作柴油机自动生成模型

我现在使用此命令在 rustdiesel 中生成模式:

diesel --database-url postgres://postgres:kZLxttcZSN@127.0.0.1:5432/rhythm \
migration run --config-file="${CURRENT_DIR}"/diesel-rhythm.toml
Run Code Online (Sandbox Code Playgroud)

这是 toml 配置:

[print_schema]
file = "src/model/diesel/rhythm/rhythm_schema.rs"

# This will cause only the users and posts tables to be output
filter = { only_tables = ["favorites", "songs", "playlist"] }
Run Code Online (Sandbox Code Playgroud)

是否可以让柴油机自动生成模型实体?该实体可能如下所示:

#[derive( Serialize, Queryable, Deserialize,Default)]
pub struct Music {
    pub id: i64,
    pub name: String,
    pub source_id: String
}
Run Code Online (Sandbox Code Playgroud)

现在我通过句柄编写实体。我应该怎么做才能让它由diesel cli生成,我阅读了文档,但没有找到任何有用的配置。

rust rust-diesel

12
推荐指数
1
解决办法
5417
查看次数

使用 Diesel 的 `belongs_to` 属性时“使用未声明的类型或模块”

我松散地遵循 Diesel 的入门指南尝试设置关系数据库,但在编译时出现以下错误:

error[E0433]: failed to resolve: use of undeclared type or module `birds`
 --> src/models.rs:9:12
  |
9 | pub struct Bird {
  |            ^^^^ use of undeclared type or module `birds`

error: aborting due to previous error

For more information about this error, try `rustc --explain E0433`.
error: Could not compile `prrr_gql`.

Run Code Online (Sandbox Code Playgroud)

这是二进制文件:

extern crate prrr_gql;
extern crate diesel;

use self::prrr_gql::*;
use self::models::*;
use self::diesel::prelude::*;

fn main() {
    use prrr_gql::schema::cats::dsl::*;
    use prrr_gql::schema::birds::dsl::*;

    let connection = establish_connection();
    let …
Run Code Online (Sandbox Code Playgroud)

rust rust-diesel

11
推荐指数
1
解决办法
1万
查看次数

`bigdecimal::BigDecimal` 未实现特性 `diesel::Expression`

我正在尝试创建一个可以在柴油中用于插入的结构。具体来说,我正在使结构可插入。编译时出现此错误。

我有一个结构,我试图Insertable通过派生属性来制作。我有一个名为的字段Bounty,它应该代表钱,所以我使用它BigDecimal作为类型。编译后,我收到标题中的错误。我也试过使用,f64但这给出了同样的错误。

#[macro_use]
extern crate diesel;
extern crate bigdecimal;

mod schema {
    use bigdecimal::BigDecimal;
    table! {
        Threads (Id) {
            Id -> Int8,
            Views -> Int4,
            Points -> Int4,
            FlagPoints -> Int4,
            IsDisabled -> Bool,
            IsAnswered -> Bool,
            Bounty -> Numeric,
            Title -> Varchar,
            Body -> Text,
            UserId -> Int8,
            CreatedBy -> Varchar,
            CreatedOn -> Timestamptz,
            LastModifiedBy -> Varchar,
            LastModifiedOn -> Timestamptz,
        }
    }

    #[allow(non_snake_case)]
    #[derive(Debug, Insertable)]
    #[table_name = "Threads"]
    pub struct InsertableThread …
Run Code Online (Sandbox Code Playgroud)

postgresql rust rust-diesel

10
推荐指数
2
解决办法
5726
查看次数

如何重新运行 Diesel 迁移?

我将 Diesel 与 PostgreSQL 一起使用。我添加了我的迁移,它们工作正常,输出schema.rs文件中的所有内容。直到我注意到我遗漏了created_at一些迁移中的字段。我编辑了 SQL 并运行了diesel migration run. 什么也没发生,没有错误,没有成功。有没有办法解决这个问题并重新运行我的迁移?

sql postgresql rust rust-diesel

10
推荐指数
1
解决办法
6402
查看次数

Rust / Diesel:如何查询具有uuid的postgres表并将其插入

我有Diesel生成的以下架构:

table! {
user (id) {
    id -> Uuid,
    name -> Text
}
Run Code Online (Sandbox Code Playgroud)

和相关的模型

use diesel::{
    self,
    Queryable,
    Insertable,
};
use diesel::prelude::*;
use diesel::sql_types::Uuid;
use super::schema::user;

#[derive(Queryable)]
pub struct User {
    pub id: Uuid,
    pub name: String,
}

impl User {

    pub fn get(id: i32, connection: &PgConnection) -> Vec<User> {
        user::table.load::<User>(connection).unwrap()
    }
}
Run Code Online (Sandbox Code Playgroud)

尝试编译此错误时显示错误:

table! {
user (id) {
    id -> Uuid,
    name -> Text
}
Run Code Online (Sandbox Code Playgroud)

如果我尝试插入,Expression则会收到类似的错误消息,提示未实现。

这可能是我的依赖项有问题还是我可能忘记将其添加到模型中?

[dependencies]
rocket = "0.4.0-rc.1"
serde = "1.0"
serde_derive = "1.0" …
Run Code Online (Sandbox Code Playgroud)

rust rust-diesel

8
推荐指数
2
解决办法
1392
查看次数

无法在 Mac M1 上链接 libpq

我一直在尝试在我的 Macbook M1 上运行 Rust Diesel crate,但它不起作用。编译的最后部分因以下错误而中断:

\n
  = note: ld: warning: ignoring file /usr/local/Cellar/libpq/14.1/lib/libpq.dylib, building for macOS-arm64 but attempting to link with file built for macOS-x86_64\n          Undefined symbols for architecture arm64:\n
Run Code Online (Sandbox Code Playgroud)\n

当我得到信息时,libpq我得到以下信息:

\n
maxwellflitton@Maxwells-MacBook-Pro vanguard % brew info libpq                                                           \nlibpq: stable 14.1 (bottled) [keg-only]\nPostgres C API library\nhttps://www.postgresql.org/docs/14/libpq.html\n/usr/local/Cellar/libpq/14.1 (2,335 files, 27.8MB)\n  Poured from bottle on 2022-01-09 at 00:14:32\nFrom: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/libpq.rb\nLicense: PostgreSQL\n==> Dependencies\nRequired: krb5 \xe2\x9c\x94, openssl@1.1 \xe2\x9c\x94\n==> Caveats\nlibpq is keg-only, which means it was not symlinked into /usr/local,\nbecause conflicts …
Run Code Online (Sandbox Code Playgroud)

postgresql macos libpq rust-diesel

8
推荐指数
1
解决办法
6611
查看次数

rustdiesel 与 `cc` 链接失败

好吧,这里有点无处可去。在我发布了我的 Mac M1 与 Rust Diesel 的链接器问题并没有得到任何结果之前。因此,我启动了一个 Ec2 实例,并尝试在此处运行此包,并得到以下结果:

error: linking with `cc` failed: exit status: 1
...
 = note: /usr/bin/ld: cannot find -lpq
Run Code Online (Sandbox Code Playgroud)

我已经安装了以下内容:

sudo yum update -y
sudo yum install git -y
sudo yum groupinstall "Development Tools" -y
sudo yum install cmake -y
sudo yum install postgresql-libs -y
Run Code Online (Sandbox Code Playgroud)

说真的,人们是如何设法让这个箱子运行的?

linker cc rust rust-diesel

8
推荐指数
1
解决办法
3395
查看次数

标签 统计

rust-diesel ×10

rust ×9

postgresql ×5

cc ×1

libpq ×1

linker ×1

macos ×1

sql ×1