添加对G5数据库的支持,实现双数据库同时写入功能 重构数据库配置和连接管理,支持主库和G5库的独立配置 优化数据同步逻辑,添加缺失字段并保持现有字段不变 改进数据过滤和事务处理,增强错误处理和日志记录
Temporary Project Management
This is a local Node.js project for fetching hotel data and loop addresses, managing them in a local SQLite database.
Prerequisites
- Node.js (v14+ recommended)
- npm
Installation
- Clone or navigate to the project directory.
- Install dependencies:
npm install - Copy
.env.exampleto.envand configure:(On Windows:cp .env.example .envcopy .env.example .env)
Configuration (.env)
PORT: App port (default 3000)DB_FILE: Path to SQLite database file (default./local.db)ENABLED_HOTEL_IDS: Comma-separated list of Hotel IDs to fetch loops for (e.g.,1085,2144)API_BASE_URL: Base URL for external APIs
Usage
- Development Mode (with hot reload):
npm run dev - Start Production:
npm start - Run Tests:
npm test
Project Structure
src/config: Configuration loadingsrc/db: Database connection and schema initializationsrc/services: Business logic for fetching and saving datasrc/utils: Helpers (Logger, HTTP client with retry/delay)src/scripts: Main entry point
Troubleshooting
- Database Locks: If you encounter
SQLITE_BUSY, ensure no other process (like a DB viewer) has the file open. The app handles some concurrency but file locks can block it. - API Timeouts: If the API is slow, the app is configured with a 100s timeout and 2 retries. Check your network connection.
- Logs: Check
logs/directory for daily application logs and error snapshots.