How to use the lowdb 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 dstack-group / Butterfly / user-manager / buttercli / src / database / LocalDb.ts View on Github external
constructor(path: string) {

    // TODO: Maybe this check can be improved
    if (path.length === 0) {
      throw Error('Path cannot be empty!');
    }

    const file = new FileSync(path);
    this.db = lowDb(file);

    this.init();
  }
github lannister-capital / lannister-app / src / db.js View on Github external
import low from 'lowdb'
import LocalStorage from 'lowdb/adapters/LocalStorage'
import shortid from 'shortid'
import currencies from './data/currencies'

const adapter = new LocalStorage('db')
const db = low(adapter)

// Example default values
db.defaults({
  holdings: [
    {
      id: shortid.generate(),
      name: 'Example',
      value: 20000.0,
      hex_color: '#ffbf00',
      currency_code: 'EUR'
    },
    {
      id: shortid.generate(),
      name: 'Bank account',
      value: 50000.0,
      hex_color: '#A52A2A',
github mrdulin / apollo-server-express-starter / src / subscription / demo-3 / db.ts View on Github external
mkdirp(path.resolve(__dirname, dir), err => {
      if (err) {
        logger.error(err);
        reject(err);
        return;
      }

      let source: string = options.source;
      if (cluster.isWorker) {
        source = path.resolve(__dirname, `${dir}/lowdb-${cluster.worker.id}.json`);
      } else if (cluster.isMaster) {
        source = path.resolve(__dirname, `${dir}/lowdb.json`);
      }
      const adapter = new FileSync(source);
      const lowdb = low(adapter);

      const authorId1 = shortid.generate();
      const authorId2 = shortid.generate();

      lowdb.defaults({ users: [], books: [] }).write();

      lowdb.set('users', [{ id: authorId1, name: casual.name }, { id: authorId2, name: casual.name }]).write();
      lowdb
        .set('books', [
          { id: shortid.generate(), title: casual.title, authorId: authorId1 },
          { id: shortid.generate(), title: casual.title, authorId: authorId2 }
        ])
        .write();

      resolve({ lowdb, authorId1, authorId2 });
    });
github gsuitedevs / md2googleslides / src / auth.ts View on Github external
private initDbSync(filePath: string): lowdb.LowdbSync {
        let adapter: lowdb.AdapterSync;
        if (filePath) {
            const parentDir = path.dirname(filePath);
            mkdirp.sync(parentDir);
            adapter = new FileSync(filePath);
        } else {
            adapter = new Memory('');
        }
        return lowdb(adapter);
    }
}
github JimmyLv / nobackend.website / src / angular / features / note / note.js View on Github external
vm.$onInit = () => {
      var meta = configService.config.meta;

      vm.selectedCategory = $routeParams.category || meta.active;

      const db = low('db', {storage: localStorage});
      db.object = vm.index;

      vm.selectedPostsByCategory = db('categories').find({name: vm.selectedCategory}).posts;

      vm.isIndex = vm.postContent ? false : true;
      vm.newestPosts = vm.index.paginator.slice(0, configService.config.paginate);
      vm.selectedTagsWithPosts = db('tags').filter(tag => meta.tags.indexOf(tag.name) > -1);

      vm.showNav = _isMobile() ? false : true;
      vm.showToc = false;

      vm.toggleNav = () => {
        vm.showNav = !vm.showNav;
        vm.showToc = !vm.showToc;
      };
github getgridea / gridea / src / server / model.ts View on Github external
private initDataStore(): void {
    const settingAdapter = new FileSync(path.join(this.appDir, 'config/setting.json'))
    const setting = low(settingAdapter)
    this.$setting = setting

    const postsAdapter = new FileSync(path.join(this.appDir, 'config/posts.json'))
    const posts = low(postsAdapter)
    this.$posts = posts

    const themeAdapter = new FileSync(path.join(this.appDir, 'config/theme.json'))
    const theme = low(themeAdapter)
    this.$theme = theme
  }
}
github Ice-Hazymoon / MikuTools / plugins / db.js View on Github external
import low from 'lowdb';
import LocalStorage from 'lowdb/adapters/LocalStorage';
import Vue from 'vue';
const adapter = new LocalStorage('mikudb');
const db = low(adapter);

db.defaults({
    id: '',
    noticeId: false,
    tool: {
        star_history: {}
    }
}).write();

Vue.prototype.$db = db;

export default db;

lowdb

Tiny local JSON database for Node, Electron and the browser

MIT
Latest version published 4 months ago

Package Health Score

87 / 100
Full package analysis