Skip to content

Commit 99b0ad6

Browse files
Copilothotlong
andcommitted
Add file storage mode option and comprehensive English README
Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
1 parent 6fb1777 commit 99b0ad6

10 files changed

Lines changed: 1313 additions & 277 deletions

File tree

6.46 KB
Binary file not shown.
6.44 KB
Binary file not shown.
6.45 KB
Binary file not shown.

examples/drivers/excel-demo/src/index.ts

Lines changed: 83 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,73 @@
11
/**
22
* Excel Driver Demo
33
*
4-
* This example demonstrates the basic usage of the Excel Driver for ObjectQL.
5-
* It creates, queries, updates, and deletes records in an Excel file.
4+
* This example demonstrates both storage modes of the Excel Driver for ObjectQL:
5+
* 1. Single-file mode (default): All data in one Excel file
6+
* 2. File-per-object mode: Each object type in its own file
67
*/
78

89
import { ExcelDriver } from '@objectql/driver-excel';
910
import * as path from 'path';
1011

11-
async function main() {
12-
console.log('🚀 Excel Driver Demo\n');
12+
async function demoFilePerObjectMode() {
13+
console.log('=' .repeat(60));
14+
console.log('📂 FILE-PER-OBJECT MODE DEMO');
15+
console.log('=' .repeat(60) + '\n');
16+
17+
const dataDir = path.join(__dirname, '../data/file-per-object');
18+
console.log(`📁 Using directory: ${dataDir}\n`);
19+
20+
const driver = await ExcelDriver.create({
21+
filePath: dataDir,
22+
fileStorageMode: 'file-per-object',
23+
createIfMissing: true,
24+
autoSave: true
25+
});
26+
27+
console.log('📝 Creating data in separate files...');
28+
29+
// Each object type will be stored in its own file
30+
await driver.create('customers', {
31+
name: 'ACME Corp',
32+
email: 'contact@acme.com',
33+
industry: 'Technology'
34+
});
35+
console.log('✓ Created customer (saved to customers.xlsx)');
36+
37+
await driver.create('invoices', {
38+
number: 'INV-001',
39+
amount: 5000.00,
40+
status: 'paid'
41+
});
42+
console.log('✓ Created invoice (saved to invoices.xlsx)');
43+
44+
await driver.create('tasks', {
45+
title: 'Review proposal',
46+
priority: 'high',
47+
status: 'in-progress'
48+
});
49+
console.log('✓ Created task (saved to tasks.xlsx)');
50+
51+
console.log('\n📊 Summary:');
52+
console.log(' - Each object type has its own Excel file');
53+
console.log(' - Better for large datasets or independent objects');
54+
console.log(' - Files: customers.xlsx, invoices.xlsx, tasks.xlsx\n');
55+
56+
await driver.disconnect();
57+
}
58+
59+
async function demoSingleFileMode() {
60+
console.log('=' .repeat(60));
61+
console.log('📄 SINGLE-FILE MODE DEMO');
62+
console.log('=' .repeat(60) + '\n');
1363

1464
// Initialize the Excel driver
1565
const dataPath = path.join(__dirname, '../data/demo.xlsx');
1666
console.log(`📁 Using Excel file: ${dataPath}\n`);
1767

1868
const driver = await ExcelDriver.create({
1969
filePath: dataPath,
70+
fileStorageMode: 'single-file', // Default mode (can be omitted)
2071
createIfMissing: true,
2172
autoSave: true
2273
});
@@ -186,15 +237,41 @@ async function main() {
186237
const finalProducts = await driver.find('products');
187238
console.log(`✓ Total products in Excel: ${finalProducts.length}`);
188239

240+
console.log('\n📊 Summary:');
241+
console.log(' - All object types in one Excel file');
242+
console.log(' - Easy to manage (single file)');
243+
console.log(' - Best for related data sets');
244+
189245
// Clean up
190246
await driver.disconnect();
191247

192-
console.log('\n✅ Demo completed successfully!');
248+
console.log('\n✅ Single-file mode demo completed!');
193249
console.log(`📁 Check the Excel file at: ${dataPath}\n`);
194250
}
195251

252+
async function main() {
253+
console.log('\n🚀 Excel Driver Demo - Storage Modes Comparison\n');
254+
255+
try {
256+
// Demo both storage modes
257+
await demoFilePerObjectMode();
258+
await demoSingleFileMode();
259+
260+
console.log('=' .repeat(60));
261+
console.log('✅ ALL DEMOS COMPLETED SUCCESSFULLY!');
262+
console.log('=' .repeat(60));
263+
console.log('\nYou can now:');
264+
console.log(' 1. Open data/demo.xlsx to see single-file mode results');
265+
console.log(' 2. Open data/file-per-object/*.xlsx to see file-per-object results');
266+
console.log('\n');
267+
} catch (error) {
268+
console.error('\n❌ Error:', error);
269+
process.exit(1);
270+
}
271+
}
272+
196273
// Run the demo
197274
main().catch(error => {
198-
console.error('❌ Error:', error.message);
275+
console.error('❌ Fatal error:', error.message);
199276
process.exit(1);
200277
});

packages/drivers/excel/CHANGELOG.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,23 @@
11
# @objectql/driver-excel
22

3+
## 0.2.0 - 2024-01-16
4+
5+
### Added
6+
7+
- **File Storage Modes**: New `fileStorageMode` configuration option
8+
- `single-file` mode: All object types in one Excel file (default, existing behavior)
9+
- `file-per-object` mode: Each object type in a separate Excel file
10+
- Complete English documentation in README
11+
- Additional tests for file-per-object mode (39 total tests now)
12+
- Examples for both storage modes
13+
14+
### Improved
15+
16+
- Better documentation with comprehensive API reference
17+
- Usage examples for common scenarios
18+
- Performance benchmarks and optimization tips
19+
- Detailed error handling guide
20+
321
## 0.1.0 - 2024-01-16
422

523
### Added

0 commit comments

Comments
 (0)