jkulton/gistkv

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Gem Version

Use gists as simple key-value databases

  • Simple non-sensitive datastore for scripts, crons, or CLI tools
  • MVP database for prototyping
gem install gistkv

Use GistKV::Client.create_database to create a new GistKV database. The method requires passing a valid token with access to the gist scope.

require 'gistkv'

# returns id of created gist
GistKV::Client.create_database(ENV['_TOKEN'])
# => f9ba626808266b93b7631aeb8321dbcf

Take note of the id returned from create_database when called, it should be saved for future use. This is the id of your database.

Use GistKV::Client.new to create a GistKV client. This method requires passing the id of a GistKV gist and a valid token with access to the gist scope.

require 'gistkv'

g = GistKV::Client.new(ENV['GIST_ID'], ENV['_TOKEN'])

# set a value
g.set("score", 10)

# get a value
g.get("score")
# => 10

# alias for .get
g["score"]
# => 10

# alias for .set
g["days"] = ["Friday", "Saturday", "Sunday"]

g.get("days")
# => ["Friday", "Saturday", "Sunday"]

# get list of keys
g.keys
# => ["score", "days"]

# update multiple keys at once
g.update(score: 11, days: ["Saturday"])

The above example code resulted in this gist.

It's also possible to create a read-only GistKV::Client by omitting the access token on creation. Please note this client will be subject to the API's public rate limits. See docs for more info.

  • GistKV creates a single __gistkv.json file in a gist.
  • On each .get or .set the gist's JSON is retrieved from the API, manipulated, and then written back to the gist.
    • As a result, you may experience unexpected results if multiple client instances are reading/writing the same gist at once.

Footnotes

  1. ⚠️Don't use GistKV to store sensitive data. Gists, even when set to secret, are not private.⚠️

About

Use gists as simple key-value databases

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages