shailesh_07
shailesh_07

Reputation: 13

How to write SQL query from orator module in python?

I recently stumbled upon orator module in python. It is used to connect to a database through python. I was using psycopg2 module before to connect to PostgreSQL, but I wanted to try orator anyway.

My question is, how do I get the data from postgesql using .statement() instead of a boolean value? Is it even possible?

from orator import DatabaseManager
config = { 'postgresql': {
    'driver': 'postgres',
    'host': 'localhost',
    'user': 'postgres',
    'password': 'postgres',
    'database': 'postgres_db'
    }}
db = DatabaseManager(config)

print(db.statement("SELECT * FROM raw_country_details WHERE name = 'Nepal'"))

The print statement prints a boolean value.

Upvotes: 0

Views: 528

Answers (1)

Ice
Ice

Reputation: 462

This is a raw SQL way.

results = db.select('select * from users where name = ?', 'Nepal')

(https://orator-orm.com/docs/0.9/basic_usage.html#running-queries)

Or you can try Query Builder.

user = db.table('raw_country_details').where('name', 'Nepal').first()

Or you can find first 10 people named 'Nepal'

users = db.table('raw_country_details').where('name', 'Nepal').chunk(100):

Here is a detailed explanation. https://orator-orm.com/docs/0.8/query_builder.html#selects

Upvotes: 1

Related Questions