[Koha-devel] Need to complete coding guidelines about when to use SQL and where.

Victor Grousset/tuxayo victor at tuxayo.net
Wed Jan 25 23:55:06 CET 2023


Hi :)

We need some additions/changes to the SQL 8 guideline
https://wiki.koha-community.org/wiki/Coding_Guidelines#SQL8:_SQL_code_in_.pl_scripts
Like it allows implicitly SQL in .pm doesn't mention DBIC.

In last meeting there was a discussion are here are some takeaways 
(https://ilbot3.kohaaloha.com/koha/2023-01-11#i_2343089)

Add in the guidelines:
No SQL by default in any place (in new code) except for database upgrades.
But if it's not possible to do a query with the ORM or if it's much less 
readable or a performance bottleneck, then it should be done in a custom 
subroutine in the relevant DBIC schema class.[1][2]
If SQL needed: SQL::Abstract syntax should be used over raw SQL in the 
/Koha namespace.[3] Syntax: 
https://metacpan.org/pod/SQL::Abstract::Classic#WHERE-CLAUSES

What about command-line scripts? Should new ones/major changes use the 
ORM by default? Is that easy to access it from a script?

SQL8: "SQL is also tolerated for reports" even new report? (assuming 
that still happens)

[1] need more feedback on that last part.
[2] Is DBIC schema class the right term?
[3] why not everywhere? (except db upgrades) related to the upcoming 
question about scrips



-- 
Victor Grousset/tuxayo


More information about the Koha-devel mailing list