lowdb-gh-adapter

    1.1.0 • Public • Published

    lowdb-gh-adapter stability

    npm version build status downloads js-standard-style

    Set your github repo as a backend for your lowdb instance

    Usage

    const low = require('lowdb')
    const GhStorage = require('lowdb-gh-adapter')
     
    const adapter = GhStorage({
      file: 'db.json',
      repo: 'lowdb-gh-adapter',
      user: 'YerkoPalma',
      token: process.env.TOKEN
    })
     
    low(adapter)
      .then(db => {
        // Set some defaults
        return db.defaults({ posts: [], user: {} })
          .write()
          .then(() => {
            // Add a post
            db.get('posts')
              .push({ id: 1, title: 'lowdb is awesome'})
              .write()
              .then(() => {
                // Set a user using Lodash shorthand syntax
                db.set('user.name', 'yerkopalma')
                  .write()
              })
          })
      })

    API

    const adapter = GhStorage(opts)

    Create an asynchronous adapter object, and then use it like any other asynchronous adapter with lowdb. Most of the options are mandatory:

    • file: Required. A string indicating the path of the file where you want to store your data in your repo. json extension is not mandatory but it is recommended. If this file is not present in your repo, it will be automatically created.
    • repo: Required. A string for the github repo where the file is stored.
    • user: Required. The github username that owns the github repo.
    • token: The personal access token for github. You can create tokens here, you only need the repo permission. If this option is not provided, then you must provide a username and password option for authentication.
    • username: A Github username who have access to the repo specified. Not needed if you provided a token, if you don't, you will also need a password for this username.
    • password: A Github password for the username provided.
    • branch: Optional. Pass a string with the name of the branch where you want to save your data. If the branch is not specified, it will default to master. If the provided branch doesn't exists in the repo it will attemp to create it as a clone of master branch.

    Disclaimer

    Please note that this is not recommended for big scale projects. As lowdb limits section says, for bigger projects you should stay with solutions like MongoDB.

    Specially for this adapter, you should have a look to Github Rate limit which has a quota of 5000 requests per hour.

    License

    MIT

    Keywords

    none

    Install

    npm i lowdb-gh-adapter

    DownloadsWeekly Downloads

    4

    Version

    1.1.0

    License

    ISC

    Last publish

    Collaborators

    • yerkopalma