2021-06-17 03:16:52 +00:00
|
|
|
import Datastore from 'nedb-promises'
|
2021-06-09 00:33:42 +00:00
|
|
|
|
|
|
|
// Initialize all datastores and export their references
|
|
|
|
// Current dbs:
|
|
|
|
// `settings.db`
|
|
|
|
// `profiles.db`
|
|
|
|
// `playlists.db`
|
|
|
|
// `history.db`
|
|
|
|
|
2021-06-17 03:16:52 +00:00
|
|
|
let buildFileName = null
|
|
|
|
|
2021-06-09 00:33:42 +00:00
|
|
|
// Check if using Electron
|
|
|
|
const usingElectron = window?.process?.type === 'renderer'
|
|
|
|
if (usingElectron) {
|
|
|
|
const { ipcRenderer } = require('electron')
|
2021-06-17 03:16:52 +00:00
|
|
|
const userDataPath = ipcRenderer.sendSync('getUserDataPathSync')
|
|
|
|
buildFileName = (dbName) => userDataPath + '/' + dbName + '.db'
|
|
|
|
} else {
|
|
|
|
buildFileName = (dbName) => dbName + '.db'
|
2021-06-09 00:33:42 +00:00
|
|
|
}
|
|
|
|
|
2021-06-17 03:16:52 +00:00
|
|
|
const settingsDb = Datastore.create({
|
2021-06-09 00:33:42 +00:00
|
|
|
filename: buildFileName('settings'),
|
|
|
|
autoload: true
|
|
|
|
})
|
|
|
|
|
2021-06-17 03:16:52 +00:00
|
|
|
const playlistsDb = Datastore.create({
|
2021-06-09 00:33:42 +00:00
|
|
|
filename: buildFileName('playlists'),
|
|
|
|
autoload: true
|
|
|
|
})
|
|
|
|
|
2021-06-17 03:16:52 +00:00
|
|
|
const profilesDb = Datastore.create({
|
2021-06-09 00:33:42 +00:00
|
|
|
filename: buildFileName('profiles'),
|
|
|
|
autoload: true
|
|
|
|
})
|
|
|
|
|
2021-06-17 03:16:52 +00:00
|
|
|
const historyDb = Datastore.create({
|
2021-06-09 00:33:42 +00:00
|
|
|
filename: buildFileName('history'),
|
|
|
|
autoload: true
|
|
|
|
})
|
|
|
|
|
|
|
|
export {
|
|
|
|
settingsDb,
|
|
|
|
profilesDb,
|
|
|
|
playlistsDb,
|
|
|
|
historyDb
|
|
|
|
}
|