From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Date: Tue, 18 Jun 2019 12:00:42 +0300 From: Vladimir Davydov Subject: Re: [PATCH v1 2/2] netbox: define formats for tuple from netbox Message-ID: <20190618090042.cuzqje3n62qyhfdp@esperanza> References: <82d7940c4420df06b6e905304f27797d4d348329.1560160282.git.imeevma@gmail.com> <20190611085511.jto7yyuognolqg3b@esperanza> <20190614122920.GA3535@tarantool.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190614122920.GA3535@tarantool.org> To: Mergen Imeev Cc: tarantool-patches@freelists.org List-ID: On Fri, Jun 14, 2019 at 03:29:21PM +0300, Mergen Imeev wrote: > Second new patch: > > From f9e959e3f0f38e8f6b8f1294ba29c28d41f30968 Mon Sep 17 00:00:00 2001 > Date: Tue, 11 Jun 2019 16:36:39 +0300 > Subject: [PATCH] netbox: define formats for tuple from netbox > > This patch creates tuple_formats for the tuples obtained through > the netbox. > > Closes #2978 > > @TarantoolBot document > Title: Field names for tuples received from net.box > > It is possible now to access by field name for tuples received > from net.box. For example: > > box.cfg{listen = 3302} > box.schema.user.grant('guest','read, write, execute', 'space') > box.schema.user.grant('guest', 'create', 'space') > > box.schema.create_space("named", {format = {{name = "id"}}}) > box.space.named:create_index('id', {parts = {{1, 'unsigned'}}}) > box.space.named:insert({1}) > require('net.box').connect('localhost', 3302).space.named:get(1).id > > Result: > > tarantool> require('net.box').connect('localhost', 3302).space.named:get(1).id > --- > - 1 > ... > > diff --git a/src/box/lua/net_box.c b/src/box/lua/net_box.c > index 7484a86..946d397 100644 > --- a/src/box/lua/net_box.c > +++ b/src/box/lua/net_box.c > @@ -590,12 +590,11 @@ netbox_encode_execute(lua_State *L) > * @param data MessagePack. > */ > static void > -netbox_decode_data(struct lua_State *L, const char **data) > +netbox_decode_data(struct lua_State *L, const char **data, > + struct tuple_format *format) > { > uint32_t count = mp_decode_array(data); > lua_createtable(L, count, 0); > - struct tuple_format *format = > - box_tuple_format_default(); > for (uint32_t j = 0; j < count; ++j) { > const char *begin = *data; > mp_next(data); > @@ -618,6 +617,15 @@ static int > netbox_decode_select(struct lua_State *L) > { > uint32_t ctypeid; > + int top = lua_gettop(L); > + assert(top == 1 || top == 2); > + struct tuple_format *format; > + if (top == 2 && lua_type(L, 2) == LUA_TCDATA) { > + format = *(struct tuple_format **)luaL_checkcdata(L, 2, > + &ctypeid); I think we should use lbox_check_tuple_format helper from the previous patch here. Other than that, this patch looks good to me. > + } else { > + format = tuple_format_runtime; > + } > const char *data = *(const char **)luaL_checkcdata(L, 1, &ctypeid); > assert(mp_typeof(*data) == MP_MAP); > uint32_t map_size = mp_decode_map(&data);