sqlite_vtable_opendal/types.rs
1//! Core types and data structures for the virtual table
2//!
3//! This module defines the fundamental types used throughout the library:
4//! - `FileMetadata`: Represents a file or directory in cloud storage
5//! - `QueryConfig`: Configuration for how queries should be executed
6
7use serde::{Deserialize, Serialize};
8
9/// Represents metadata for a file or directory in cloud storage
10///
11/// This struct contains all the information that can be queried through
12/// the virtual table SQL interface. It's designed to be lightweight by default,
13/// only fetching file contents when explicitly requested.
14///
15/// # Examples
16///
17/// ```
18/// use sqlite_vtable_opendal::types::FileMetadata;
19///
20/// let file = FileMetadata {
21/// name: "document.pdf".to_string(),
22/// path: "/docs/document.pdf".to_string(),
23/// size: 1024000,
24/// last_modified: Some("2024-01-15T10:30:00Z".to_string()),
25/// etag: Some("abc123".to_string()),
26/// is_dir: false,
27/// content_type: Some("application/pdf".to_string()),
28/// content: None, // Not fetched by default
29/// };
30/// ```
31#[derive(Debug, Clone, Serialize, Deserialize)]
32pub struct FileMetadata {
33 /// The name of the file or directory (without path)
34 pub name: String,
35
36 /// The full path of the file or directory
37 pub path: String,
38
39 /// The size of the file in bytes (0 for directories)
40 pub size: u64,
41
42 /// ISO 8601 formatted timestamp of last modification
43 pub last_modified: Option<String>,
44
45 /// ETag or content hash (MD5, SHA256, etc.)
46 pub etag: Option<String>,
47
48 /// Whether this entry is a directory
49 pub is_dir: bool,
50
51 /// MIME type or file extension
52 pub content_type: Option<String>,
53
54 /// Actual file content (only populated when explicitly requested)
55 /// This is None by default to avoid unnecessary data transfer
56 pub content: Option<Vec<u8>>,
57}
58
59/// Configuration for querying file metadata
60///
61/// This struct controls how the virtual table fetches data from cloud storage.
62/// Users can configure whether to fetch content, recurse into directories,
63/// and implement pagination.
64///
65/// # Examples
66///
67/// ```
68/// use sqlite_vtable_opendal::types::QueryConfig;
69///
70/// // Metadata-only query (default)
71/// let config = QueryConfig::default();
72///
73/// // Fetch file contents as well
74/// let config = QueryConfig {
75/// fetch_content: true,
76/// ..Default::default()
77/// };
78///
79/// // Recursive listing with pagination
80/// let config = QueryConfig {
81/// root_path: "/documents".to_string(),
82/// recursive: true,
83/// limit: Some(100),
84/// offset: 0,
85/// ..Default::default()
86/// };
87/// ```
88#[derive(Debug, Clone)]
89pub struct QueryConfig {
90 /// The root path to start listing from
91 pub root_path: String,
92
93 /// Whether to fetch file contents (default: false for metadata-only queries)
94 pub fetch_content: bool,
95
96 /// Whether to recursively list subdirectories
97 pub recursive: bool,
98
99 /// Maximum number of results to return (for pagination)
100 pub limit: Option<usize>,
101
102 /// Offset for pagination
103 pub offset: usize,
104}
105
106impl Default for QueryConfig {
107 fn default() -> Self {
108 Self {
109 root_path: "/".to_string(),
110 fetch_content: false,
111 recursive: false,
112 limit: None,
113 offset: 0,
114 }
115 }
116}
117
118/// Column indices for the virtual table schema
119///
120/// These constants make it easier to reference columns by name
121/// rather than magic numbers in the code.
122pub mod columns {
123 pub const PATH: i32 = 0;
124 pub const SIZE: i32 = 1;
125 pub const LAST_MODIFIED: i32 = 2;
126 pub const ETAG: i32 = 3;
127 pub const IS_DIR: i32 = 4;
128 pub const CONTENT_TYPE: i32 = 5;
129 pub const NAME: i32 = 6;
130 pub const CONTENT: i32 = 7;
131}