cx_Oracle
- official support from oracle
- simple to use and excute queris
- documintation very good with and lots of examples
- sting manipulation is easier in python
- can excute procedures storend in database need more search
- use python sepcification api for db
- work only with oracledb
- documintaion in procedures is minimal with some work in datatypes needed
import cx_Oracle
# Connect string format: [username]/[password]@//[hostname]:[port]/[DB service name]
conn = cx_Oracle.connect("system/GetStarted18c@//localhost:1521/XEPDB1")
cur = conn.cursor()
cur.execute("SELECT 'Hello World!' FROM dual")
res = cur.fetchall()
print(res)
dataToInsert = [
(10, 'Parent 10'),
(20, 'Parent 20'),
(30, 'Parent 30'),
(40, 'Parent 40'),
(50, 'Parent 50')
]
cursor.executemany("insert into ParentTable values (:1, :2)", dataToInsert)
in database
DECLARE
l_customer_name customers.name%TYPE;
BEGIN
-- get name of the customer 100 and assign it to l_customer_name
SELECT name INTO l_customer_name
FROM customers
WHERE customer_id = 100;
-- show the customer name
dbms_output.put_line( v_customer_name );
END;
in python
outVal = cursor.var(int)
cursor.callproc('myproc', [123, outVal])
flask with Flask-RESTful
- minimal server no restraction in project structure
#!flask/bin/python
from flask import Flask
app = Flask(__name__)
@app.route('/')
def index():
return "Hello, World!"
if __name__ == '__main__':
app.run(debug=True)
#!flask/bin/python
from flask import Flask, jsonify
app = Flask(__name__)
tasks = [
{
'id': 1,
'title': u'Buy groceries',
'description': u'Milk, Cheese, Pizza, Fruit, Tylenol',
'done': False
}
]
@app.route('/todo/api/v1.0/tasks', methods=['GET'])
def get_tasks():
return jsonify({'tasks': tasks})
- todo
<repo link>