Skip to content

Use SQL functions in Rust for checkpointing in SQLite bagfile databases #9

@ruffsl

Description

@ruffsl

Diesel, the Rust crate being migrated to for interfacing with recording in SQLite .db3, enables the use of custom sql_functions which can also be implemented in rust:
http://docs.diesel.rs/diesel/macro.sql_function.html#use-with-sqlite

I'm still unsure how to formulate a SQL query that could loop over all rows given a topic_id (A vs B) in the messages (1,2,...,N) table such that it could replicate a hash chain as follows in (9) and (10):

image

An example of specifying a .filter() query using the topic_id as a criteria is as follows:

use crate::schema::messages::dsl::topic_id;
let message_results = messages::table
.filter(topic_id.eq(topic_result.id))
.load::<message::Message>(&conn)
.expect("Error loading messages");

Would it be possible to replicate something like a LAG function (guessing here?) over filter query and feed that into a custom function in SQL sequentially? Is this even possible in SQLite?

https://www.sqlitetutorial.net/sqlite-window-functions/sqlite-lag/

CREATE TABLE messages(
id INTEGER PRIMARY KEY NOT NULL,
topic_id INTEGER NOT NULL,
timestamp INTEGER NOT NULL,
data BLOB NOT NULL,
bbr_digest BLOB);

Relates to: diesel-rs/diesel#1775 , cc @weiznich

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions