# HG changeset patch # User jbe # Date 1447633982 -3600 # Node ID 16baed4c0483740055c8c9e6810e1cfb696c15f8 # Parent 4b1d88f77ab80041679b3902808b95a3274b1a29 Extended _column_info table to be an associative array as well (in addition to a sequence); Allow direct (proxy) access to fields of JSON object in a special column (completed write access) diff -r 4b1d88f77ab8 -r 16baed4c0483 libraries/mondelefant/mondelefant_native.c --- a/libraries/mondelefant/mondelefant_native.c Mon Nov 16 01:01:51 2015 +0100 +++ b/libraries/mondelefant/mondelefant_native.c Mon Nov 16 01:33:02 2015 +0100 @@ -1012,8 +1012,12 @@ lua_newtable(L); // 6 for (col = 0; col < cols; col++) { lua_newtable(L); // 7 - lua_pushstring(L, PQfname(res, col)); + lua_pushstring(L, PQfname(res, col)); // 8 + lua_pushvalue(L, 8); // 9 + lua_pushvalue(L, 7); // 10 + lua_rawset(L, 6); lua_setfield(L, 7, "field_name"); + // _column_info entry (for current column) on stack position 7 { Oid tmp; tmp = PQftable(res, col); @@ -1690,6 +1694,26 @@ return 0; } lua_settop(L, 5); + // check proxy access to document in special column: + if (lua_toboolean(L, 4)) { + lua_getfield(L, 1, "_column_info"); // 6 + lua_pushvalue(L, 2); // 7 + lua_gettable(L, 6); // 7 + if (lua_toboolean(L, 7)) { + lua_settop(L, 5); + lua_pushvalue(L, 4); // 6 + // _data table is on stack position 5 + // document column name is on stack position 4 and 6 + lua_gettable(L, 5); // 6 + if (!lua_isnil(L, 6)) { + lua_pushvalue(L, 2); // 7 + lua_pushvalue(L, 3); // 8 + lua_settable(L, 6); + return 0; + } + } + lua_settop(L, 5); + } // store value in data field info: lua_pushvalue(L, 2); // 6 lua_pushvalue(L, 3); // 7