1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
//! # 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
//! ```rust
//! 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
//! ```rust
//! 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(())
//! }
//!
//! ```
// ------------------------------------------------------------------------
use SqliteFs;
use LazyLock;
use Mutex;
// ------------------------------------------------------------------------
// pub mod file;
pub
// ------------------------------------------------------------------------
///
/// FS Handle
///
static FS: = new;
///
/// Represents if the FS was already initialized
///
static FS_IS_INIT: = new;