-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(repository): fix query to get id nomenclature #72
fix(repository): fix query to get id nomenclature #72
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Quelques optimisations à faire et c'est tout bon :)
src/pypnnomenclature/repository.py
Outdated
@@ -179,8 +179,7 @@ def get_nomenclature_id_term(cd_type, cd_term, raise_exp=True): | |||
t = text("SELECT ref_nomenclatures.get_id_nomenclature(:cd_type, :cd_term) as id") | |||
try: | |||
value = db.session.scalars( | |||
select("id").from_statement(t.params(cd_type=cd_type, cd_term=cd_term).limit(1)) | |||
).first() | |||
t.params(cd_type=cd_type, cd_term=cd_term)).first() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
t.params(cd_type=cd_type, cd_term=cd_term)).first() | |
select(func.ref_nomenclatures.get_id_nomenclature(cd_type,cd_term) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
on peut appeler des fonctions avec l'objet func
de SQLAlchemy (from sqlalchemy import func
)
src/pypnnomenclature/repository.py
Outdated
@@ -179,8 +179,7 @@ def get_nomenclature_id_term(cd_type, cd_term, raise_exp=True): | |||
t = text("SELECT ref_nomenclatures.get_id_nomenclature(:cd_type, :cd_term) as id") | |||
try: | |||
value = db.session.scalars( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
value = db.session.scalars( | |
value = db.session.scalar( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Vu que l'on récupére une valeur, on peut utiliser scalar
(voir https://docs.sqlalchemy.org/en/14/core/connections.html#sqlalchemy.engine.CursorResult.scalar)
src/pypnnomenclature/repository.py
Outdated
@@ -179,8 +179,7 @@ def get_nomenclature_id_term(cd_type, cd_term, raise_exp=True): | |||
t = text("SELECT ref_nomenclatures.get_id_nomenclature(:cd_type, :cd_term) as id") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
t = text("SELECT ref_nomenclatures.get_id_nomenclature(:cd_type, :cd_term) as id") |
Très déconseillé de faire les requêtes en SQL brut avec SQLAlchemy.
Rahh, le lint qui plante juste pour un espace manquant 😿 |
No description provided.