Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8248321
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T23:09:12+00:00 2026-06-07T23:09:12+00:00

Using Flask, I’m curious to know if SQLAlchemy is still the best way to

  • 0

Using Flask, I’m curious to know if SQLAlchemy is still the best way to go for querying my database with raw SQL (direct SELECT x FROM table WHERE ...) instead of using the ORM or if there is an simpler yet powerful alternative ?

Thank for your reply.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T23:09:14+00:00Added an answer on June 7, 2026 at 11:09 pm

    I use SQLAlchemy for direct queries all the time.

    Primary advantage: it gives you the best protection against SQL injection attacks. SQLAlchemy does the Right Thing whatever parameters you throw at it.

    I find it works wonders for adjusting the generated SQL based on conditions as well. Displaying a result set with multiple filter controls above it? Just build your query in a set of if/elif/else constructs and you know your SQL will be golden still.

    Here is an excerpt from some live code (older SA version, so syntax could differ a little):

    # Pull start and end dates from form
    # ...
    # Build a constraint if `start` and / or `end` have been set.
    created = None
    if start and end:
        created = sa.sql.between(msg.c.create_time_stamp, 
            start.replace(hour=0, minute=0, second=0),
            end.replace(hour=23, minute=59, second=59))
    elif start:
        created = (msg.c.create_time_stamp >= 
                   start.replace(hour=0, minute=0, second=0))
    elif end:
        created = (msg.c.create_time_stamp <= 
                   end.replace(hour=23, minute=59, second=59))
    
    # More complex `from_` object built here, elided for example
    # [...]
    # Final query build
    query = sa.select([unit.c.eli_uid], from_obj=[from_])
    query = query.column(count(msg.c.id).label('sent'))
    query = query.where(current_store)
    if created:
        query = query.where(created)
    

    The code where this comes from is a lot more complex, but I wanted to highlight the date range code here. If I had to build the SQL using string formatting, I’d probably have introduced a SQL injection hole somewhere as it is much easier to forget to quote values.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using flask-sqlalchemy to build a webapp and I have the following model(s): class
Im using the python framework flask with sqlalchemy. My many-to-many looks like this: collections_questions
I am trying to use Elixir with Flask. Reason being using SQL Alchemy directly
I'm using Flask framework with sqlalchemy and I can't query some related table of
Using Flask Flask-sqlalchemy Sqlalchemy Jquery Datatables (jquery plugin) Jeditable (jquery plugin) Consider this user
I am using SQLAlchemy via Flask, and I want to add simple personal messaging
I'm using flask as a python framework with sqlalchemy. The models use the query_property
I am working on a web development project using flask and sqlalchemy orm. My
I am working on an web application using flask, postgresql and sqlalchemy and coding
I have a web application written using Flask, SQLAlchemy, and MySQL. When I get

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.