Git Product home page Git Product logo

stupiddb's Introduction

StupidDB

I was looking for a really easy way to organize SQL outside of code. Standard ORMs just seem to have way more functionality then I actually need and object models just seem to kill all that is great with SQL. Additionally, I actually like working with SQL and found little use for proper models in my projects. So thus, all I really needed was a stupid simple python module to communicate with the database and provide an ORM'ish type framework to organize SQL.

StupidDB supports PostgreSQL (psycopg2) and MySQL (MySQLdb). One caveat is that there is no restriction to writing db-specific SQL in your SQL map files. StupidDB provides no abstraction as far as the database layer is concerned. But really, how often are you gonna swap the underlying DB? Plus, with little restriction on the DB layer, you can take advantage of more advanced DB-specific features (analytical functions and stuff).

Configuration

Place your config file in the root of your application and specify the following arguments:

  • db_user=username
  • db_password=password
  • db_host=hostname
  • db_port=port
  • db_connectdb=connect_db
  • db_type=postgresql/mysql
  • sqlmap_path=path to sqlmap directory (optional: by default, assumes a sqlmap directory exists in your application root)

How to use this StupidDB

It's really quick and easy with 3 methods to remember. First, instantiate a class:

from StupidDB.stupiddb import StupidDB
stupid = StupidDB(<config_file (optional)>)
# if config path is not provided, StupidDB will just look in the app root

You might need to modify the import statement depending on how your environment is setup.

read

This encompasses any and all queries meant to return as a list of dicts. As a consumer, the call is as follows:

results = stupid.read(<sqlmap>, <id>, <**kwargs>)
  • sqlmap refers to the xml file containing the relevant set of queries (see sqlmap/example.xml)
  • id refers to the name of the query being called (see sqlmap/example.xml)
  • **kwargs all named parameters that will be used in the query (match in sqlmap is required)

read_single

Same as read_single accepts returns a single dict

result = stupid.read_single(<sqlmap>, <id>, <**kwargs>)

write

This ecompasses all inserts, updates, merges (DML statements, see sqlmap/example.xml)

stupid.write(<sqlmap>, <id>, <**kwargs>)

other things to keep in mind

  • The sqlmap file can be contained within subdirectories: ie, <sqlmap_root>/dir1/dir2/map.xml. You can define this in the read/write calls as sqlmap='dir1.dir2.map'. The module will auto detect path seperators and point to the correct place.

And that's it! Have fun...

stupiddb's People

Contributors

nrodrigo avatar

Watchers

 avatar 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.