
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:
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,
file::File,
fs::{FsMode, SqliteFs},
};
use std::io::Read;
#[tokio::main]
async fn main() -> Result<(), FsStatus> {
let mut s = String::new();
let mut x = std::fs::File::open("Cargo.lock").unwrap();
x.read_to_string(&mut s).unwrap();
drop(x);
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}");
let mut f = File::create(&f_name).await?;
f.write(s.as_bytes()).await?;
}
Ok(())
}
Example 2 - Persistent FS
use sqlitefs::{
datatypes::FsStatus,
file::File,
fs::{FsMode, SqliteFs},
};
use std::io::Read;
#[tokio::main]
async fn main() -> Result<(), FsStatus> {
let mut s = String::new();
let mut x = std::fs::File::open("Cargo.lock").unwrap();
x.read_to_string(&mut s).unwrap();
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}");
let mut f = File::create(&f_name).await?;
f.write(s.as_bytes()).await?;
}
Ok(())
}