Download pool/shard005/JavaScript/0031240_database-config.js from Variable-role/sajaniemi_variable_dataset_large: direct link, hf CLI and curl.
- Browser
- Download file 1.36 kB
-
https://huggingface.co/datasets/Variable-role/sajaniemi_variable_dataset_large/resolve/main/pool/shard005/JavaScript/0031240_database-config.js
- Command line
-
hf download hf://datasets/Variable-role/sajaniemi_variable_dataset_large/pool/shard005/JavaScript/0031240_database-config.js
-
curl -L -o 0031240_database-config.js https://huggingface.co/datasets/Variable-role/sajaniemi_variable_dataset_large/resolve/main/pool/shard005/JavaScript/0031240_database-config.js
1.36 kB
| import fs from 'fs' | |
| import loki from 'lokijs' | |
| const init = () => { | |
| const userHome = process.env.APPDATA || process.env.HOME | |
| const projectDbFileName = '.stringerdb' | |
| const dbFile = `${userHome}/${projectDbFileName}` | |
| console.log('Initializing the database in ', dbFile) | |
| if (!fs.existsSync(dbFile)) { | |
| console.log('Database did NOT exist, creating it now') | |
| fs.writeFile(dbFile, '', (err) => { | |
| if (err) { | |
| console.error('Error creating the empty database file', err) | |
| } | |
| }) | |
| while (true) { | |
| if (fs.existsSync(dbFile)) { | |
| console.log('Database file found at', dbFile) | |
| break | |
| } | |
| console.log('Waiting for the blank db file to be created...') | |
| } | |
| } | |
| let db = new loki(dbFile, { | |
| autoload: true, | |
| autoloadCallback: onDbAutoload, | |
| autosave: true, | |
| autosaveInterval: 125, | |
| verbose: process.env.ENV === 'development' | |
| }) | |
| function onDbAutoload() { | |
| console.log('Database loaded!') | |
| initProjectsCollection(db) | |
| } | |
| return db | |
| } | |
| const initProjectsCollection = (db) => { | |
| let projectsCollection = db.getCollection('projects') | |
| if (!projectsCollection) { | |
| console.log('[projects] collection did not exist, creating it now') | |
| projectsCollection = db.addCollection('projects') | |
| } | |
| return projectsCollection | |
| } | |
| export function initDatabase() { | |
| return init() | |
| } | |