Giter VIP home page Giter VIP logo

gist-db's Introduction

☁️ Gist-DB ☁️

Treat your gist account like a database. Powered by TaffyDB and Github.

npm downloads npm version js-standard-style

Install

npm install --save gist-db

Usage

var config = {
  github: {
    username: "mcwhittemore"
  }
}

var db = require("gist-db")(config);

db.event.on('refreshing', function(){
  //MIGHT WANT TO LOCK DOWN THINGS FOR A BIT
  console.log("LETS DO THIS");
});

db.event.on('refreshed', function(err){
  db().each(function(file){
    console.log(file);
  });
});

File Object structure

{
  id = gist_id + "_" + filename,
  filename = filename,
  gist_id = gist_id,
  error: undefined,
  raw: "THE RAW VALUE OF THE FILE",
  type: "mime type",
  language: "language the file is written in",
  raw_url: "https path to the raw text version of the file",
  size: numeric size of the file,
  gist: {
    id: gist_id
    public: boolean,
    created_at: date object,
    updated_at: date object,
    description: "the gist description"
  }
}

Demo

# Clone the repository
git clone https://github.com/pinn3/gist-db

# Run the demo! This will also install dependencies and run the build script
npm run demo

API

Please refer to the TaffyDB docs for more details

GISTDB(config, fileInit, fileSave)

Create a new gist-db.

Parameters

  • config: A settings object.
Required: {
  github:{
    username:"SOME_USER_NAME"
  }
}

Defaults: {
  refreshMin: 10,
    github: {
      per_page: 100,
      timeout: 5000,
      version: "3.0.0"
    },
    local: {
      save: "NEVER", //NEVER, ON_REFRESH, ALWAYS 
      location: undefined
    }
}

Available: {
  refreshMin: 10,
  github: {
    per_page: 100,
    timeout: 5000
    version: "3.0.0",
    authenticate: {
      type: "basic or oauth",
      username: "your_username_if_basic",
      password: "your_password_if_basic",
      token: "your_oauth_token_if_oauth"
    },
    local: {
      save: "NEVER OR NEVER OR ON_REFRESH OR ALWAYS"
      location: "path and filename"
    }
  }
}
  • fileInit: function(file). A function that returns the file obj if it should be added to the DB and undefined if it should be excluded.

  • fileSave: function(file, callback). A function that allows for further parameter work on files after the raw data has been received. A functioning implementation of this MUST pass the file object as a parameter to callback to save changes to the DB. Note: this will perform an update to the database.

db({field:value})

  • TaffyDB: Yes

  • Returns: All rows that meet the passed criteria. Not passing an object, will return all rows.

db.insert({})

Inserts records into the database.

  • TaffyDB: Yes
  • Returns: A query pointing to the inserted records

db.github

Full use of the github module passed the github subsection of your config file.

db.event

An implementation of require("events").EventEmitter

db.event.on('refreshing', function(){})

Use to be notified when gist-db is connecting gist for a refresh.

db.event.on('refreshed', function(err){})

Use to be notified when gist-db is done its current refresh. If err is set, this refresh was ended due to error.

db.event.on('file_error', function(err, file){})

Use to be notified of errors in gathering data on the gist files.

Parameters

  • err: The error object that triggered this event
  • file: The file object that was being gathered when the error occurred

db.event.on('github_error', function(err, res){})

Use to be notified of errors when connecting with github.

Parameters

  • err: the github module error object that triggered this event

  • res: The github module response object. Might contain good data about the error.

Things to be done

0.1.10

  • Add tests

0.2.0

  • Add Update gist.github
  • Add Insert gist.github
  • Add Delete gist.github

Licenses

All code not otherwise specified is released under the MIT License.

All code found in the node_modules directory is Copyrighted by its creators. Please see each module for further details.

gist-db's People

Contributors

pinn3 avatar mcwhittemore avatar

Stargazers

 avatar Jinhu Wang avatar Alexander H avatar  avatar Kernel Jackson avatar Erlan Sobakin avatar Tu Huynh avatar  avatar Kotaro Inoue avatar foresightyj avatar Sami AlEsh avatar Stanislav Pankevich avatar Mindaugas Jasiulis avatar LearningResource avatar Benjamin Keating avatar Dimitri DO BAIRRO avatar Albin Ekblom avatar fly avatar Dawson Botsford avatar Ger Hobbelt avatar Aleksandar.B avatar Kevin Bohinski avatar James Michael DuPont avatar  avatar Simon Kusterer avatar gonzoid avatar Ilya avatar Greg Lamp avatar Will Laurance avatar

Watchers

 avatar Jameson Aranda avatar  avatar  avatar

gist-db's Issues

Decide on a new API design

This project has not aged well these last years. It is currently based on TaffyDB, which doesn't seem to be actively maintained either. I personally feel like it would be quicker to redesign this project, as I'd otherwise have to read up on how TaffyDB works again in order to maintain the current structure.

It is also unclear how much has changed in the Gist API's. Last time I checked, it was possible to store multiple snippets in a single gist, which I considered to take advantage of and use as collections/tables.

This issue will serve as a place to collect and culminate thoughts/ideas. The output of this will be implemented in the overhaul branch. Note that changes of its commit history might be force pushed at any time

First load from saved DB

If there is a saved DB file, load this and issue a refreshed event. Then run a gist request refresh.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.