[Tile-serving] [openstreetmap/osm2pgsql] [Flex] Provide conninfo to Lua script (#1212)
mmd
notifications at github.com
Sat Jun 13 08:42:03 UTC 2020
This relates a bit to #1211. Assuming we want to create additional indices, or use database lookups, etc., it would be useful to have access to the database connection information that the C++ code uses, and leverage a library like `luasql.postgres` :
```
luasql = require "luasql.postgres"
envv = assert (luasql.postgres())
con = assert (envv:connect(osm2pgsql.conninfo))
res = con:execute("DROP TABLE people")
res = assert (con:execute[[
CREATE TABLE people(
id bigint,
key text,
value text
)
]])
```
Maybe this one liner would be sufficient? There's one caveat: conninfo might contain a password. Not sure, if we can assume Lua scripts to be trustworthy enough here.
```
diff --git a/src/output-flex.cpp b/src/output-flex.cpp
index 4c7afd3e..ad43d349 100644
--- a/src/output-flex.cpp
+++ b/src/output-flex.cpp
@@ -1273,6 +1273,7 @@ void output_flex_t::init_lua(std::string const &filename)
luaX_add_table_func(lua_state(), "define_table",
lua_trampoline_app_define_table);
luaX_add_table_func(lua_state(), "mark", lua_trampoline_app_mark);
+ luaX_add_table_str(lua_state(), "conninfo", m_options.database_options.conninfo().c_str());
lua_setglobal(lua_state(), "osm2pgsql");
```
--
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/openstreetmap/osm2pgsql/issues/1212
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openstreetmap.org/pipermail/tile-serving/attachments/20200613/216fd764/attachment-0001.htm>
More information about the Tile-serving
mailing list