开发者社区> 镜像站> NPM> lowdb-gh-adapter
lowdb-gh-adapter
Set your github repo as a backend for your lowdb instance
Last updated 3 years ago by yerkopalma .
ISC · Original npm · Tarball · package.json
$ cnpm install lowdb-gh-adapter 
SYNC missed versions from official npm registry.

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

Current Tags

  • 1.1.0                                ...           latest (3 years ago)

2 Versions

  • 1.1.0                                ...           3 years ago
  • 1.0.0                                ...           3 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 1
Last Month 1
Dependencies (2)
Dev Dependencies (6)
Dependents (0)
None