Skip to content

Added PostgreSQL support #160

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Conversation

VilainMamuth
Copy link

Initial support for PostgreSQL i made at work to test your tool

/**
* HostMapper class implementation for MariaDB
*/
class HostMapper implements HostMapperInterface
Copy link
Contributor

Choose a reason for hiding this comment

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

could it not extend the MySQL one if there is no changes to the implementation ?

Copy link
Author

Choose a reason for hiding this comment

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

Implementation is slightly different, I had to remove all backticks from sql queries to make it work
sure there's a lot of duplicate code :(

Copy link
Contributor

Choose a reason for hiding this comment

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

maybe all implementations could benefit from a function to quote column names @liuch ?

Copy link
Owner

Choose a reason for hiding this comment

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

@williamdes I think it's better to remove the quotes than to add another function to confuse the code. Quotation marks are not really necessary.

Copy link
Contributor

Choose a reason for hiding this comment

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

sure

Copy link
Author

Choose a reason for hiding this comment

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

@williamdes I think it's better to remove the quotes than to add another function to confuse the code. Quotation marks are not really necessary.

i agree, plus backticks are not sql standard. I also changed some group by clauses as PG is more strict about that.
In MariaDb, maybe SQL_MODE variable could help to standardize queries.

Copy link
Owner

Choose a reason for hiding this comment

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

In MariaDb, maybe SQL_MODE variable could help to standardize queries.

Thanks for the tip!

@@ -22,7 +22,8 @@
"league/flysystem-aws-s3-v3": "^2.5 || ^3.25.1"
},
"suggest": {
"ext-imap": "Needed to process incoming DMARC reports stored in a mailbox"
"ext-imap": "Needed to process incoming DMARC reports stored in a mailbox",
"ext-pdo_pgsql": "Needed to use Postgresql"
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we not move ext-pdo_mysql here too ?

@liuch
Copy link
Owner

liuch commented Mar 22, 2025

Hi VilainMamuth, williamdes,

Quoting column names is not necessary in my implementation. I find it convenient (to search for fields and table names in code), but I'm not willing to pay for it by increasing code duplication.

I propose to do this: Add a directory, let's say classes/Database/Common, move to it all the code from classes/Database/Mariadb and remove the quoting of names. The DatabaseConnector::getMapper method will first look for the required class in the database type-specific directory, and then in the Common directory. Inheriting from Mariadb classes will be confusing, especially when there are more than two database types. Therefore, I suggest inheriting from classes in the Common directory if you need to make corrections to the class implementation. What do you thing about this?

Sorry for the slow replies: I'm sick and it's currently a bit inconvenient for me to use the computer.

@williamdes
Copy link
Contributor

Hi VilainMamuth, williamdes,

Quoting column names is not necessary in my implementation. I find it convenient (to search for fields and table names in code), but I'm not willing to pay for it by increasing code duplication.

I propose to do this: Add a directory, let's say classes/Database/Common, move to it all the code from classes/Database/Mariadb and remove the quoting of names. The DatabaseConnector::getMapper method will first look for the required class in the database type-specific directory, and then in the Common directory. Inheriting from Mariadb classes will be confusing, especially when there are more than two database types. Therefore, I suggest inheriting from classes in the Common directory if you need to make corrections to the class implementation. What do you thing about this?

Sorry for the slow replies: I'm sick and it's currently a bit inconvenient for me to use the computer.

Very good idea!
Let's make it easier to understand what each implementation has different

Second subject: maybe we could benefit from an active record pattern?
I built one that is very simple and works in most easy cases. That said, manual queries can still be needed.

@williamdes
Copy link
Contributor

@liuch
Copy link
Owner

liuch commented Mar 25, 2025

@VilainMamuth If I make a modification (moving to Common and removing name quoting), can you modify your PR?

@liuch
Copy link
Owner

liuch commented Mar 25, 2025

Second subject: maybe we could benefit from an active record pattern?
I built one that is very simple and works in most easy cases. That said, manual queries can still be needed.

I don't like the long and difficult for understanding text strings of sql queries in my code, I've been wanting to solve this for a long time somehow. But the idea did not go further than writing special tests. I will definitely look at your code more carefully.

liuch added a commit that referenced this pull request Apr 10, 2025
@liuch
Copy link
Owner

liuch commented Apr 10, 2025

I just did a refactoring of the code related to database access. I believe now we can get rid of a lot of duplicated code.

@williamdes
Copy link
Contributor

I just did a refactoring of the code related to database access. I believe now we can get rid of a lot of duplicated code.

awesome !

@VilainMamuth can you rebase this PR and use the new abtractions ?

@liuch
Copy link
Owner

liuch commented Apr 13, 2025

@VilainMamuth Do I understand correctly that you have just merged your branch with this one, without removing excess code?

@VilainMamuth
Copy link
Author

I wanted to rebase my repo from yours but github's "Sync fork" button does the f... merge
I'll try to undo this commit on next week

@VilainMamuth
Copy link
Author

VilainMamuth commented Apr 25, 2025

hi, just a little follow up
code is refactored but now i'm facing an encoding issue i didn't have before :(

it seems related to inet_pton.
@liuch , why are you using this instead of INET4/6 MariaDb types ?

@liuch
Copy link
Owner

liuch commented Apr 26, 2025

why are you using this instead of INET4/6 MariaDb types ?

Because I wanted to depend on the database type as little as possible.

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.

3 participants