How to use lowdb - 10 common examples

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 vuejs / vue-apollo / packages / test-ssr / apollo-server / utils / db.js View on Github external
import Lowdb from 'lowdb'
// import FileSync from 'lowdb/adapters/FileSync'
import Memory from 'lowdb/adapters/Memory'
import mkdirp from 'mkdirp'
import { resolve } from 'path'

mkdirp(resolve(__dirname, '../../live'))

// export const db = new Lowdb(new FileSync(resolve(__dirname, '../../live/db.json')))
export const db = new Lowdb(new Memory())

// Seed an empty DB
db.defaults({
  messages: [
    {
      id: 'a',
      text: 'Message 1',
    },
    {
      id: 'b',
      text: 'Message 2',
    },
    {
      id: 'c',
      text: 'Message 3',
    },
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 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 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 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 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 d2-projects / d2-admin-start-kit / src / libs / db.js View on Github external
import low from 'lowdb'
import LocalStorage from 'lowdb/adapters/LocalStorage'
import { version } from '../../package'

const adapter = new LocalStorage(`d2admin-${version}`)
const db = low(adapter)

// 初始化数据库
db.defaults({
  themeActiveName: [],
  pageOpenedList: [],
  userInfo: [],
  isMenuAsideCollapse: [],
  database: [],
  databasePublic: {}
}).write()

export default db
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 typicode / json-server / src / router.js View on Github external
var express = require('express')
var methodOverride = require('method-override')
var bodyParser = require('body-parser')
var _ = require('underscore')
var low = require('lowdb')
var utils = require('./utils')

low.mixin(require('underscore-db'))
low.mixin(require('underscore.inflections'))
low.mixin({ createId: utils.createId })

module.exports = function(source) {
  // Create router
  var router = express.Router()

  // Add middlewares
  router.use(bodyParser.json({limit: '10mb'}))
  router.use(bodyParser.urlencoded({ extended: false }))
  router.use(methodOverride())

  // Create database
  if (_.isObject(source)) {
    var db = low()
    db.object = source
github grafoojs / grafoo / packages / test-utils / src / index.js View on Github external
function setupDB() {
  const db = low(new MemoryAdapter());

  db.defaults({ posts: [], authors: [] }).write();

  times(2, () =>
    db
      .get("authors")
      .push({
        id: casual.uuid,
        name: casual.first_name + " " + casual.last_name
      })
      .write()
  );

  db.get("authors")
    .value()
    .forEach(({ id }) => {

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