< 返回版块

KKould 发表于 2023-10-03 01:02

Tags:KV, SQL, DBMS

#[derive(Debug, Clone, Default)]
pub struct Post {
    pub post_title: String,
    pub post_date: NaiveDateTime,
    pub post_body: String,
}

implement_from_tuple!(Post, (
    post_title: String => |post: &mut Post, value: DataValue| {
        if let Some(title) = value.utf8() {
            post.post_title = title;
        }
    },
    post_date: NaiveDateTime => |post: &mut Post, value: DataValue| {
        if let Some(date_time) = value.datetime() {
            post.post_date = date_time;
        }
    },
    post_body: String => |post: &mut Post, value: DataValue| {
        if let Some(body) = value.utf8() {
            post.post_body = body;
        }
    }
));

async fn get_posts(kip_sql: &Database<KipStorage>) -> Result<Vec<Post>, DatabaseError> {
    Ok(kip_sql.run("select post_title, post_date, post_body from myposts")
        .await?
        .into_iter()
        .map(|tuple| Post::from(tuple))
        .collect_vec())
}

仓库地址:https://github.com/KipData/KipSQL 覆盖了大多数SQL语法,并支持索引(目前仅支持唯一索引) 我为其写了一个Web Example项目部署到了线上: http://www.kipdata.site/

同时希望对Rust熟悉且对数据库感兴趣的大佬们一起参与进来 喜欢的话,请给个Star吧!


Ext Link: http://www.kipdata.site/

评论区

写评论

还没有评论

1 共 0 条评论, 1 页