-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfunctional-test.ts
67 lines (62 loc) · 1.57 KB
/
functional-test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import { startTimer } from '@beenotung/tslib/node'
import {
countRows,
createDB,
} from '../src'
import { makePredefinedInsertRowFn, makePredefinedSelectRowFn } from './functional-helpers'
import { dbfile, iterateSamples, sampleCount } from './sample'
export function exportToSqlite() {
const timer = startTimer('init db')
const db = createDB({ file: dbfile, mode: 'overwrite' })
// const insertRowFn = makeGeneralInsertRowFn(db)
const insertRowFn = makePredefinedInsertRowFn(db)
const n = sampleCount
let i = 0
timer.next('import data')
timer.setProgress({ totalTick: n, estimateTime: true, sampleOver: n / 100 })
for (const { key, value } of iterateSamples()) {
i++
timer.tick()
if (i > n) {
break
}
if (key === 'last-thread') {
continue
}
if (key.startsWith('thread-')) {
insertRowFn(value)
continue
}
throw new Error('unknown data type')
}
timer.end()
}
export function loadFromSqlite() {
const timer = startTimer('init')
const db = createDB({ file: dbfile })
const countRowsFn = () => countRows(db, 'thread')
const selectRowFn = makePredefinedSelectRowFn(db)
timer.next('load data')
const n = countRowsFn()
timer.setProgress({
totalTick: n,
estimateTime: true,
sampleOver: n / 100,
})
for (let i = 0; i < n; i++) {
const thread = selectRowFn(i)
if (!thread) {
throw new Error('failed to load thread')
}
timer.tick()
}
timer.end()
db.close()
}
export function test() {
exportToSqlite()
loadFromSqlite()
}
if (process.argv[1] === __filename) {
test()
}