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