Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jan 16, 2026

Implements a file-based persistence driver where each ObjectQL object type is stored as a separate JSON file (e.g., users.json, projects.json).

Implementation

New Package: @objectql/driver-fs

  • Storage model: Array of records per file with atomic writes (temp file + rename)
  • Backup strategy: Auto-generated .bak files on write operations
  • Cache layer: In-memory cache for reads, flush on disconnect
  • Query support: Full filter/sort/pagination via in-memory evaluation
  • ID generation: Timestamp + counter (configurable via data.id field)
  • Initial data support: Pre-populate data on initialization via initialData config
  • Utility methods: clear(), clearAll(), invalidateCache(), getCacheSize()

Usage

import { FileSystemDriver } from '@objectql/driver-fs';

const driver = new FileSystemDriver({
    dataDir: './data',
    prettyPrint: true,    // Human-readable JSON
    enableBackup: true,   // Create .bak files
    initialData: {        // Optional: pre-populate data
        users: [
            { id: 'admin', name: 'Admin User', role: 'admin' }
        ]
    }
});

const app = new ObjectQL({
    datasources: { default: driver }
});

File Format

// data/projects.json
[
  {
    "id": "PROJ-001",
    "name": "Website Redesign",
    "status": "in_progress",
    "created_at": "2024-01-16T12:00:00.000Z",
    "updated_at": "2024-01-16T12:00:00.000Z"
  }
]

Test Coverage

  • 36 tests covering CRUD, bulk operations, query filters, edge cases, and new features
  • Working example in examples/drivers/fs-demo
  • Zero security vulnerabilities (CodeQL scan)

Documentation

  • Complete English documentation (README.md)
  • Chinese documentation (README.zh-CN.md)
  • Comprehensive API examples and usage patterns

Limitations

Not recommended for:

  • Datasets > 10k records per object (full file rewrite on update)
  • Multi-process concurrent writes (no external locking)
  • Production high-traffic scenarios (use SQL/MongoDB drivers)
Original prompt

写一个基于文件系统的启动,每张表一个json文件


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

});

test('should handle _id field', async () => {
const result = await driver.create('docs', {
Copilot AI changed the title [WIP] Add file system based startup with JSON files for each table Add FileSystem driver with one JSON file per table Jan 16, 2026
Copilot AI requested a review from huangyiirene January 16, 2026 12:19
@huangyiirene huangyiirene requested review from Copilot and removed request for huangyiirene January 16, 2026 12:51
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces a new file-based persistence driver (@objectql/driver-fs) for ObjectQL that stores each object type as a separate JSON file, providing a lightweight alternative to traditional database drivers for development and small-scale applications.

Changes:

  • Implements a complete FileSystem driver with atomic write operations, backup support, and in-memory caching
  • Adds comprehensive test coverage (29 test cases) for CRUD operations, query filters, bulk operations, and edge cases
  • Includes a working example demonstrating real-world usage with projects management

Reviewed changes

Copilot reviewed 12 out of 13 changed files in this pull request and generated no comments.

Show a summary per file
File Description
packages/drivers/fs/src/index.ts Core driver implementation with full Driver interface support and query operations
packages/drivers/fs/test/index.test.ts Comprehensive test suite covering CRUD, queries, bulk operations, and file system behavior
packages/drivers/fs/package.json Package configuration with workspace dependencies
packages/drivers/fs/tsconfig.json TypeScript configuration for the driver package
packages/drivers/fs/jest.config.js Jest test configuration with module mapping
packages/drivers/fs/README.md Complete documentation with examples, API reference, and usage guidelines
packages/drivers/fs/CHANGELOG.md Initial release changelog
examples/drivers/fs-demo/src/index.ts Demo application showing practical usage patterns
examples/drivers/fs-demo/package.json Demo package configuration
examples/drivers/fs-demo/tsconfig.json TypeScript configuration for demo
examples/drivers/fs-demo/README.md Demo documentation and usage instructions
examples/drivers/fs-demo/.gitignore Excludes runtime-generated data directory
Files not reviewed (1)
  • pnpm-lock.yaml: Language not supported

@huangyiirene
Copy link
Contributor

@copilot 审查代码并修复,更新文档

…y methods, Chinese docs, and enhanced error handling

Co-authored-by: huangyiirene <[email protected]>
Copy link
Contributor Author

Copilot AI commented Jan 16, 2026

@copilot 审查代码并修复,更新文档

代码已审查并改进完成(commit: 55465cf):

新增功能:

  • initialData 配置选项 - 初始化时预加载数据
  • clear(objectName) - 清除特定对象的所有数据
  • clearAll() - 清除所有对象的数据
  • invalidateCache() - 强制重新加载缓存
  • getCacheSize() - 获取缓存大小

改进:

  • ✅ 增强的错误处理(处理无效 JSON 和空文件)
  • ✅ 新增中文文档(README.zh-CN.md)
  • ✅ 修复 TypeScript 编译配置
  • ✅ 新增 7 个测试用例(共 36 个测试,全部通过)
  • ✅ 更新了 CHANGELOG 和文档

所有测试通过 ✓

@huangyiirene huangyiirene marked this pull request as ready for review January 16, 2026 13:26
@huangyiirene huangyiirene merged commit 0db5577 into main Jan 16, 2026
8 checks passed
@huangyiirene huangyiirene deleted the copilot/add-file-system-startup branch January 16, 2026 13:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants