File tree Expand file tree Collapse file tree 3 files changed +59
-4
lines changed Expand file tree Collapse file tree 3 files changed +59
-4
lines changed Original file line number Diff line number Diff line change
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.
Original file line number Diff line number Diff line change 1
1
mod buffer;
2
2
mod conn;
3
- mod http;
4
3
mod utils;
4
+ mod vfs;
5
5
6
6
use buffer:: LazyBuffer ;
7
7
use conn:: Connection ;
8
- use http:: HttpVfs ;
9
8
use sqlite_vfs:: register;
10
9
use std:: sync:: { Arc , Once , RwLock } ;
11
10
use utils:: AtomicRuntime ;
11
+ use vfs:: HttpVfs ;
12
12
13
- pub use http :: HTTP_VFS ;
13
+ pub use vfs :: HTTP_VFS ;
14
14
15
15
pub fn register_http_vfs ( ) {
16
16
const ONCE : Once = Once :: new ( ) ;
Original file line number Diff line number Diff line change @@ -163,7 +163,7 @@ mod tests {
163
163
#[ tokio:: test]
164
164
async fn test_http_vfs ( ) {
165
165
init_server ( |base| async move {
166
- super :: register_http_vfs ( ) ;
166
+ vfs :: register_http_vfs ( ) ;
167
167
168
168
{
169
169
let conn = Connection :: open_with_flags_and_vfs (
You can’t perform that action at this time.
0 commit comments