Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

196
Visualizações
Do I need to use sqlalchemy if my database was already designed manually?

I am new to flask. I am developing a web application using flask and postgres. I have already designed database. I know sqlalchemy is orm. Do I still need to use sqlalchemy in flask if my database was already designed without sqlalchemy. I have to use that database for fetching and updating values. While going further will sqlalchemy is useful to me? or can I simply use db connector and proceed?

over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

Flask is a web framework and does not require SQLAlchemy. If you do choose to use Flask and SQLAlchemy, there is the Flask-SQLAlchemy extension to make them work together better.

Do you need to use SQLAlchemy, or any ORM, to work with a database? No. Should you? Yes. ORMs bring certain features and conveniences that raw SQL does not provide. And you can always write raw SQL.

Here are some important benefits of SQLAlchemy.

Compatibility

While there is a SQL standard, all SQL databases are different. An ORM smooths over many of these differences so your SQLAlchemy code will be easier to migrate to different databases.

Migrations

Your schema is written, but what if you need to change it? That's where database migrations come in. They allow you to change your schema (adding and removing columns, changing types, adding tables) in a manner that is reproducible and reversible. This makes it easier and safer to change your database, and the data in it, along with your code. As well as to reverse out of changes that turned out to be bad ideas.

Object Mapping

ORM stands for "Object-Relational Mapper". It lets you treat a database as a bunch of objects rather than just some data. Python is an object-oriented language, and your data will be much easier to work with as objects with methods. Each table is a class, each row is an object.

The "mapping" part doesn't just apply to rows, it also applies to SQL data types. For example, timestamp columns will be loaded as Python as datetime objects. This makes it more convenient to work with the data in Python.

Validations

SQLAlchemy allows you to validate your data before you insert it into the database ensuring all your data is as you expect. Knowing everything in the database is valid makes the system more robust and cuts down on your error handling.

Build Queries

Instead of having to write all your SQL by hand, SQLAlchemy has a query builder. You can build and modify queries as objects. This makes writing queries simpler. And it lets you build them up in pieces. For example, you can start with a query.

all_users = select([
    users.c.name,
    users.c.email
])

And then add a where clause.

a_users = all_users.where(users.c.name.ilike("a%"))

And then a limit clause.

some_a_users = a_users.limit(10)
over 4 years ago · Santiago Trujillo Relatório

0

Using sqlalchemy will help you fetching/inserting data very easy, no matter you designed your db manually, you just need to define your design and then instead of writing multiple lines, you write a line and everything done. It also help you handle errors and a lot more. Strongly suggest you to use it.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda