How to use the lowdb/adapters/FileAsync function in lowdb

To help you get started, we’ve selected a few lowdb examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github TokenChingy / _api / src / index.js View on Github external
_.forEach(element, (object, key) => {
    // Create new adapter for LowDB to read/write.
    // Encrypt/decrypt corresponding collection file.
    const Adapter = new FileAsync(`${DB_CONFIG.LOCATION}/${key}.json`, Encryption);

    // Use adapter for LowDB instance.
    // Set defaults and write new collection file if none exists.
    // Load collection into memory.
    LowDB(Adapter)
      .then(Collection => {
        Collection.defaults(element)
          .write()
          .then(() => {
            inFileSystem += 1;

            // Generate CRUD API routes for this collection.
            RouteDynamic(Server, Collection);
          })
          .catch(error => {
            throw new Error(error);
github pharindoko / json-serverless / src / server / storage / file.storage.ts View on Github external
async init(): Promise {
    const storageAdapter = new FileAsync(this.initialFilePath);
    return storageAdapter;
  }
}
github zifeo / Croque / src / index.js View on Github external
}
  if (nextNoon.hours() >= 12) {
    if (nextNoon.isoWeekday() === 5) {
      nextNoon = nextNoon.add(3, 'd');
    } else {
      nextNoon = nextNoon.add(1, 'd');
    }
  }
  return nextNoon
    .hours(12)
    .minutes(15)
    .seconds(0)
    .milliseconds(0);
}

low(new FileAsync('db.json')).then(db => {
  db
    .defaults({
      users: {},
      miams: {},
    })
    .write();

  const isProduction = process.env.NODE_ENV === 'production';

  if (isProduction) {
    Raven.config('', {
      release: 'latest',
    }).install();
  }

  const tequilaStrategy = new tequilaPassport.Strategy({
github zifeo / Croque / src / db.js View on Github external
function lowdbFactory(): Promise {
  const file = new FileAsync(config.lowdb.file);
  return low(file).then(db => {
    db.defaults(config.lowdb.defaults).write();
    return injectOps(db);
  });
}
github steelbrain / pundle / packages / pundle-core / src / cache.js View on Github external
`${getStringHash(`${rootDirectory}-${target}-${cacheConfig.cacheKey}`)}.json`,
    )
    await new Promise((resolve, reject) => {
      mkdirp(path.dirname(filePath), err => {
        if (err) {
          reject(err)
        } else resolve()
      })
    })

    if (cacheConfig.reset && (await fs.exists(filePath))) {
      await fs.unlink(filePath)
    }

    const cacheKey = statsToCacheKey(configFilePath ? await fs.stat(configFilePath) : null)
    const fileAdapter = new FileAsync(filePath, {
      defaultValue: {
        cacheKey,
        version,
        files: {},
      },
    })

    const adapter = await lowdb(fileAdapter)
    if (adapter.get('cacheKey').value() !== cacheKey || adapter.get('version').value() !== version) {
      adapter
        .set('files', {})
        .set('cacheKey', cacheKey)
        .set('version', version)
        .value()
      this.write()
    }

lowdb

Tiny local JSON database for Node, Electron and the browser

MIT
Latest version published 11 months ago

Package Health Score

77 / 100
Full package analysis