close

How to get cursor in SQLAlchamy

Hello Guys, How are you all? Hope You all Are Fine. Today We Are Going To learn about How to get cursor in SQLAlchamy in Python. So Here I am Explain to you all the possible Methods here.

Without wasting your time, Let’s start This Article.

Table of Contents

How to get cursor in SQLAlchamy?

  1. How to get cursor in SQLAlchamy?

    Finally got answer from Flask documentation, we can get cursor from db object using,
    from sqlalchemy import create_engine engine = create_engine('your_connection_string') connection = engine.raw_connection() cursor = connection.cursor()

  2. get cursor in SQLAlchamy

    Finally got answer from Flask documentation, we can get cursor from db object using,
    from sqlalchemy import create_engine engine = create_engine('your_connection_string') connection = engine.raw_connection() cursor = connection.cursor()

Method 1

Finally got answer from Flask documentation, we can get cursor from db object using,

from sqlalchemy import create_engine
engine = create_engine('your_connection_string')
connection = engine.raw_connection()
cursor = connection.cursor()

Method 2

It’s ok in this way.

db = SQLAlchemy(app)
session = db.session()
cursor = session.execute(sql).cursor

Summery

It’s all About this issue. Hope all Methods helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which Method worked for you? Thank You.

Also, Read