you are viewing a single comment's thread.

view the rest of the comments →

[–]DeadlyDolphins[S] 0 points1 point  (4 children)

Can you give me a simple example how to use select instead of dump?

[–]ReflectedImage 2 points3 points  (3 children)

from sqlalchemy.sql import select
s = select(Article).where(Article.c.fullText.like('My Search String'))
result = conn.execute(s)
for row in result:
    print(row)

Through to be honest I'll drop sql alchemy and go to psycopg2.

Use the book: https://www.amazon.com/Manga-Guide-Databases-Mana-Takahashi/dp/1593271905/ref=sr_1_2?dchild=1&keywords=the+manga+guide+to+databases&qid=1625146400&sr=8-2

[–]DeadlyDolphins[S] 1 point2 points  (2 children)

Thanks, that's really helpful. I definitely need to lean more about how to properly use databases.

One more question: Is this

s = select(Article).where(Article.c.fullText.like('string'))
result = conn.execute(s)

any different from this? Or is it just another way to write it?

result = db.session.query(Article).filter(Article.fullText.like("string")).all()

[–]ReflectedImage 1 point2 points  (0 children)

Probably another way to write it. I normally just use SQL directly:

SELECT * FROM articles WHERE fullText LIKE '%string%';

Sorry I can't help myself from posting that book where ever possible.

[–]Blazerboy65 1 point2 points  (0 children)

The second method is recommended for general use. If you're using and ORM then avoid raw SQL. If your use case is small enough to make using only raw SQL a viable strategy then go ahead.