Code Monkey home page Code Monkey logo

lurker's Introduction

Lurker

Lurker is a tiny mysql wrapper built on the top of python-mySQLdb.

Installation

install via pip

pip install lurker

or easy_install if you like 90's.

easy_install lurker

or latest master branch

git clone git://github.com/emre/lurker.git
python setup.py install

Quick Tutorial

Connecting to the database

  • with Configuration objects. (This could be preferrable for seperating environments like DevConfig, ProdConfig, TestConfig)
class DatabaseConfig(BaseLurkerConfig):
    host = 'localhost'
    user = 'root'
    passwd = ''
    db = ''

connection = Connection(DatabaseConfig)
  • without Configuration objects
connection = Connection().quick_connect("mysql_user", "mysql_passwd", "db_name", "host")

Sending Queries

# returns last_id
connection.execute("INSERT INTO table_name (name) VALUES (%s)", ['Selami Sahin', ])

# returns row count
connection.execute("UPDATE table_name SET name = %s", ["Muhittin Bosat", ])

# returns a result set
all_people = connection.get_results("SELECT * FROM people")

# returns a row
one_people = connection.get_row("SELECT * FROM people WHERE id = 1")

# server-side cursor
for person in connection.iterate("SELECT * FROM people"):
    print person

Query Caching Support with Redis

  • In order to activate caching support, you need to set cache and cache_information variables in your config class.
from lurker.configuration import BaseLurkerConfig
from lurker.connection import Connection
from lurker.cache.backends.redis_backend import RedisBackend

class DbConfig(BaseLurkerConfig):
    host = 'localhost'
    user = 'root'
    passwd = 'passwd'
    db = 'db_name'
    cache = True
    cache_information = {
        'backend': RedisBackend,
        'args': (),
        'kwargs': {'host': 'localhost', 'port': 6379, 'db': 0},
    }
  • Usage in get_results and get_row
print connection.get_row("SELECT * FROM people WHERE id = %s", parameters=(1,), cache=30)
print connection.get_row("SELECT * FROM people WHERE id = %s", parameters=(1,), cache=30)

# output
# DEBUG:root:cache miss: SELECT * FROM people WHERE id = %s
# {'id': 1L, 'name': u'Emre Yilmaz'}
# DEBUG:root:cache hit: SELECT * FROM people WHERE id = %s
# {u'id': 1, u'name': u'Emre Yilmaz'}

Maintainer

Emre Yılmaz - @emre_yilmaz

Contributors

Mirat Can Bayrak - @mirat

Projects/Scripts powered by lurker

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.