Docs.rs
  • sqlitefs-0.0.6
    • sqlitefs 0.0.6
    • Permalink
    • Docs.rs crate page
    • EUPL-1.2
    • Links
    • Homepage
    • Repository
    • crates.io
    • Source
    • Owners
    • KajSoerenGrunow
    • Dependencies
      • base64 =0.22.1 normal
      • flate2 =1.1.1 normal
      • log =0.4.27 normal
      • sha2 =0.10.9 normal
      • sqlx =0.8.6 normal
      • thiserror =2.0.12 normal
      • tokio =1.45.1 normal
      • uuid =1.17.0 normal
    • Versions
    • 82.35% of the crate is documented
  • Platform
    • i686-unknown-linux-gnu
    • x86_64-unknown-linux-gnu
  • Feature flags
  • docs.rs
    • About docs.rs
    • Privacy policy
  • Rust
    • Rust website
    • The Book
    • Standard Library API Reference
    • Rust by Example
    • The Cargo Guide
    • Clippy Documentation

Crate sqlitefs

sqlitefs0.0.6

  • All Items

Sections

  • SQLiteFS
    • Example 1 - In-Memory FS
    • Example 2 - Persistent FS

Crate Items

  • Modules

Crates

  • sqlitefs

Crate sqlitefs

Source
Expand description

§SQLiteFS

SQLiteFS is a Rust Crate to provide you with an In-App Filesystem based on SQLite.

The base for this are the SQLite Docs:

  • SQLite As An Application File Format: https://sqlite.org/appfileformat.html
  • SQLite Archive Files: https://sqlite.org/sqlar.html

This crate is basically just a wrapper around a SQLite Database.

This crate makes use of sqlx and uses the default (bundled) feature. So SQLite should be included on build and there should be no need to install SQLite separately on your machine.

§Example 1 - In-Memory FS

use sqlitefs::{
    datatypes::FsStatus,
    fs::{FsMode, SqliteFs},
};
use std::io::Read;

#[tokio::main]
async fn main() -> Result<(), FsStatus> {
    // read a file so we have some data to work with
    let mut s = String::new();
    let mut x = std::fs::File::open("Cargo.toml").unwrap();
    x.read_to_string(&mut s).unwrap();
    drop(x);
    // ----------------------------------------------------------------------

    // Init the FS. Must be called befor anything usefull can be done with it
    SqliteFs::init(FsMode::Memory).await?;

    for i in 1..=100 {
        let uuid = uuid::Uuid::now_v7();
        let f_name = format!("/my/new/file_{i}_{uuid}");

        SqliteFs::write(&f_name, &s.as_bytes()).await?;
    }

    // Optional: Save the memory fs to disk. Otherwise everything will get lost.
    // Right now there is no way to load such saved FS back into memory
    // let fs_path = "FS.SQLITE".to_string();
    // SqliteFs::save_memory_fs_to_disk(&fs_path).await?;

    Ok(())
}

§Example 2 - Persistent FS

use sqlitefs::{
    datatypes::FsStatus,
    fs::{FsMode, SqliteFs},
};
use std::io::Read;

#[tokio::main]
async fn main() -> Result<(), FsStatus> {
    // read a file so we have some data to work with
    let mut s = String::new();
    let mut x = std::fs::File::open("Cargo.toml").unwrap();
    x.read_to_string(&mut s).unwrap();

    // ----------------------------------------------------------------------

    // Init the FS. Must be called befor anything usefull can be done with it
    let fs_path = "FS.SQLITE".to_string();
    SqliteFs::init(FsMode::Persist(fs_path)).await?;

    for i in 1..=100 {
        let uuid = uuid::Uuid::now_v7();
        let f_name = format!("/my/new/file_{i}_{uuid}");

        SqliteFs::write(&f_name, &s.as_bytes()).await?;
    }

    Ok(())
}

Modules§

datatypes
dtos
fs

Results

Settings
Help
    enum variant
    sqlitefs::datatypes::FsStatus::ErrorFileExist
    Text
    enum variant
    sqlitefs::datatypes::FsStatus::ErrorFileNotFound
    enum variant
    sqlitefs::datatypes::FsStatus::ErrorFileExistAlready
    method
    sqlitefs::fs::SqliteFs::remove_file
    Removes a file from the filesystem.
    struct
    sqlitefs::fs::SqliteFsFileMeta
    enum variant
    sqlitefs::datatypes::FsStatus::ErrorGetFileNameList
    Text
    enum variant
    sqlitefs::datatypes::FsStatus::ErrorOpenFile
    Text
    enum variant
    sqlitefs::datatypes::FsStatus::ErrorReadFileData
    Text
    enum variant
    sqlitefs::datatypes::FsStatus::ErrorWriteFile
    Text
    enum variant
    sqlitefs::datatypes::FsStatus::ErrorCreateFile
    Text Text
    enum variant
    sqlitefs::datatypes::FsStatus::ErrorDeleteFile
    Text
    enum variant
    sqlitefs::datatypes::FsStatus::ErrorCouldNotReadFile
No results :(
Try on DuckDuckGo?

Or try looking in one of these:
  • The Rust Reference for technical details about the language.
  • Rust By Example for expository code examples.
  • The Rust Book for introductions to language features and the language itself.
  • Docs.rs for documentation of crates released on crates.io.
No results :(
Try on DuckDuckGo?

Or try looking in one of these:
  • The Rust Reference for technical details about the language.
  • Rust By Example for expository code examples.
  • The Rust Book for introductions to language features and the language itself.
  • Docs.rs for documentation of crates released on crates.io.