https://github.com/zhujiaming/node-sqlite-updater
nodejs-sqlite3 数据库版本管理与升级
https://github.com/zhujiaming/node-sqlite-updater
database nodejs sqlite3 typeorm typescript
Last synced: 11 months ago
JSON representation
nodejs-sqlite3 数据库版本管理与升级
- Host: GitHub
- URL: https://github.com/zhujiaming/node-sqlite-updater
- Owner: zhujiaming
- Created: 2021-07-08T11:07:08.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2021-07-19T01:35:56.000Z (over 4 years ago)
- Last Synced: 2024-04-24T07:13:17.211Z (almost 2 years ago)
- Topics: database, nodejs, sqlite3, typeorm, typescript
- Language: TypeScript
- Homepage:
- Size: 6.84 KB
- Stars: 3
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
### node-sqlite-updater
> 基于nodejs的客户端或服务端使用sqlite3时,对数据库文件进行版本管理升级的辅助工具库,对Electron+sqlite3+typeorm应用友好。
### 接入
```powershell
npm i node-sqlite-updater
```
### 使用
```javascript
const dbFile = path.join("",'test.db')//目标数据库文件
const DB_VERSION = 1 //当前应用对应的当前数据库文件版本,每次+1会触发升级,默认从1开始。
const dbupgradeImpl = new DbUpgradeImpl() //数据库升级的具体内容是抽象接口,交给业务实现,参考./example/upgrade-impl.ts。
function beforInitDB() {
let dbUpdater = new DbUpdater({
vercode: 1,
database: dbFile,
logging: true, //是否打印日志
upgradeImpl: dbupgradeImpl
});
dbUpdater
.init()
.then(res => {
console.log('db update res',res)
initDB() //成功后继续正常db init
}).catch(e => {
console.error('db update err', e)
});
}
function initDB(){
// custom init db
}
```