GithubDB by TerenceSun
A lightweight GitHub database operator, let your GitHub repo like mongodb
Usage
npm install @terencesun/githubdb
import { GithubDb } from "@terence/githubdb";
async function main() {
const githubdb = new GithubDb({
token: "<your GitHub token, generat from https://github.com/settings/tokens>",
owner: "<your username, like db server name>",
repo: "<your repository to store the db's data, like database name>",
path: "<your file path in the repository to store the db's data, like table name>",
branch: "<your repository's branch you can choose, optional, default is your default branch>"
});
const usage = await githubdb.usageInfo();
console.log(usage);
await githubdb.connect();
await githubdb.insertOne({ test: 1 });
await githubdb.insertMany([ { test: 1, test2: 2 }, { test3: 3 } ]);
await githubdb.deleteOne({ test: 1 });
await githubdb.deleteMany({ test: 1 });
await githubdb.updateOne({ test: 1 }, { $set: { test2: 123 } });
await githubdb.updateMany({ test: 1 }, { $set: { test2: 123 } });
await githubdb.find({ test: 1 });
}
main();
Performance
We all use GitHub as a database, so, Low performance, but can be used to record some small things
CHANGES
- 1.1.2
- github.ts: add pre_page: 9999 into method isBranchExist, to avoid the github api branch number limit
- 1.1.3
- github.ts: add getAllBranchs function to get all branches (the max pre_page is 100 via the api's documents), to avoid the github api branch number limit
- 1.1.4
- add usageInfo() method to get the current usage information of the API
Licence
MIT