Console for live debugging of development databases
Project description
dbreak
A development database debugging tool that lets you set breakpoints and issue direct queries to one or more databases. Extensible via plugins to allow you to query a wide range of database types, both SQL and NoSQL.
Requires Python 3.6+
Installation
Install from PyPi using pip:
pip install dbreak
The base dbreak package includes support for DB API-compliant connections, such as the following:
- sqlite3 (built-in)
- psycopg2
- pymysql
Add support for additional connection types by installing plugins:
Usage
Your main interaction will be with the show_console() function. This pauses the application and lets you query any database connections you've provided.
Basic Usage
Example using a SQLite in-memory database:
import sqlite3
import dbreak
# Set up a SQLite connection as you normally would
connection = sqlite3.connect(":memory:")
# Add a table
connection.execute("create table foobar(x int, y int)")
# Add a row
connection.execute("insert into foobar select 1, 2")
# Pause execution and enter the console
dbreak.start_console(connection)
Once the start_console command is encountered you'll enter an interactive console where you can query the database using the connections you've provided:
Starting debug session on connection 'db[0]'.
You may issue database commands by simply typing them and pressing enter.
Use !help for a list of special commands.
Use !exit to quit the debugger and resume the application.
db[0]> select * from foobar
=== ===
x y
=== ===
1 2
=== ===
(1 row(s) returned)
Multiple Connections
If you have multiple database connections, you can name them via arguments to the show_console() command for easier access in the shell. Connections can be of the same type or different (for example, one shell could handle connections to both MySQL and Redis databases).
Example using two SQLite connections:
import sqlite3
import dbreak
# Set up a couple of SQLite connections
connection1 = sqlite3.connect(":memory:")
connection2 = sqlite3.connect(":memory:")
# Pause execution and enter the console
dbreak.start_console(
conn1=connection1,
conn2=connection2,
starting_connection="conn1"
)
The starting_connection
parameter takes a string that indicates what connection the shell should use initially. The other parameters act as names for the connections and can be anything you want.
Once inside the shell you can then use special commands (described via !help) to list and switch between the connections:
Starting debug session on connection 'conn1'.
You may issue database commands by simply typing them and pressing enter.
Use !help for a list of special commands.
Use !exit to quit the debugger and resume the application.
conn1> !connections
================= ============== ======================= ======================
Connection Name Wrapper Type Raw Connection Module Raw Connection Class
================= ============== ======================= ======================
conn1 DBAPIWrapper sqlite3 Connection
conn2 DBAPIWrapper sqlite3 Connection
================= ============== ======================= ======================
(2 row(s) returned)
conn1> !switch conn2
conn2>
Note that the name of the current connection is shown at the input prompt.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file dbreak-0.0.1.tar.gz
.
File metadata
- Download URL: dbreak-0.0.1.tar.gz
- Upload date:
- Size: 12.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.1.0 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.6.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c94505c8f659a3d5a5be2a9f6347db16c2bc4c10d39901088c4b422b8d54d330 |
|
MD5 | 912bdb35ecadfbb5dd7a6b3fcfd0cd75 |
|
BLAKE2b-256 | 35ab7e9810e6b0c943fe18ae47f2a65e4fc9e04e9f9118dcdec5384056b36290 |
File details
Details for the file dbreak-0.0.1-py3-none-any.whl
.
File metadata
- Download URL: dbreak-0.0.1-py3-none-any.whl
- Upload date:
- Size: 15.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.1.0 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.6.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 562b228329f720fa8419315a7b9cc3c66309451a239a3bced651f7ca68e8364b |
|
MD5 | 1dd2f085d00e1e40cb42162d658a0900 |
|
BLAKE2b-256 | f955ff8ad1a8598d39c339ebd9b1401cdaed871e5d9640464d4f39df3ef2c83c |