From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTP id 545AA2E88C for ; Sun, 26 May 2019 08:07:41 -0400 (EDT) Received: from turing.freelists.org ([127.0.0.1]) by localhost (turing.freelists.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Cbw7qKlZAHHT for ; Sun, 26 May 2019 08:07:41 -0400 (EDT) Received: from smtp14.mail.ru (smtp14.mail.ru [94.100.181.95]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTPS id EF54F2C75B for ; Sun, 26 May 2019 08:07:40 -0400 (EDT) Subject: [tarantool-patches] Re: [PATCH v5 6/6] box: user-friendly interface to manage ck constraints References: From: Vladislav Shpilevoy Message-ID: Date: Sun, 26 May 2019 15:07:39 +0300 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: tarantool-patches-bounce@freelists.org Errors-to: tarantool-patches-bounce@freelists.org Reply-To: tarantool-patches@freelists.org List-Help: List-Unsubscribe: List-software: Ecartis version 1.0.0 List-Id: tarantool-patches List-Subscribe: List-Owner: List-post: List-Archive: To: Kirill Shcherbatov , tarantool-patches@freelists.org Thanks for the patch! See 1 comment below. > diff --git a/src/box/lua/space.cc b/src/box/lua/space.cc > index 3e8f3b2e5..b375716c6 100644 > --- a/src/box/lua/space.cc > +++ b/src/box/lua/space.cc > @@ -28,6 +28,7 @@ > * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF > * SUCH DAMAGE. > */ > +#include "box/ck_constraint.h" > #include "box/lua/space.h" > #include "box/lua/tuple.h" > #include "box/lua/key_def.h" > @@ -147,6 +148,66 @@ lbox_space_before_replace(struct lua_State *L) > lbox_push_txn_stmt, lbox_pop_txn_stmt); > } > > +/** > + * Make ck_constraints available in Lua, via ck_constraint[] > + * array. > + * Updata a ck_constraint table in the parent space table object > + * on the Lua stack. > + */ > +static void > +lbox_ck_constraint(struct lua_State *L, struct space *space, int i) > +{ > + lua_getfield(L, i, "ck_constraint"); > + if (lua_isnil(L, -1)) { > + lua_pop(L, 1); > + lua_pushstring(L, "ck_constraint"); > + lua_newtable(L); > + lua_settable(L, i); > + lua_getfield(L, i, "ck_constraint"); > + } else { > + lua_pushnil(L); > + while (lua_next(L, -2) != 0) { > + size_t name_len; > + const char *name = lua_tolstring(L, -2, &name_len); > + /* > + * Remove ck_constraint only if it was > + * deleted. > + */ > + if (space_ck_constraint_by_name(space, name, > + (uint32_t)name_len) == NULL) { > + lua_pushlstring(L, name, name_len); > + lua_pushnil(L); > + lua_settable(L, -5); > + } > + lua_pop(L, 1); > + } > + } > + struct ck_constraint *ck_constraint = NULL; > + rlist_foreach_entry(ck_constraint, &space->ck_constraint, link) { > + lua_getfield(L, i, ck_constraint->def->name); > + if (lua_isnil(L, -1)) { > + lua_pop(L, 1); > + lua_pushstring(L, ck_constraint->def->name); > + lua_newtable(L); > + lua_settable(L, -3); > + lua_getfield(L, -1, ck_constraint->def->name); > + assert(!lua_isnil(L, -1)); > + } > + > + lua_pushstring(L, ck_constraint->def->name); > + lua_setfield(L, -2, "name"); > + > + lua_pushnumber(L, space->def->id); > + lua_setfield(L, -2, "space_id"); > + > + lua_pushstring(L, ck_constraint->def->expr_str); > + lua_setfield(L, -2, "expr_str"); 1. I think, 'expr' is better name. What else except 'str' you can expose? - nothing. It means, that '_str' suffix is redundant, IMO. > + > + lua_setfield(L, -2, ck_constraint->def->name); > + } > + lua_pop(L, 1); > +}