npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@terencesun/githubdb

v1.1.4

Published

operate with github like mongodb for nodejs

Downloads

1,548

Readme

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>",    // Suggest that repo be private
                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>"
        });
        
        // NOTE: the programe will create the branch you set if you branch is not created, and the base sha is the latest default branch commit
        // if you don't want the behavior, you should create the branch by yourself
  
        // you can use usageInfo() to get the current usage information of the API
        // more detail infomation about rate limit, visit: https://docs.github.com/en/rest/using-the-rest-api/rate-limits-for-the-rest-api?apiVersion=2022-11-28
        // we only focus on the primary rate limit, but not the secondary rate limit
        // and you should control the rate when you use this package
        const usage = await githubdb.usageInfo();
        console.log(usage);
        
        // connect to db, if the repo or path is not exist, here will create them
        await githubdb.connect();
        
        // insert operations, insertOne/insertMany
        await githubdb.insertOne({ test: 1 });
        await githubdb.insertMany([ { test: 1, test2: 2 }, { test3: 3 } ]);
        
        // delete operations, deleteOne/deleteMany
        await githubdb.deleteOne({ test: 1 });
        await githubdb.deleteMany({ test: 1 });
        
        // update operations, updateOne/updateMany, here is not the options like mongodb's update operation
        await githubdb.updateOne({ test: 1 }, { $set: { test2: 123 } });
        await githubdb.updateMany({ test: 1 }, { $set: { test2: 123 } });
        
        // find operations, find, only one method here
        await githubdb.find({ test: 1 });
        
        /*
        * Support Operators
        * Query Operators: $eq/$gt/$gte/$lt/$lte/$ne/$in/$nin/$exists/$and/$or/$not/$geoWithin/$geoIntersects/$near
        * Update Operators: $inc/$mul/$rename/$set/$unset/$min/$max/$currentDate/$pop/$pullAll/$pull/$push
        * - Array Update Operator Modifiers: $each/$slice/$position
        * - Array Update Comparison Operators: $eq/$gt/$gte/$lt/$lte/$ne/$in/$nin
        * Powered by https://github.com/jclo/picodb
        * thx so much
        * */
        
        // All the methods and operators is above
}

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