Still no work properly...
This commit is contained in:
parent
c237c83917
commit
36ab9d81e5
|
@ -5,7 +5,10 @@ import { open } from 'sqlite'
|
||||||
|
|
||||||
const log = initLog("database")
|
const log = initLog("database")
|
||||||
|
|
||||||
export let sqlite = undefined
|
export let sqlite = await open({
|
||||||
|
filename: 'ddnet.sqlite',
|
||||||
|
driver: sqlite3.cached.Database
|
||||||
|
})
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This initializes both the sqlite db and mongodb.
|
* This initializes both the sqlite db and mongodb.
|
||||||
|
|
|
@ -1,24 +1,31 @@
|
||||||
import Finish from '../../../schemas/Finish-copy.js'
|
import Finish from '../../../schemas/Finish-copy.js'
|
||||||
import initLog from '../log.js'
|
import initLog from '../log.js'
|
||||||
|
import init from '../../database/init.js'
|
||||||
|
import { sqlite } from '../../database/init.js'
|
||||||
|
import dotenv from 'dotenv'
|
||||||
|
|
||||||
|
dotenv.config()
|
||||||
|
init()
|
||||||
|
|
||||||
const log = initLog('DB TEST')
|
const log = initLog('DB TEST')
|
||||||
|
|
||||||
export function main(data) {
|
export function main(data) {
|
||||||
return new Promise(
|
return new Promise(
|
||||||
(resolve, reject) => {
|
async (resolve, reject) => {
|
||||||
const {err, finish} = data
|
const rows = await sqlite.all(`SELECT * FROM race ORDER BY Timestamp LIMIT 5000 OFFSET ${data.offset + 1}`)
|
||||||
|
let finishes = []
|
||||||
Finish.create({
|
rows.map(
|
||||||
map: finish.Map,
|
finish => finishes.push({
|
||||||
time: finish.Time,
|
map: finish.Map,
|
||||||
date: finish.Timestamp === '0000-00-00 00:00:00' ? new Date('January 1, 1970 00:00:00 UTC') : new Date(`${finish.Timestamp}+00:00`),
|
time: finish.Time,
|
||||||
serverLocation: finish.Server ?? '',
|
date: finish.Timestamp === '0000-00-00 00:00:00' ? new Date('January 1, 1970 00:00:00 UTC') : new Date(`${finish.Timestamp}+00:00`),
|
||||||
player: finish.Name
|
serverLocation: finish.Server ?? '',
|
||||||
}).then(() => {
|
player: finish.Name
|
||||||
log(`Added finish ~/~ -> At ${finish.Timestamp} «${finish.Name}» completed «${finish.Map}» in ${finish.Time} s`)
|
})
|
||||||
})
|
)
|
||||||
|
await Finish.insertMany(finishes)
|
||||||
resolve(true)
|
log('Inserted!')
|
||||||
|
resolve()
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
|
@ -1,5 +1,4 @@
|
||||||
import { initWorkers, spread } from '../libs/utils/multithread.js'
|
import { initWorkers, spread } from '../libs/utils/multithread.js'
|
||||||
import { sqlite } from '../libs/database/init.js'
|
|
||||||
import Finish from '../schemas/Finish-copy.js'
|
import Finish from '../schemas/Finish-copy.js'
|
||||||
import initLog from '../libs/utils/log.js'
|
import initLog from '../libs/utils/log.js'
|
||||||
|
|
||||||
|
@ -14,19 +13,10 @@ export default async function() {
|
||||||
|
|
||||||
let offset = -1
|
let offset = -1
|
||||||
while (offset < 10000000) {
|
while (offset < 10000000) {
|
||||||
await sqlite.each(
|
await spread(
|
||||||
`SELECT * FROM race ORDER BY Timestamp LIMIT 5000 OFFSET ${offset + 1}`,
|
'./db.test.js',
|
||||||
[],
|
{
|
||||||
(err, finish) => {
|
offset
|
||||||
spread(
|
|
||||||
'./db.test.js',
|
|
||||||
{
|
|
||||||
err,
|
|
||||||
finish,
|
|
||||||
}
|
|
||||||
).then(
|
|
||||||
result => {}
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
offset += 5000
|
offset += 5000
|
||||||
|
|
Loading…
Reference in New Issue
Block a user