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
Support for raw SQL when using PostgreSQL or MariaDB/MySQL #31
Comments
Thanks for reporting! I'll update the documentation. Currently, I think the built-in methods must be used. It's also possible to use a plugin (that could use SQL), but I think that would be a bit cumbersome. External Lua code can be used if you use the What is the specific use case that you want to solve? |
Just trying to wrap my head around how to use Algernon with it's DB functionality, code samples with how to do standard CRUD operations would be great. I haven't had much luck with the help in the REPL, which the documentation seems to mirror. |
I should document this in more detail, but here is one example for using a list, regardless of which database backend is in use: https://github.com/xyproto/algernon/blob/master/samples/list/index.lua |
Thanks, what if I have a database with existing schema, how do I query/filter/sort it? Also are there any more comprehensive examples on JFile and JNode? |
Hello xyproto, |
Currently, there is no support from running SQL from Lua, but it can be done by writing a plugin for Algernon. |
Thanks, IMO without being able to run SQL queries against databases, it severely limits the usefulness of the server. |
The database backends are interchangeable, and the PostgreSQL and MariaDB/MySQL dialects are different (and PostgreSQL has the HSTORE feature). Currently, the same Lua code can be used regardless of which database backend is in use, whether it's PostgreSQL, Redis, BoltDB or a future backend that has not been added yet. Which SQL dialect do you think should be supported and which use case is not currently covered, either through the existing Lua functions or by using an Algernon plugin? |
It will be nice if you can provide an example plugin for raw database access to postgresql. |
Added a function for querying PostgreSQL databases. This does not have to be the same database as is used internally by Algernon, it can be any remote database as well. |
I'm not able to get it to work. My query doesn't execute to run and the results are
|
@mphuie Thanks for testing, It was a bug. It's fixed in master now. |
I can now query, but only can select a single column. This query works - My code
|
Thanks for testing! What would be the ideal return format, a Lua table of strings? A Lua table of strings and numbers? Or a Lua object that could be further queried? Or JSON? What is it typically being used for next, for inserting into a template or generating a table? If so, I could add a function for returning a Markdown table and one for returning a HTML table, for instance. The idea is to have quick and easy PostgreSQL support, with the option of writing a plugin for Algernon for more specialized usage. |
Just the ability to get full query results would be great, for me personally I just want to output JSON, however I'm fine with writing the code from |
It looks like the results of a query can only be a Line 110 in 895ebb2
|
Possibly instead of using Golang to do the execution, possibly include a Lua module/library instead? Or allow the user to import a library themselves? |
I will look into adding support for loading Lua modules. I think this will give more flexibility, while the |
It's not clear how the DB integration works-
Do you have to use the built in methods to write/access data or can you write SQL queries? Or do you have to write Lua code to make the connection? Also, how to imports/require work for external Lua modules?
Thanks
The text was updated successfully, but these errors were encountered: