5 releases
Uses new Rust 2024
0.0.5 | May 5, 2025 |
---|---|
0.0.4 | May 2, 2025 |
0.0.3 | May 2, 2025 |
0.0.2 | May 2, 2025 |
0.0.1 | May 2, 2025 |
#406 in Database interfaces
411 downloads per month
69KB
1K
SLoC
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,
file::File,
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.lock").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}");
// create a new file in the SQLiteFS
let mut f = File::create(&f_name).await?;
// write data to it
f.write(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,
file::File,
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.lock").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}");
// create a new file in the SQLiteFS
let mut f = File::create(&f_name).await?;
// write data to it
f.write(s.as_bytes()).await?;
}
Ok(())
}
Dependencies
~54MB
~1M SLoC