Home > Net >  How to write SQL query from orator module in python?
How to write SQL query from orator module in python?

Time:01-06

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.

CodePudding user response:

This is the raw SQL method.

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

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

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

  •  Tags:  
  • Related