Skip to content
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

Merged
merged 3 commits into from
Jun 3, 2024

Conversation

ch-cbna
Copy link
Contributor

@ch-cbna ch-cbna commented May 31, 2024

No description provided.

@jacquesfize jacquesfize changed the base branch from master to develop June 3, 2024 07:32
Copy link
Contributor

@jacquesfize jacquesfize left a 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 :)

@@ -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()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
t.params(cd_type=cd_type, cd_term=cd_term)).first()
select(func.ref_nomenclatures.get_id_nomenclature(cd_type,cd_term)

Copy link
Contributor

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)

@@ -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(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
value = db.session.scalars(
value = db.session.scalar(

Copy link
Contributor

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)

@@ -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")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.

@jacquesfize
Copy link
Contributor

Rahh, le lint qui plante juste pour un espace manquant 😿

@jacquesfize jacquesfize merged commit 334de80 into PnX-SI:develop Jun 3, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants