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

INSERT SQL is MySQL specific #145

Closed
lllama opened this issue Apr 4, 2019 · 9 comments
Closed

INSERT SQL is MySQL specific #145

lllama opened this issue Apr 4, 2019 · 9 comments

Comments

@lllama
Copy link
Contributor

lllama commented Apr 4, 2019

The INSERT statement in the SQL backend is specific. In particular, changing the backend to postgres results in SQL error.

The two main changes to make are:

  1. backticks need to be replaced with double quotes
  2. ? placeholders need to be replaced with $x, where x increments.

I'm not sure whether it's possible to replace the SQL with something more cross-platform or whether there is the need for DB specific backends.

@flashmob
Copy link
Owner

flashmob commented Apr 4, 2019

Thanks for the info, didn't know about the backticks and placeholders. You're welcome to attempt to change it to a more cross platform query, then post it here, so it can be tested with MySQL. Also would welcome to suggest any other solutions, eg. recommend an ORM or something similar that's more cross platform.

@flashmob
Copy link
Owner

flashmob commented Apr 4, 2019

Another idea would be to refactor prepareInsertQuery to allow the SQL query to be configurable via the config?

@lllama
Copy link
Contributor Author

lllama commented Apr 8, 2019

So I have something working in my backend which takes the SQL from the config. I'm marking it as omitempty, as I think that would allow a fallback to the MySQL statement. The current implementation requires sql_insert and sql_values config values as there is a requirement for multiple row inserts. I don't think this is a major issue as it allows for some additional customisation of the SQL but does require two variables to be configured, which has the potential to be confusing.

I'll look to get a pull request done asap.

@flashmob
Copy link
Owner

flashmob commented Apr 8, 2019

Thanks for the update, sounds good.

@lllama
Copy link
Contributor Author

lllama commented Jun 20, 2019

The SQL insert statement can now be changed in the config thanks to #157, so I'll close this.

@lllama lllama closed this as completed Jun 20, 2019
@lord-alfred
Copy link
Contributor

In wiki page: https://github.com/flashmob/go-guerrilla/wiki/Configuration-example:-save-to-Redis-&-MySQL

There are incorrect variables for config. Need sql_insert and sql_values, not SQLInsert and SQLValues

@flashmob
Copy link
Owner

flashmob commented Aug 2, 2019 via email

@lllama
Copy link
Contributor Author

lllama commented Nov 14, 2019

You can now define your own SQL statement in the config. Have a look at the wiki page or pull request linked above

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

No branches or pull requests

4 participants
@lllama @flashmob @lord-alfred and others