Mappings for easy access to (database) stored procedures in Python.
Currently the following database types are supported:
- MySQL, MariaDB, Percona, using the MySQL-python DB API 2.0 module
- PgSQL, using the psycopg2 DB API 2.0 module
Firstly, we can declare a PL/pgSQL stored procedure as follows:
CREATE OR REPLACE FUNCTION test_dbproc_add(a INTEGER, b INTEGER)
RETURNS INTEGER AS $$
BEGIN
RETURN $1 + $2;
END;
$$ LANGUAGE 'plpgsql';
Now, using wrap, we can access this stored procedure in Python like:
>>> import psycopg2
>>> from dbproc import Wrap
>>> conn = psycopg2.connect('dbname=test')
>>> proc = Wrap(conn, prefix='test_dbproc_')
>>> print proc.add(23, 42)
65
You can issue a ticket in GitHub: https://github.com/tehmaze/dbproc