How to use the lowdb/adapters/FileSync 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 loomnetwork / plasma-cli / src / modules / db.ts View on Github external
constructor(ethereum: String, dappchain: String, plasmaAddress: String, privateKey: String) {
    // If we're on node.js
    let adapter
    if (typeof localStorage === 'undefined' || localStorage === null) {
      const low = require('lowdb')
      adapter = new FileSync(`db/db_${privateKey}.json`)
    } else {
      adapter = new LocalStorage('db')
    }
    this.db = low(adapter)
    // Initialize the database
    this.db
      .defaults({
        ethereum: ethereum,
        dappchain: dappchain,
        plasma: plasmaAddress,
        privatekey: privateKey,
        coins: []
      })
      .write()
    console.log('Initialized database', this.db.value())
  }
github emqx / MQTTX / src / database / index.ts View on Github external
public constructor() {
    const adapter: Lowdb.AdapterSync = new FileSync(path.join(STORE_PATH, '/db.json'))
    this.db = Lowdb(adapter)
    // Use lodash-id must use insert methods
    this.db._.mixin(LodashID)
    if (!this.db.has('windowSize').value()) {
      this.db
        .set('windowSize', {
          width: 1025,
          height: 749,
        })
        .write()
    }
    if (!this.db.has('settings').value()) {
      this.db
        .set('settings', {
          autoCheck: true,
          currentLang: 'en',
github ArkEcosystem / core / packages / core-webhooks / src / database.ts View on Github external
public make(): void {
        const adapterFile: string = `${process.env.CORE_PATH_CACHE}/webhooks.json`;

        if (!existsSync(adapterFile)) {
            ensureFileSync(adapterFile);
        }

        this.database = lowdb(new FileSync(adapterFile));
        this.database.defaults({ webhooks: [] }).write();
    }
github oberonamsterdam / jsonapi-mock / src / constants / Globals.js View on Github external
NESTEDROUTEPREFIX: 'route:',
        CONTENTTYPE: 'application/vnd.api+json',
        ACCEPT: 'application/vnd.api+json',
    };
    process.env = {
        ...process.env,
        ...obj
    };
}

export const globalContentType = process.env.CONTENTTYPE;
export const globalAccept = process.env.ACCEPT;
export const nestedRoutePrefix = process.env.NESTEDROUTEPREFIX;
export const json = JSON.parse(fs.readFileSync(process.env.WATCHFILE, 'utf8'));
export const port = process.env.PORT;
export const adapter = new FileSync(process.env.WATCHFILE);
export const db = low(adapter);
export const mainRoutes = [];
recursiveThroughRoutes(json, null, []);
github basarat / cypress-guide / webapp / src / server / server.ts View on Github external
import express from 'express';
import cors from 'cors';
import low from 'lowdb';
import uuid from 'uuid/v4';
import FileSync from 'lowdb/adapters/FileSync';
import { TodoItem, API } from '../common/types';

/** 
 * Setup db 
 */
type DBSchema = {
  items: TodoItem[]
}
const adapter = new FileSync('db.json', {
  defaultValue: {
    items: []
  }
});
const db = low(adapter);

/** 
 * API server 
 */
const app = express();
const api = express.Router();

api.use(cors(), express.json());
api.get(API.getAll.endpoint, (_, res) => {
  res.send({ todos: db.get('items') });
});
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 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 animify / colorbook / server / database / Db.js View on Github external
loadShotsDb() {
        const adapter = new FileSync('./server/database/projects.json');
        const db = low(adapter);

        return db;
    }
}

lowdb

Tiny local JSON database for Node, Electron and the browser

MIT
Latest version published 12 months ago

Package Health Score

80 / 100
Full package analysis