Documentation Index
Fetch the complete documentation index at: https://docs.regatta.dev/llms.txt
Use this file to discover all available pages before exploring further.
Let’s create a simple Python application that queries the Regatta database. Start by adding the reference to the regatta driver:
from pyregatta import connect
Note that you should import all relevant classes based on the functionality of your application
and its requirements.
Connection Details
Connection parameters will be defined as follows:
host = "aaa.bbb.ccc.ddd:ppp"
user = "MyUserName"
password = "SomeSophisticatedPassword"
Example Appliaction
Below is an example of a sample application that creates an employees table, adds four rows and then selects and prints the rows.
Create the main program and save it as: database_example.py
from pyregatta import connect
host = "aaa.bbb.ccc.ddd:pppp"
user = "MyUserName"
password = "SomeSophisticatedPassword"
# The connection and cursor are automatically closed when their blocks are exited
with connect(user, password, host) as conn:
with conn.cursor() as cursor:
# Create an employees table
cursor.execute(
"""
CREATE TABLE employees
(
employee_key INT PRIMARY KEY INDEX,
employee_name VARCHAR(40) NOT NULL,
employee_salary INT,
employee_department VARCHAR(50) NOT NULL
)
"""
)
conn.commit()
# Insert some sample rows
cursor.execute(
"""
INSERT INTO employees (employee_key,
employee_name,
employee_salary,
employee_department)
VALUES (1, 'John Doe', 10932, 'DevOps'),
(2, 'Richard Roe', 18324, 'Legal'),
(3, 'Jane Roe', 20411, 'Engineering'),
(4, 'Rachel Roe', 19555, 'Support')
"""
)
conn.commit()
# Query data
cursor.execute("SELECT * FROM employees")
# Fetch all rows
rows = cursor.fetchall()
# Print the results
for row in rows:
# Whole row (supports index and attribute access)
print(row)
# Example: access a specific column
# print(row.employee_name)
# print(row[0]) # employee_key
conn.commit()
# Drop the table
cursor.execute("DROP TABLE employees")
Running the Appliaction
Run the application from the directory containing your example:
python3 database_example.py
Expected output:
(1, 'John Doe', 10932, 'DevOps')
John Doe
1
(2, 'Richard Roe', 18324, 'Legal')
Richard Roe
2
(3, 'Jane Roe', 20411, 'Engineering')
Jane Roe
3
(4, 'Rachel Roe', 19555, 'Support')
Rachel Roe
4