@@ -18,18 +18,20 @@ to extract or compare the index key values.
1818 Create a new key_def instance.
1919
2020 :param table parts: field numbers and types.
21- There must be at least one part and it
22- must have at least fieldno and type.
21+ There must be at least one part.
22+ Every part must have the attributes ``type `` and ``fieldno ``/``field ``.
23+ Other attributes are optional.
2324
2425 :returns: key_def-object :ref: `a key_def object <key_def-object >`
2526
2627 The parts table has components which are the same as
2728 the ``parts `` option in
2829 :ref: `Options for space_object:create_index() <box_space-create_index-options >`.
2930
30- fieldno (integer) for example fieldno = 1. It is legal to say field instead of fieldno.
31+ ``fieldno `` (integer) for example ``fieldno = 1 ``.
32+ It is legal to use ``field `` instead of ``fieldno ``.
3133
32- type (string) for example type = 'string'.
34+ `` type `` (string) for example `` type = 'string' `` .
3335
3436 Other components are optional.
3537
@@ -54,15 +56,15 @@ to extract or compare the index key values.
5456
5557 .. method :: extract_key(tuple)
5658
57- Return a tuple containing only the fields of the key_def object.
59+ Return a tuple containing only the fields of the `` key_def `` object.
5860
5961 :param table tuple: tuple or Lua table with field contents
6062
61- :return: the fields that were defined for the key_def object
63+ :return: the fields that were defined for the `` key_def `` object
6264
6365 **Example #1: **
6466
65- .. code-block :: none
67+ .. code-block :: tarantoolsession
6668
6769 -- Suppose that an item has five fields
6870 -- 1, 99.5, 'X', nil, 99.5
@@ -76,7 +78,7 @@ to extract or compare the index key values.
7678 ...
7779
7880 tarantool> k = key_def.new({{type = 'string', fieldno = 3},
79- > {type = 'unsigned', fieldno =1 }})
81+ > {type = 'unsigned', fieldno = 1 }})
8082 ---
8183 ...
8284
@@ -87,7 +89,7 @@ to extract or compare the index key values.
8789
8890 **Example #2 **
8991
90- .. code-block :: none
92+ .. code-block :: lua
9193
9294 -- Now suppose that the item is a tuple in a space which
9395 -- has an index on field #3 plus field #1.
@@ -96,14 +98,14 @@ to extract or compare the index key values.
9698 -- The result will be the same.
9799 key_def = require('key_def')
98100 box.schema.space.create('T')
99- i = box.space.T:create_index('I',{parts={3,'string',1, 'unsigned'}})
101+ i = box.space.T:create_index('I', {parts={3, 'string', 1, 'unsigned'}})
100102 box.space.T:insert{1, 99.5, 'X', nil, 99.5}
101103 k = key_def.new(i.parts)
102104 k:extract_key(box.space.T:get({'X', 1}))
103105
104106 **Example #3 **
105107
106- .. code-block :: none
108+ .. code-block :: lua
107109
108110 -- Iterate through the tuples in a secondary non-unique index.
109111 -- extracting the tuples' primary-key values so they can be deleted
@@ -125,11 +127,11 @@ to extract or compare the index key values.
125127
126128 .. method :: compare(tuple_1, tuple_2)
127129
128- Compare the key fields of tuple_1 to the key fields of tuple_2.
130+ Compare the key fields of `` tuple_1 `` to the key fields of `` tuple_2 `` .
129131 This is a tuple-by-tuple comparison so users do not have to
130132 write code which compares a field at a time.
131133 Each field's type and collation will be taken into account.
132- In effect it is a comparison of extract_key(tuple_1) with extract_key(tuple_2).
134+ In effect it is a comparison of `` extract_key(tuple_1) `` with `` extract_key(tuple_2) `` .
133135
134136 :param table tuple1: tuple or Lua table with field contents
135137 :param table tuple2: tuple or Lua table with field contents
@@ -140,22 +142,22 @@ to extract or compare the index key values.
140142
141143 **Example: **
142144
143- .. code-block :: none
145+ .. code-block :: lua
144146
145147 -- This will return 0
146148 key_def = require('key_def')
147- k = key_def.new({{type= 'string',fieldno=3, collation= 'unicode_ci'},
148- {type= 'unsigned',fieldno= 1}})
149+ k = key_def.new({{type = 'string', fieldno = 3, collation = 'unicode_ci'},
150+ {type = 'unsigned', fieldno = 1}})
149151 k:compare({1, 99.5, 'X', nil, 99.5}, {1, 99.5, 'x', nil, 99.5})
150152
151153 .. _key_def-compare_with_key :
152154
153155 .. method :: compare_with_key(tuple_1, tuple_2)
154156
155- Compare the key fields of tuple_1 to all the fields of tuple_2.
157+ Compare the key fields of `` tuple_1 `` to all the fields of `` tuple_2 `` .
156158 This is the same as :ref: `key_def_object:compare() <key_def-compare >`
157- except that tuple_2 contains only the key fields.
158- In effect it is a comparison of extract_key(tuple_1) with tuple_2.
159+ except that `` tuple_2 `` contains only the key fields.
160+ In effect it is a comparison of `` extract_key(tuple_1) `` with `` tuple_2 `` .
159161
160162 :param table tuple1: tuple or Lua table with field contents
161163 :param table tuple2: tuple or Lua table with field contents
@@ -166,32 +168,32 @@ to extract or compare the index key values.
166168
167169 **Example: **
168170
169- .. code-block :: none
171+ .. code-block :: lua
170172
171173 -- This will return 0
172174 key_def = require('key_def')
173- k = key_def.new({{type= 'string',fieldno=3, collation= 'unicode_ci'},
174- {type= 'unsigned',fieldno= 1}})
175+ k = key_def.new({{type = 'string', fieldno = 3, collation = 'unicode_ci'},
176+ {type = 'unsigned', fieldno = 1}})
175177 k:compare_with_key({1, 99.5, 'X', nil, 99.5}, {'x', 1})
176178
177179 .. _key_def-merge :
178180
179181 .. method :: merge (other_key_def_object)
180182
181- Combine the main key_def_object with other_key_def_object.
182- The return value is a new key_def_object containing all the fields of
183- the main key_def_object, then all the fields of other_key_def_object which
184- are not in the main key_def_object.
183+ Combine the main `` key_def_object `` with `` other_key_def_object `` .
184+ The return value is a new `` key_def_object `` containing all the fields of
185+ the main `` key_def_object `` , then all the fields of `` other_key_def_object `` which
186+ are not in the main `` key_def_object `` .
185187
186188 :param key_def_object other_key_def_object: definition of fields to add
187189
188190 :return: key_def_object
189191
190192 **Example: **
191193
192- .. code-block :: none
194+ .. code-block :: lua
193195
194- -- This will return a key definition with fieldno= 3 and fieldno= 1.
196+ -- This will return a key definition with fieldno = 3 and fieldno = 1.
195197 key_def = require('key_def')
196198 k = key_def.new({{type = 'string', fieldno = 3}})
197199 k2= key_def.new({{type = 'unsigned', fieldno = 1},
@@ -202,21 +204,21 @@ to extract or compare the index key values.
202204
203205 .. method :: totable()
204206
205- Return a table containing what is in the key_def_object.
207+ Return a table containing what is in the `` key_def_object `` .
206208 This is the reverse of ``key_def.new() ``:
207209
208- * ``key_def.new() `` takes a table and returns a key_def object,
209- * ``key_def_object:totable() `` takes a key_def object and returns a table.
210+ * ``key_def.new() `` takes a table and returns a `` key_def `` object,
211+ * ``key_def_object:totable() `` takes a `` key_def `` object and returns a table.
210212
211213 This is useful for input to ``_serialize `` methods.
212214
213215 :return: table
214216
215217 **Example: **
216218
217- .. code-block :: none
219+ .. code-block :: lua
218220
219- -- This will return a table with type= 'string', fieldno= 3
221+ -- This will return a table with type = 'string', fieldno = 3
220222 key_def = require('key_def')
221223 k = key_def.new({{type = 'string', fieldno = 3}})
222224 k:totable()
0 commit comments