Git Product home page Git Product logo

kvstore's Introduction

KVStore

Simple key/value store using PHP and SQLite.

This is intended for a low to medium traffic website. If you need to use it on a high traffic website, switching the MySQL or PostgreSQL would be preferred to SQLite.

KVStore supports the following operations:

get
put
inc
dec
add

KVStore fails silently in most situation unless the json param is passed.

Creating the database

When creating the database make sure it is in a location where the web server has read/write access.

sqlite3 some/path/kv.db

CREATE TABLE kv_store (
  id INTEGER PRIMARY KEY,
  key TEXT,
  value TEXT,
  project TEXT,
  time TEXT
);
CREATE TABLE auth (
  id INTEGER PRIMARY KEY,
  project TEXT,
  secret TEXT,
  name TEXT,
  email TEXT,
  disabled INTEGER
);
CREATE INDEX idx_key ON kv_store(key ASC);
INSERT INTO auth (project,secret) VALUES ("my_project", "qskpchkqupdqydkz");
PRAGMA journal_mode = WAL;
PRAGMA synchronous = 1;
.quit

Installing

Most modern installations of PHP already have the SQLite extention installed. If you're running an older version of PHP you will need to install the SQLite extention.

Place the kvstore.php file where the web server has access.

Copy kvstore_inc.sample.php to kvstore_inc.php and change $DB_NAME = "some/path/kv.db" to the location of the database file.

Testing

Once installed the key/value store can be tested with the following:

KVSTORE="https://example.com/kvstore.php?project=my_project&secret=qskpchkqupdqydkz"
curl -s -X POST -d "action=put" -d "key=games/favorite" -d "value=thimbleweedpark" $KVSTORE
curl -s -X POST -d "action=put" -d "key=test" -d "value=1" $KVSTORE
curl -s -X POST -d "action=inc" -d "key=test" $KVSTORE
curl -s -X POST -d "action=get" -d "key=games/favorite" $KVSTORE
curl -s -X POST -d "action=get" -d "key=games/favorite" -d "json=1" $KVSTORE
curl -s -X POST -d "action=inc" -d "key=test" -d "json=1" $KVSTORE

To check the key/value database:

sqlite3 some/path/kv.db

SELECT * FROM auth
SELECT * FROM kv_store
.quit

kvstore's People

Contributors

grumpygamer avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

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.