Skip to content

[Flex] Provide conninfo to Lua script #1212

Description

@mmd-osm

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 same 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))

--- example only
res = assert (con:execute[[
        CREATE INDEX title_idx_nulls_low ON films (title NULLS FIRST)
]])

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");

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions