feat(desktop): ✨ 实现一些功能
1. 实现了用户阅读画像 2. 实现了全局检索功能
This commit is contained in:
@@ -2,29 +2,34 @@ import 'reflect-metadata'
|
||||
import { DataSource } from 'typeorm'
|
||||
import { app } from 'electron'
|
||||
import path from 'path'
|
||||
import { ReadingReflectionTaskBatch } from '@main/db/entities/ReadingReflectionTaskBatch'
|
||||
import { ReadingReflectionTaskItem } from '@main/db/entities/ReadingReflectionTaskItem'
|
||||
import { ReadingReflectionTaskBatch } from './entities/ReadingReflectionTaskBatch'
|
||||
import { ReadingReflectionTaskItem } from './entities/ReadingReflectionTaskItem'
|
||||
import { ReadingPersona } from './entities/ReadingPersona' // 必须导入
|
||||
|
||||
const dbPath = app.isPackaged
|
||||
? path.join(app.getPath('userData'), 'reflections.db')
|
||||
: path.join(process.cwd(), 'db.sqlite')
|
||||
console.log('--- 数据库存储绝对路径 ---')
|
||||
console.log(dbPath)
|
||||
console.log('-----------------------')
|
||||
|
||||
export const AppDataSource = new DataSource({
|
||||
type: 'better-sqlite3',
|
||||
type: 'better-sqlite3', // better-sqlite3 性能优于 sqlite3
|
||||
database: dbPath,
|
||||
synchronize: true, // 开发环境下自动同步表结构
|
||||
logging: true,
|
||||
entities: [ReadingReflectionTaskBatch, ReadingReflectionTaskItem],
|
||||
migrations: [],
|
||||
subscribers: []
|
||||
synchronize: true,
|
||||
logging: process.env.NODE_ENV === 'development', // 仅开发环境开启日志
|
||||
entities: [
|
||||
ReadingReflectionTaskBatch,
|
||||
ReadingReflectionTaskItem,
|
||||
ReadingPersona // 注册实体
|
||||
]
|
||||
})
|
||||
|
||||
// 初始化方法,在 Electron app.whenReady() 中调用
|
||||
export const initDB = async () => {
|
||||
if (!AppDataSource.isInitialized) {
|
||||
await AppDataSource.initialize()
|
||||
console.log('TypeORM SQLite Data Source has been initialized!')
|
||||
try {
|
||||
await AppDataSource.initialize()
|
||||
console.log('Database initialized successfully at:', dbPath)
|
||||
} catch (err) {
|
||||
console.error('Error during Data Source initialization', err)
|
||||
}
|
||||
}
|
||||
return AppDataSource
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user