manojpawar94 / python-jdbc

Python JDBC Utils

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Python JDBC

It is jdbc utility helps to query on the RDBMS databases. It avoids the boilerplate code required while executing the sql query. It supports database connection pool as well.

Examples

from jdbc.mysql_connector import MySQLConnector
from jdbc.template import JdbcTemplate

config = {
    "host": "localhost",
    "port": 3306,
    "database": "xxx",
    "user": "root",
    "password": ""
}

# initialize MySQLConnector and JdbcTemplate once in program (in __init__.py)
mysql_conn = MySQLConnector(config)
jdbcTemplate = JdbcTemplate(mysql_conn)

# query to retrieve tuple
jdbcTemplate.query_for_tuple("select * from users where user_id = %s ", (1234,))

# query to retrieve list of tuples
jdbcTemplate.query_for_tuple_list("select * from users where is_active = %s", ('A',))

# query to retrieve dictionary 
jdbcTemplate.query_for_dict("select * from users where user_id = %s", (1234,))

# query to retrieve list of dictionary
jdbcTemplate.query_for_dict_list("select * from users where is_active = %s", ('A',))

# query to insert record
jdbcTemplate.update("Insert into users (first_nam, last_nam) values (%s, %s)", ("Manoj", "Pawar"))

# query to update record
jdbcTemplate.update("Update users set is_activev = %s where user_id = %s", ('A', 1234))

About

Python JDBC Utils

License:MIT License


Languages

Language:Python 100.0%