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 8256961
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T02:02:47+00:00 2026-06-08T02:02:47+00:00

The Sqlalchemy result can have 0 to many records. Result is: record = meta.Session.query(model.EmpsTable).filter(model.EmpsTable

  • 0

The Sqlalchemy result can have 0 to many records.

Result is:

record = meta.Session.query(model.EmpsTable).filter(model.EmpsTable
         .firstname.like(searchQuery))

If there was only one record to return I would do:

return {'file_id':record.file_id, 'filename':
         record.filename, 'links_to' :record.url}

I can print the records on terminal like such:

for r in record:
    print r.file_id

But in this case I need to send these multiple records as JSON reply to a JQuery ajax.

How can I achieve this?

  • 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-08T02:02:49+00:00Added an answer on June 8, 2026 at 2:02 am

    First thing, don’t call record an object that is a query, collection, instrumented sequence/whatever… then you can just get a list of dictionaries.

    qry = meta.Session.query(model.EmpsTable).filter(model.EmpsTable
             .firstname.like(searchQuery))
    
    return {'data': [
             {'file_id':record.file_id, 'filename':
                record.filename, 'links_to' :record.url}
            for record in qry
           ]}
    

    To convert the returned object into JSON, you might already have decorated your method for that, or just call json.dumps() over it.

    UPDATE: for security reasons, as pointed out by @MrGhimire it’s better to wrap the list in a dictionary.

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

Sidebar

Related Questions

I have an SQLAlchemy model like the one below, and at first it didn't
I'm using SQLAlchemy, and many classes in my object model have the same two
I have a SQL query that I execute like this with an SQLAlchemy engine:
I'm using flask-sqlalchemy to build a webapp and I have the following model(s): class
I need execute 2 select in SQLAlchemy. For example: select1 = Session.query(col1, col2, col3,
I'm using Flask framework with sqlalchemy and I can't query some related table of
I have recently started using SQLALCHEMY to query a my-sql database. I want to
I have the following command that's kind of working as expected: DBSession.query(Users).filter(or_(Users.first_name.contains(search_term),Users.last_name.contains(search_term))).all() I searches
I'm new to SQLAlchemy. I currently have: ev = model.EnumerationValue(key=key_level_2, code=level_2) ev.keyvalues[key_parent] = level_1
Being new to SQLAlchemy, I was wondering at what time would Session() should be

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.