Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

mydb

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mydb

db wrapper for mysql

  • 0.1.2
  • PyPI
  • Socket score

Maintainers
1

mydb

mydb is a simple db wrapper for mysql.

.. contents::

Install

::

pip install mydb

Usage

Single Connection

::

    from mydb.connection import Connection

    db = Connection("mysql://youngking@localhost:13306/mydatabase")
    for article in db.query("SELECT * FROM articles"):
        print article.title

Multiple Connection Like Master/Slave

::

    from mydb.router import ConnectionRouter
    from mydb.proxy import DBProxy
    router = ConnectionRouter(["myapp.somewhere.MasterSlaveRouter"])
    db = DBProxy(router)

    for article in db.query("SELECT * FROM articles"):
        print article.title

Database routers


A database Router is a class that provides up to two methods:

db_for_read(statement, \**hints)

::

    Suggest the database that should be used for read operations for ``SELECT`` statement.

    If a database operation is able to provide any additional information that might assist in selecting a database, it will be provided in the hints dictionary. Details on valid hints are provided below.

    Returns None if there is no suggestion.

db_for_write(model, \**hints)

::

    Suggest the database that should be used for writes of statements except ``SELECT``.

    If a database operation is able to provide any additional information that might assist in selecting a database, it will be provided in the hints dictionary. Details on valid hints are provided below.


There is an example in ``tests/test_router.py``.

A router doesn’t have to provide all these methods – it may omit one or more of them. If one of the methods is omitted, 
mydb will skip that router when performing the relevant check.


In ``mydb.router``  there are some default routers, where you can inherit from and overwriten them.


Links
===============================

* `documentation <http://pythonhosted.org/mydb>`_

* `SouceCode at github <https://github.com/youngking/mydb>`_

Keywords

FAQs


Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc