{"id":17224845,"url":"https://github.com/pseudomuto/ruby_simple_db","last_synced_at":"2025-08-13T01:13:54.355Z","repository":{"id":10202398,"uuid":"12295474","full_name":"pseudomuto/ruby_simple_db","owner":"pseudomuto","description":"A very simple in-memory database...just for fun","archived":false,"fork":false,"pushed_at":"2013-08-22T11:55:42.000Z","size":42,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-28T22:49:12.194Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pseudomuto.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-08-22T11:46:58.000Z","updated_at":"2013-12-04T16:47:11.000Z","dependencies_parsed_at":"2022-09-13T21:40:23.507Z","dependency_job_id":null,"html_url":"https://github.com/pseudomuto/ruby_simple_db","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/pseudomuto/ruby_simple_db","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pseudomuto%2Fruby_simple_db","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pseudomuto%2Fruby_simple_db/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pseudomuto%2Fruby_simple_db/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pseudomuto%2Fruby_simple_db/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pseudomuto","download_url":"https://codeload.github.com/pseudomuto/ruby_simple_db/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pseudomuto%2Fruby_simple_db/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264916028,"owners_count":23682957,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-15T04:12:08.843Z","updated_at":"2025-07-12T00:07:55.351Z","avatar_url":"https://github.com/pseudomuto.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Simple Database\n\n[![Build Status](https://travis-ci.org/pseudomuto/ruby_simple_db.png)](https://travis-ci.org/pseudomuto/ruby_simple_db)\n\nThis was a programming challenge I found online and thought I'd play around with. I've copied this origin problem here in the README in case you want to try it yourself (without using this code of course).\n\n## Original Problem\n\nYour task is create a very simple in-memory database, which has a very limited command set. Please code your solution in one of the following languages: Python, PHP, JavaScript, Ruby, Perl, Java, C++ or C. This problem should take you anywhere from 30 to 90 minutes. All of the commands are going to be fed to you one line at a time via stdin, and your job is to process the commands and to perform whatever operation the command dictates.\n\n### Commands you need to handle\n\n* SET [name]\u0026nbsp;[value]: Set a variable [name] to the value [value]. Neither variable names nor values will ever contain spaces.\n* GET [name]: Print out the value stored under the variable [name]. Print NULL if that variable name hasn't been set.\n* UNSET [name]: Unset the variable [name]\n* NUMEQUALTO [value]: Return the number of variables equal to [value]. If no values are equal, this should output 0.\n* END: Exit the program\n\nSo here is a sample input:\n\n\tSET a 10\n\tGET a\n\tUNSET a\n\tGET a\n\tEND\n\nAnd its corresponding output:\n\n\t10\n\tNULL\n\n\nAnd another one:\n\n\tSET a 10\n\tSET b 10\n\tNUMEQUALTO 10\n\tNUMEQUALTO 20\n\tUNSET a\n\tNUMEQUALTO 10\n\tSET b 30\n\tNUMEQUALTO 10\n\tEND\n\nAnd its corresponding output:\n\n\t2\n\t0\n\t1\n\t0\n\nNow, as I said this was a database, and because of that we want to add in a few transactional features to help us maintain data integrity. So there are 3 additional commands you will need to support:\n\nBEGIN: Open a transactional block\nROLLBACK: Rollback all of the commands from the most recent transactional block. If no transactional block is open, print out NO TRANSACTION\nCOMMIT: Permanently store all of the operations from any presently open transactional blocks. If no transactional block is open, print out NO TRANSACTION\nOur database supports nested transactional blocks as you can tell by the above commands. Remember, ROLLBACK only rolls back the most recent transaction block, while COMMIT closes all open transactional blocks. Any command issued outside of a transactional block commits automatically. The most commonly used commands are GET, SET, UNSET and NUMEQUALTO, and each of these commands should be faster than O(N) expected worst case, where N is the number of total variables stored in the database. Hint: this means that, for example, if your database had 100 items in it, your solution should be able to perform the GET, SET, UNSET and NUMEQUALTO operations without scanning all 100 items. \n\nTypically, we will already have committed a lot of data when we begin a new transaction, but the transaction will only modify a few values. So, your solution should be efficient about how much memory is allocated for new transactions, i.e., it is bad if beginning a transaction nearly doubles your program's memory usage. Here are some sample inputs and expected outputs using these commands:\n\nInput:\n\n\tBEGIN\n\tSET a 10\n\tGET a\n\tBEGIN\n\tSET a 20\n\tGET a\n\tROLLBACK\n\tGET a\n\tROLLBACK\n\tGET a\n\tEND\n\nOutput:\n\n\t10\n\t20\n\t10\n\tNULL\n\n\nInput:\n\n\tBEGIN\n\tSET a 30\n\tBEGIN\n\tSET a 40\n\tCOMMIT\n\tGET a\n\tROLLBACK\n\tEND\n\nOutput:\n\n\t40\n\tNO TRANSACTION\n\n\nInput:\n\n\tSET a 50\n\tBEGIN\n\tGET a\n\tSET a 60\n\tBEGIN\n\tUNSET a\n\tGET a\n\tROLLBACK\n\tGET a\n\tCOMMIT\n\tGET a\n\tEND\n\nOutput:\n\n\t50\n\tNULL\n\t60\n\t60\n\n\nInput:\n\n\tSET a 10\n\tBEGIN\n\tNUMEQUALTO 10\n\tBEGIN\n\tUNSET a\n\tNUMEQUALTO 10\n\tROLLBACK\n\tNUMEQUALTO 10\n\tEND\n\nOutput:\n\n\t1\n\t0\n\t1\n\n## Usage\n\n* fork/clone\n* bundle install\n* `bundle exec guard` for tests\n* `ruby bin/simple_db.rb` to use the app\n\n## Contributing\n\n1. Fork it\n2. Create your feature branch (`git checkout -b my-new-feature`)\n3. Commit your changes (`git commit -am 'Add some feature'`)\n4. Push to the branch (`git push origin my-new-feature`)\n5. Create new Pull Request\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpseudomuto%2Fruby_simple_db","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpseudomuto%2Fruby_simple_db","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpseudomuto%2Fruby_simple_db/lists"}