Coder Social home page Coder Social logo

db.sh's Introduction

db.sh - Append-only Bash database

Roughly based on an example in Martin Kleppmann's book Designing Data-Intensive Applications.

Additional, unique feature: The database file itself is also a valid Bash script 🤪🥴.

How does it work?

Startup: The database file is "sourced" to evaluate all assignments from previous runs.

Write operations: Write operations are specified in the form of a Bash variable assigment instruction.
This instruction is 1) executed with eval and 2) appended to the database file.

Read operations: Read operations are specified simply as the variable name.
This variable is printed using eval "printf '%s\n' ...".

All variables are internally prefixed with dbsh_, to avoid overwriting predefined variables.

Examples:

# Write command:
myvar="\"That's a hell of a database\", he said."
# ...is executed as:
eval dbsh_myvar="\"That's a hell of a database\", he said."
echo dbsh_myvar="\"That's a hell of a database\", he said." >> "$db_file"

# Read command:
myvar
# ...is executed as:
printf eval "printf '%s\n' \"$dbsh_myvar\""

Is this safe?

This code is using eval. Can this be safe?

./db.sh -c "safe=Yes \"No, of course not...\""
./db.sh: line 62: No, of course not...: command not found

Since this seems too dangerous, the option -k was added.
The code then follows mostly the example from the book.
This avoids 99% of the security issues, but doesn't store the database as real a Bash script any more.

Should I use it in production?

If you currently use a Powershell script as your database, then it could be an improvement.

Otherwise, use it only if you like databases that allow arbitrary code execution.

db.sh's People

Contributors

heidemn avatar

Watchers

 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.