Skip to content

Commit 56d4a34

Browse files
committed
refactor: Delete sqlite by clearing tables instead of
erasing files
1 parent bd3e35b commit 56d4a34

File tree

1 file changed

+9
-16
lines changed
  • packages/neuron-wallet/src/database/chain

1 file changed

+9
-16
lines changed
Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,14 @@
1-
import fs from 'fs'
2-
import path from 'path'
3-
import env from 'env'
1+
import { getConnection } from 'typeorm'
2+
import InputEntity from './entities/input'
3+
import OutputEntity from './entities/output'
4+
import TransactionEntity from './entities/transaction'
5+
import SyncInfoEntity from './entities/sync-info'
46

57
// Clean local sqlite storage
68
export default class ChainCleaner {
7-
// Delete all sqlite files under cells folder.
8-
// It doesn't handle error or throw exception when deleting fails.
9-
public static clean() {
10-
const folder = path.join(env.fileBasePath, 'cells')
11-
fs.readdir(folder, (err, files) => {
12-
if (err) {
13-
return
14-
}
15-
16-
for (const file of files.filter(f => { return path.extname(f) === '.sqlite' })) {
17-
fs.unlink(path.join(folder, file), () => {})
18-
}
19-
})
9+
public static async clean() {
10+
for (const entity of [InputEntity, OutputEntity, TransactionEntity, SyncInfoEntity]) {
11+
await getConnection().getRepository(entity).clear()
12+
}
2013
}
2114
}

0 commit comments

Comments
 (0)