小编Tim*_*Tim的帖子

如何使用diesel-rs选择色谱柱的子集?

我现在花了几个小时的时间来查询表的可用列的子集以及在其中包含计算。我知道这不是在选择查询中执行计算的最佳方式,但现在,我只是在开发一个原型,它应该是可行的。

diesel-rs在后端实现中将其用作所有数据库操作的 ORM。数据将存储在 PostgresSQL 服务器中。存储在数据库中的完整表是使用以下查询创建的:

CREATE TABLE airports
(
    id          SERIAL PRIMARY KEY,
    icao_code   VARCHAR(4) NOT NULL UNIQUE, -- the official ICAO code of the airport
    last_update TIMESTAMP  NOT NULL,        -- when were the information updated the last time?
    country     VARCHAR(2) NOT NULL,        -- two letter country code
    longitude   REAL       NOT NULL,        -- with 6 decimal places
    latitude    REAL       NOT NULL,        -- with 6 decimal places
    name        VARCHAR    NOT NULL         -- just a human readable name of the …
Run Code Online (Sandbox Code Playgroud)

postgresql rust rust-diesel

6
推荐指数
1
解决办法
5220
查看次数

如何将不同的类实例分配给 Rust 中的变量?

我正在尝试用 Rust 创建一个简单的程序(用于教育目的)。目前,我主要使用经典的 OOP 语言(如 Java)进行开发,因此我意识到我可能无法在 Rust 中实现相同的功能。

我试图通过根据外部(用户触发)输入初始化变量,然后在此对象实例上调用方法来避免重复代码。

我搜索了一段时间寻找答案,但我无法为我的问题得到明确的答案。

为了说明我的问题,我用 Java 写了以下几行:

interface Command {
    String getName();
}

class FirstCommand implements Command {
    @Override
    public String getName() {
        return "First command";
    }
}

class SecondCommand implements Command {
    @Override
    public String getName() {
        return "Second command";
    }
}

public class Test {
    public static void main(String[] argv) {
        Command cmd;
        if (argv.length > 10) {
            cmd = new SecondCommand();
        } else {
            cmd = new FirstCommand();
        }
        System.out.println(cmd.getName());
    } …
Run Code Online (Sandbox Code Playgroud)

rust

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

标签 统计

rust ×2

postgresql ×1

rust-diesel ×1