Skip to content

Commit 55465cf

Browse files
Copilothuangyiirene
andcommitted
Review and improve FileSystem driver: Add initialData support, utility methods, Chinese docs, and enhanced error handling
Co-authored-by: huangyiirene <[email protected]>
1 parent 3afa731 commit 55465cf

File tree

6 files changed

+684
-4
lines changed

6 files changed

+684
-4
lines changed

packages/drivers/fs/CHANGELOG.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,24 @@
22

33
All notable changes to the @objectql/driver-fs package will be documented in this file.
44

5+
## [0.1.1] - 2024-01-16
6+
7+
### Added
8+
- `initialData` configuration option to pre-populate data on initialization
9+
- `clear(objectName)` method to clear all data for a specific object
10+
- `clearAll()` method to clear all data from all objects
11+
- `invalidateCache(objectName)` method to force cache reload
12+
- `getCacheSize()` method to get the number of cached objects
13+
- Chinese documentation (README.zh-CN.md)
14+
- Better error handling for invalid JSON files
15+
- Support for empty JSON files
16+
17+
### Improved
18+
- Enhanced JSON parse error messages with more detailed information
19+
- Better documentation with examples for all new features
20+
- Added 7 new test cases (total: 36 tests)
21+
- TypeScript configuration for proper workspace resolution
22+
523
## [0.1.0] - 2024-01-16
624

725
### Added

packages/drivers/fs/README.md

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
File System Driver for ObjectQL - JSON file-based persistent storage with one file per table.
44

5+
> **中文文档**: [README.zh-CN.md](./README.zh-CN.md)
6+
57
## Features
68

79
**Persistent Storage** - Data survives process restarts
@@ -80,6 +82,9 @@ interface FileSystemDriverConfig {
8082

8183
/** Enable strict mode (throw on missing objects) (default: false) */
8284
strictMode?: boolean;
85+
86+
/** Initial data to populate the store (optional) */
87+
initialData?: Record<string, any[]>;
8388
}
8489
```
8590

@@ -90,7 +95,12 @@ const driver = new FileSystemDriver({
9095
dataDir: './data',
9196
prettyPrint: true, // Human-readable JSON
9297
enableBackup: true, // Create .bak files
93-
strictMode: false // Graceful handling of missing records
98+
strictMode: false, // Graceful handling of missing records
99+
initialData: { // Pre-populate with initial data
100+
users: [
101+
{ id: 'admin', name: 'Admin User', role: 'admin' }
102+
]
103+
}
94104
});
95105
```
96106

@@ -297,6 +307,24 @@ await products.create({
297307

298308
### Loading Initial Data
299309

310+
**Method 1: Provide in configuration**
311+
312+
```typescript
313+
const driver = new FileSystemDriver({
314+
dataDir: './data',
315+
initialData: {
316+
users: [
317+
{ id: 'admin-001', name: 'Admin User', role: 'admin' }
318+
],
319+
settings: [
320+
{ key: 'theme', value: 'dark' }
321+
]
322+
}
323+
});
324+
```
325+
326+
**Method 2: Pre-create JSON files**
327+
300328
You can pre-populate JSON files:
301329

302330
```json
@@ -329,6 +357,22 @@ const testDriver = new FileSystemDriver({
329357
});
330358
```
331359

360+
### Utility Methods
361+
362+
```typescript
363+
// Clear all data for a specific object
364+
await driver.clear('users');
365+
366+
// Clear all data for all objects
367+
await driver.clearAll();
368+
369+
// Invalidate cache for an object
370+
driver.invalidateCache('users');
371+
372+
// Get cache size
373+
const size = driver.getCacheSize();
374+
```
375+
332376
## Comparison with Other Drivers
333377

334378
| Feature | FileSystem | Memory | SQL | MongoDB |

0 commit comments

Comments
 (0)