Skip to content

Commit 3975079

Browse files
committed
feat: add readme
1 parent ca703b4 commit 3975079

File tree

3 files changed

+59
-4
lines changed

3 files changed

+59
-4
lines changed

README.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# sqlite-vfs-http
2+
3+
The `sqlite-vfs-http` is a library based on the SQLite VFS extension, designed to access static SQLite files located on a CDN via HTTP/HTTPS protocol.
4+
5+
By using this library, you can host SQLite database files on a remote server and perform queries without downloading the files locally.
6+
7+
### Requirements
8+
9+
- any crate that link SQLite3 to your binary, such as `rusqlite`, `sqlx` or `libsqlite3-sys`
10+
11+
### Usage
12+
13+
1. add the following to your `Cargo.toml`:
14+
15+
```toml
16+
[dependencies]
17+
sqlite-vfs-http = "0.1.0"
18+
```
19+
20+
2. use the library in your code:
21+
22+
```rust
23+
use rusqlite::{Connection, NO_PARAMS};
24+
use sqlite_vfs_http::{register_http_vfs, HTTP_VFS};
25+
26+
27+
// Register the HTTP VFS for sqlite
28+
register_http_vfs();
29+
30+
let base = "https://example.com";
31+
let conn = Connection::open_with_flags_and_vfs(
32+
format!("{base}/0.db"),
33+
OpenFlags::SQLITE_OPEN_READ_WRITE
34+
| OpenFlags::SQLITE_OPEN_CREATE
35+
| OpenFlags::SQLITE_OPEN_NO_MUTEX,
36+
// Use HTTP VFS
37+
HTTP_VFS,
38+
)?;
39+
conn.query_row(
40+
"SELECT count(1) FROM sqlite_master WHERE type = 'table'",
41+
[], |row| row.get::<usize>(0)
42+
).unwrap();
43+
```
44+
45+
### Limitations
46+
47+
- Before uploading to the CDN, the database needs to change the journal mode to `MEMORY`:
48+
49+
```sql
50+
PRAGMA journal_mode = MEMORY;
51+
```
52+
53+
### License
54+
55+
> This project is licensed under the AGPL-3.0 license.

src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
mod buffer;
22
mod conn;
3-
mod http;
43
mod utils;
4+
mod vfs;
55

66
use buffer::LazyBuffer;
77
use conn::Connection;
8-
use http::HttpVfs;
98
use sqlite_vfs::register;
109
use std::sync::{Arc, Once, RwLock};
1110
use utils::AtomicRuntime;
11+
use vfs::HttpVfs;
1212

13-
pub use http::HTTP_VFS;
13+
pub use vfs::HTTP_VFS;
1414

1515
pub fn register_http_vfs() {
1616
const ONCE: Once = Once::new();

src/http.rs renamed to src/vfs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ mod tests {
163163
#[tokio::test]
164164
async fn test_http_vfs() {
165165
init_server(|base| async move {
166-
super::register_http_vfs();
166+
vfs::register_http_vfs();
167167

168168
{
169169
let conn = Connection::open_with_flags_and_vfs(

0 commit comments

Comments
 (0)