1.1.1 • Published 2 years ago

git-database v1.1.1

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

Installation

Because it's not in npmjs, you have to add this in package.json

{
   "dependencies": {
      "@neoxr/gitdb": "git+https://github.com/neoxr/gitdb",
   }
}

Get Token

You must have access to an authentication token to get it go to the https://github.com/settings/tokens page. Give a name for your token, set no expiration and follow the scope rules that need to be checked below to grant access and avoid errors.

  • repo
  • write:packages
  • delete:packages
  • admin:org
  • admin:public_key
  • admin:repo_hook
  • admin:org_hoox
  • gist
  • notifications
  • delete:repo
  • user
  • admin:enterprise
  • project
  • admin:rpg_key

Token format looks like this :

ghp_ZYuUPTSs3W4orj34g97iQRVrFWoswjwo

Authentication

Github authentication using this package as an example :

const config = {
   username: 'YOUR_USERNAME'
   repository: 'YOUR_REPOSITORY',
   file: 'FILENAME', // <-- JSON filename, If not passed defaults to : database
   token: 'YOUR_TOKEN'
}
const git = new(require('@neoxr/gitdb'))(config)

Fetch & Save JSON

There are main functions, namely .save() and .fetch()

1. Save

const data = {
   "name": "Budi Budiman",
   "age": 20,
   "hobby": "Turu"
}

git.save(data).then(res => {
   console.log(res)
})

2. Fetch

git.fetch().then(res => {
   console.log(res)
})

Example

Access the sample script here