Git Product home page Git Product logo

simple-in-memory-database's Introduction

Simple in memory database

This is a very simple in-memory database, which has a very limited command set.

  • SET [name] [value]: Set a variable [name] to the value [value]. Neither variable names or values will ever contain spaces.
  • GET [name]: Print out the value stored under the variable [name]. Print NULL if that variable name hasn't been set.
  • UNSET [name]: Unset the variable [name]
  • NUMEQUALTO [value]: Return the number of variables equal to [value]. If no values are equal, this should output 0.
  • END: Exit the program
  • BEGIN: Open a transactional block
  • ROLLBACK: Rollback all of the commands from the most recent transaction block. If no transactional block is open, print out INVALID ROLLBACK
  • COMMIT: Permanently store all of the operations from any presently open transactional blocks

Usage examples

Example 1

$ php cli.php 
SET a 10
GET a
UNSET a
GET a
END
-- OUTPUT --
10
NULL

Example 2

$ php cli.php 
SET a 10
SET b 10
NUMEQUALTO 10
NUMEQUALTO 20
UNSET a
NUMEQUALTO 10
SET b 30
NUMEQUALTO 10
END
-- OUTPUT --
2
0
1
0

Example 3

$ php cli.php 
BEGIN
SET a 10
GET a
BEGIN
SET a 20
GET a
ROLLBACK
GET a
ROLLBACK
GET a
END
-- OUTPUT --
10
20
10
NULL

Example 4

$ php cli.php 
BEGIN
SET a 30
BEGIN
SET a 40
COMMIT
GET a
ROLLBACK
END
-- OUTPUT --
40
INVALID ROLLBACK

Example 5

$ php cli.php 
SET a 50
BEGIN
GET a
SET a 60
BEGIN
UNSET a
GET a
ROLLBACK
GET a
COMMIT
GET a
END
-- OUTPUT --
50
NULL
60
60

Example 6

$ php cli.php 
SET a 10
BEGIN
NUMEQUALTO 10
BEGIN
UNSET a
NUMEQUALTO 10
ROLLBACK
NUMEQUALTO 10
END
-- OUTPUT --
1
0
1

simple-in-memory-database's People

Contributors

vhpoet avatar

Watchers

James Cloos 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.