From 8c48d037a0ee65f4215948fa3c7fd8297da6f65b Mon Sep 17 00:00:00 2001 From: Alexey Romanov Date: Thu, 21 Jan 2021 21:26:41 +0300 Subject: [PATCH 01/11] ADD: some examples of select && pairs --- README.md | 4 +++ doc/pairs.md | 33 ++++++++++++++++++++ doc/select.md | 84 +++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 121 insertions(+) create mode 100644 doc/pairs.md create mode 100644 doc/select.md diff --git a/README.md b/README.md index 856fb740..ac2e9e67 100644 --- a/README.md +++ b/README.md @@ -347,6 +347,8 @@ crud.select('customers', {{'<=', 'age', 35}}) **Note**: tuples are sorted by age because space has index `age`. Otherwise, tuples are sorted by primary key. +See more examples of select queries [here.](https://github.com/tarantool/crud/docs/select.md) + ### Pairs You can iterate across a distributed space using the `crud.pairs` function. @@ -370,6 +372,8 @@ for _, object in crud.pairs('customers', {{'<=', 'age', 35}}, {use_tomap = true} end ``` +See more examples of pairs queries [here.](https://github.com/tarantool/crud/docs/pairs.md) + ### Truncate ```lua diff --git a/doc/pairs.md b/doc/pairs.md new file mode 100644 index 00000000..9ffeeaa6 --- /dev/null +++ b/doc/pairs.md @@ -0,0 +1,33 @@ +# Pairs examples + +## Lua Fun + +Queries using pairs support the [Lua Fun](https://github.com/luafun/luafun) library. Some examples of working with basic functional functions below. + +**Filter example:** +```lua +local objects = {} +for _, obj in fun.filter(function(x) return x.age % 5 == 0 end, crud.pairs('customers', {{'==', 'name', 'Alexey'}}, {use_tomap = true})) do + table.insert(objects, obj) +end +``` + +**Reduce (foldl) example:** +```lua +local age_sum = fun.reduce(function(acc, x) return acc + x.age end, 0, crud.pairs('customers', nil, {use_tomap = true})) +``` + +**Map example:** +```lua +local objects = {} +for _, obj in fun.map(function(x) return {obj.id, obj.name, obj.age * 2} end, crud.pairs('customers', nil, {use_tomap = true})) +``` + +**Take example**: + +```lua +local tuples = {} +for _, tuple in fun.take(3, crud.pairs('customers', {{'>=', 'age', 18}})) do + table.insert(tuples, tuple) +end +``` diff --git a/doc/select.md b/doc/select.md new file mode 100644 index 00000000..dd0a1c0a --- /dev/null +++ b/doc/select.md @@ -0,0 +1,84 @@ +# Select examples + +## Pagination + +Select supports pagination. To use it, use the [``after``](https://github.com/tarantool/crud#select) and [``first``](https://github.com/tarantool/crud#select) parameter. + +**Example**: + +```lua +res, err = crud.select('developers', nil, { first = 3 }) +res.rows +--- +- - [1, 7331, 'Alexey', 20] + - [2, 899, 'Sergey', 21] + - [3, 9661, 'Pavel', 27] +... +res, err = crud.select('developers', nil, { after = res.rows[3], first = 3 }) +res.rows +--- +- - [4, 501, 'Mikhail', 31] + - [5, 1997, 'Dmitry', 16] + - [6, 8765, 'Artyom', 51] +... +``` + +Select also supports reverse pagination. + +**Example**: + +```lua +res, err = crud.select('developers', nil, { after = res.rows[3], first = 3 }) +res.rows +--- +- - [4, 501, 'Mikhail', 31] + - [5, 1997, 'Dmitry', 16] + - [6, 8765, 'Artyom', 51] +... +res, err = crud.select('developers', nil, { after = res.rows[1], first = -3 }) +res.rows +--- +- - [1, 7331, 'Alexey', 20] + - [2, 899, 'Sergey', 21] + - [3, 9661, 'Pavel', 27] +... +``` + +## Select using composite index + +Suppose we have a composite index consisting of the ``name`` and ``surname`` fields. See example of select queries using such a composited index below. + +**Example**: + +```lua +crud.select('customers', {{'==', 'full_name', {"John", "Sidorov"}}}) +--- +- metadata: + - {'name': 'id', 'type': 'unsigned'} + - {'name': 'bucked_id', 'type': 'unsigned'} + - {'name': 'name', 'type': 'string'} + - {'name': 'surname', 'type': 'string'} + - {'name': 'age', 'type': 'number'} + rows: + - [37, 2364, 'John', 'Sidorov', 28] +... +``` + +Alternatively, you can use a partial key for a composite index. + +**Example**: + +```lua +crud.select('customers', {{'==', 'full_name', "John"}}) +--- +- metadata: + - {'name': 'id', 'type': 'unsigned'} + - {'name': 'bucked_id', 'type': 'unsigned'} + - {'name': 'name', 'type': 'string'} + - {'name': 'surname', 'type': 'string'} + - {'name': 'age', 'type': 'number'} + rows: + - [37, 2364, 'John', 'Sidorov', 28] + - [99, 635, 'John', 'Adams', 65] +... +``` From f0a51c35d5a2453347f30b1e18db3c4e3719c46b Mon Sep 17 00:00:00 2001 From: Alexey Romanov Date: Thu, 21 Jan 2021 21:34:47 +0300 Subject: [PATCH 02/11] a little fix --- doc/pairs.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/doc/pairs.md b/doc/pairs.md index 9ffeeaa6..84a70ab5 100644 --- a/doc/pairs.md +++ b/doc/pairs.md @@ -21,6 +21,8 @@ local age_sum = fun.reduce(function(acc, x) return acc + x.age end, 0, crud.pair ```lua local objects = {} for _, obj in fun.map(function(x) return {obj.id, obj.name, obj.age * 2} end, crud.pairs('customers', nil, {use_tomap = true})) + table.insert(objects, obj) +end ``` **Take example**: From 84c3c4863596f314b63475ca43c89a1c27249d04 Mon Sep 17 00:00:00 2001 From: Alexey Romanov Date: Mon, 25 Jan 2021 15:13:54 +0300 Subject: [PATCH 03/11] Fix some PR issues --- doc/select.md | 162 ++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 123 insertions(+), 39 deletions(-) diff --git a/doc/select.md b/doc/select.md index dd0a1c0a..4e55063c 100644 --- a/doc/select.md +++ b/doc/select.md @@ -1,84 +1,168 @@ # Select examples -## Pagination +## Filtering -Select supports pagination. To use it, use the [``after``](https://github.com/tarantool/crud#select) and [``first``](https://github.com/tarantool/crud#select) parameter. +The second parameter passed to ``crud.select`` is an array of conditions. Below are examples of filtering data using these conditions. -**Example**: +### Getting full space + +To get a full space without filtering, you need to pass nil as a condition. + +**Example:** ```lua -res, err = crud.select('developers', nil, { first = 3 }) +crud.select('customers', nil) +--- +- metadata: + - {'name': 'id', 'type': 'unsigned'} + - {'name': 'bucked_id', 'type': 'unsigned'} + - {'name': 'name', 'type': 'string'} + - {'name': 'surname', 'type': 'string'} + - {'name': 'age', 'type': 'number'} + rows: + - [1, 635, 'John', 'Adams', 65] + - [2, 2364, 'John', 'Sidorov', 28] + - [3, 6517, 'Ronald', 'Dump', 77] + - [4, 563, 'Sergey', 'Lee', 21] + - [5, 2313, 'Tatyana', 'May', 20] +... +``` + +### Select using index + +Let's say we have a ``age`` index. Example below + +**Example:** + +```lua +res, err = crud.select('customers', {{'>=', 'age', 30}}) res.rows --- -- - [1, 7331, 'Alexey', 20] - - [2, 899, 'Sergey', 21] - - [3, 9661, 'Pavel', 27] +- - [1, 635, 'John', 'Adams', 65] + - [3, 6517, 'Ronald', 'Dump', 77] ... -res, err = crud.select('developers', nil, { after = res.rows[3], first = 3 }) +``` + +### Select using composite index + +Suppose we have a composite index consisting of the ``name`` and ``surname`` fields. See example of select queries using such a composited index below. + +**Example**: + +```lua +res, err = crud.select('customers', {{'==', 'full_name', {"John", "Sidorov"}}}) res.rows --- -- - [4, 501, 'Mikhail', 31] - - [5, 1997, 'Dmitry', 16] - - [6, 8765, 'Artyom', 51] +- - [1, 2364, 'John', 'Sidorov', 28] ... ``` -Select also supports reverse pagination. +### Select using partial key + +Alternatively, you can use a partial key for a composite index. **Example**: ```lua -res, err = crud.select('developers', nil, { after = res.rows[3], first = 3 }) +res, err = crud.select('customers', {{'==', 'full_name', "John"}}) res.rows --- -- - [4, 501, 'Mikhail', 31] - - [5, 1997, 'Dmitry', 16] - - [6, 8765, 'Artyom', 51] +- - [1, 2364, 'John', 'Sidorov', 28] + - [2, 635, 'John', 'Adams', 65] ... -res, err = crud.select('developers', nil, { after = res.rows[1], first = -3 }) +``` + +### Select using non-indexed field + +**Example:** + +```lua +res, err = crud.select('customers', {{'>=', 'id', 3}}) res.rows --- -- - [1, 7331, 'Alexey', 20] - - [2, 899, 'Sergey', 21] - - [3, 9661, 'Pavel', 27] +- - [3, 6517, 'Ronald', 'Dump', 77] + - [4, 563, 'Sergey', 'Lee', 21] + - [5, 2313, 'Tatyana', 'May', 20] ... ``` -## Select using composite index +**Note:** -Suppose we have a composite index consisting of the ``name`` and ``surname`` fields. See example of select queries using such a composited index below. +## Pagination -**Example**: +### First parameter + +**Example:** ```lua -crud.select('customers', {{'==', 'full_name', {"John", "Sidorov"}}}) ---- +crud.select('developers', nil, { first = 3 }) - metadata: - {'name': 'id', 'type': 'unsigned'} - {'name': 'bucked_id', 'type': 'unsigned'} - {'name': 'name', 'type': 'string'} - - {'name': 'surname', 'type': 'string'} - {'name': 'age', 'type': 'number'} rows: - - [37, 2364, 'John', 'Sidorov', 28] + - [1, 7331, 'Alexey', 20] + - [2, 899, 'Sergey', 21] + - [3, 9661, 'Pavel', 27] ... ``` -Alternatively, you can use a partial key for a composite index. +### After parameter -**Example**: +**Example:** ```lua -crud.select('customers', {{'==', 'full_name', "John"}}) +res, err = crud.select('developers', nil, { after = res.rows[3] }) +res.rows --- -- metadata: - - {'name': 'id', 'type': 'unsigned'} - - {'name': 'bucked_id', 'type': 'unsigned'} - - {'name': 'name', 'type': 'string'} - - {'name': 'surname', 'type': 'string'} - - {'name': 'age', 'type': 'number'} - rows: - - [37, 2364, 'John', 'Sidorov', 28] - - [99, 635, 'John', 'Adams', 65] +- - [4, 501, 'Mikhail', 31] + - [5, 1997, 'Dmitry', 16] + - [6, 8765, 'Artyom', 51] +``` + +### Combine first and after parameters + +Select supports pagination. To use it, we have to combine ``after`` and ``first`` parameters. + +**Example:** + +```lua +res, err = crud.select('developers', nil, { first = 3 }) +res.rows +--- +- - [1, 7331, 'Alexey', 20] + - [2, 899, 'Sergey', 21] + - [3, 9661, 'Pavel', 27] +... +res, err = crud.select('developers', nil, { after = res.rows[3], first = 3 }) +res.rows +--- +- - [4, 501, 'Mikhail', 31] + - [5, 1997, 'Dmitry', 16] + - [6, 8765, 'Artyom', 51] +... +``` + +### Reverse pagination + +Select also supports reverse pagination. + +**Example:** + +```lua +res, err = crud.select('developers', nil, { after = res.rows[3], first = 3 }) +res.rows +--- +- - [4, 501, 'Mikhail', 31] + - [5, 1997, 'Dmitry', 16] + - [6, 8765, 'Artyom', 51] +... +res, err = crud.select('developers', nil, { after = res.rows[1], first = -3 }) +res.rows +--- +- - [1, 7331, 'Alexey', 20] + - [2, 899, 'Sergey', 21] + - [3, 9661, 'Pavel', 27] ... ``` From 3393759e1361c86a161365628b66d8bb8b189691 Mon Sep 17 00:00:00 2001 From: Alexey Romanov Date: Mon, 25 Jan 2021 16:58:15 +0300 Subject: [PATCH 04/11] Get select examples more informative --- doc/select.md | 56 ++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 46 insertions(+), 10 deletions(-) diff --git a/doc/select.md b/doc/select.md index 4e55063c..6ccb3f6f 100644 --- a/doc/select.md +++ b/doc/select.md @@ -6,7 +6,7 @@ The second parameter passed to ``crud.select`` is an array of conditions. Below ### Getting full space -To get a full space without filtering, you need to pass nil as a condition. +To get a full space without filtering, you need to pass ``nil`` as a condition. **Example:** @@ -30,7 +30,7 @@ crud.select('customers', nil) ### Select using index -Let's say we have a ``age`` index. Example below +Let's say we have a ``age`` index. Example below gets a list of ``customers`` over 30 years old. **Example:** @@ -74,6 +74,8 @@ res.rows ### Select using non-indexed field +You can also make a selection using a non-indexed field. + **Example:** ```lua @@ -86,11 +88,39 @@ res.rows ... ``` -**Note:** +**Note:** in this case full scan is performed. + +Note that the search condition for the indexed field must be placed first to avoi a full scan. + +**Example:** + +```lua +res, err = crud.select('customers', {{'>=', 'id', 3}, {'>=', 'age', 30}}) +res.rows +--- +- - [3, 6517, 'Ronald', 'Dump', 77] +... +``` + +In this case, a full scan will be performed, since non-indexed field is placed first in search conditions. Example below shows how you can avoid a full scan. + +**Example:** + +```lua +res, err = crud.select('customers', {{'>=', 'age', 30}, {'>=', 'id', 3}}) +res.rows +--- +- - [3, 6517, 'Ronald', 'Dump', 77] +... +``` ## Pagination -### First parameter +The third (but optional) parameter in ``crud.select`` is array of [``options``](https://github.com/tarantool/crud#select). With this parameter, we can implement pagination. + +### ``First`` parameter + +Using the ``first`` option we will get the first **N** results for the query. **Example:** @@ -108,7 +138,11 @@ crud.select('developers', nil, { first = 3 }) ... ``` -### After parameter +Thus, we got the first three objects from the ``developers`` space. + +### ``After`` parameter + +Using ``after``, we can get the objects after specified tuple. **Example:** @@ -121,23 +155,25 @@ res.rows - [6, 8765, 'Artyom', 51] ``` -### Combine first and after parameters +With this request, we got objects behind the objects from the [previous example](https://github.com/crud/doc/select#first-parameter) -Select supports pagination. To use it, we have to combine ``after`` and ``first`` parameters. +### Combine ``first`` and ``after`` + +To use pagination, we have to combine ``after`` and ``first`` parameters. **Example:** ```lua res, err = crud.select('developers', nil, { first = 3 }) res.rows ---- +--- Got first three objects - - [1, 7331, 'Alexey', 20] - [2, 899, 'Sergey', 21] - [3, 9661, 'Pavel', 27] ... res, err = crud.select('developers', nil, { after = res.rows[3], first = 3 }) res.rows ---- +--- Get the next three objects - - [4, 501, 'Mikhail', 31] - [5, 1997, 'Dmitry', 16] - [6, 8765, 'Artyom', 51] @@ -146,7 +182,7 @@ res.rows ### Reverse pagination -Select also supports reverse pagination. +Select also supports reverse pagination. To use it, pass a negative value to the ``first`` parameter. **Example:** From 55e1ff77656d4fe55c2ba5cf73a9dc0b2affa882 Mon Sep 17 00:00:00 2001 From: Alexey Romanov Date: Mon, 25 Jan 2021 19:15:27 +0300 Subject: [PATCH 05/11] Add some pairs examples --- doc/pairs.md | 122 ++++++++++++++++++++++++++++++++++++++++++++++---- doc/select.md | 2 +- 2 files changed, 115 insertions(+), 9 deletions(-) diff --git a/doc/pairs.md b/doc/pairs.md index 84a70ab5..a73f5fa7 100644 --- a/doc/pairs.md +++ b/doc/pairs.md @@ -1,35 +1,141 @@ # Pairs examples +With ``crud.pairs``, you can iterate across a distributed space. The arguments are the same as [``crud.select``](https://github.com/tarantool/crud/docs/select.md), except or the ``use_tomap`` parameter. Below are examples that may help you. + +## ``Use_tomap`` parameter + +With ``use_tomap`` flag, you can choose to iterate over objects or over tuples. If ``use_tomap = false``, you will iterate over tuples. This parameter is false by default. + +**Example:** + +```lua +tuples = {} +for _, tuple in crud.pairs('customers', nil, {use_tomap = false}) do + table.insert(tuples, tuple) +end + +tuples +--- +- - - 1 + - 2313 + - Alexey + - 20 + - - 2 + - 241 + - Vladimir + - 18 + - - 3 + - 571 + - Alexander + - 24 +... +``` + +If ``use_tomap = true``, you will iterate over objects. + +**Example:** + +```lua +objects = {} +for _, obj in crud.pairs('customers', nil, {use_tomap = true}) do + table.insert(tuples, tuple) +end + +objects +--- +- - id: 1 + bucket_id: 2313 + name: Alexey + age: 20 + - id: 2 + bucket_id: 241 + name: Vladimir + age: 14 + - id: 3 + bucket_id: 571 + name: Alexander + age: 24 +... +``` + +## Pagination + +``crud.pairs``, like [``crud.select``](https://github.com/tarantool/crud/doc/select#pagination), supports pagination. To use it, combine the ``first`` and ``after`` parameters. + +**Example:** + +```lua +TODO +``` + +Note that ``crud.pairs``, unlike ``crud.select``, **don't support reverse pagination.** + ## Lua Fun -Queries using pairs support the [Lua Fun](https://github.com/luafun/luafun) library. Some examples of working with basic functional functions below. +[``Pairs``](https://github.com/tarantool/crud#pairs) is [Lua Fun](https://github.com/luafun/luafun) compatible. Some examples of working with basic functional functions below. **Filter example:** + ```lua -local objects = {} -for _, obj in fun.filter(function(x) return x.age % 5 == 0 end, crud.pairs('customers', {{'==', 'name', 'Alexey'}}, {use_tomap = true})) do +objects = {} +for _, obj in crud.pairs('customers', {{'>=', 'age', 20}}, {use_tomap = true}):filter(function(x) return x.age % 5 == 0 end) do table.insert(objects, obj) end + +objects +--- +- - id: 1 + bucket_id: 2313 + name: Alexey + age: 20 +... ``` **Reduce (foldl) example:** + ```lua -local age_sum = fun.reduce(function(acc, x) return acc + x.age end, 0, crud.pairs('customers', nil, {use_tomap = true})) +age_sum = crud.pairs('customers', nil, {use_tomap = true}):reduce(function(acc, x) return acc + x.age end, 0) +age_sum +--- +- 30 +.... ``` **Map example:** + ```lua -local objects = {} -for _, obj in fun.map(function(x) return {obj.id, obj.name, obj.age * 2} end, crud.pairs('customers', nil, {use_tomap = true})) +objects = {} +for _, obj in crud.pairs('customers', nil, {use_tomap = true}):map(function(x) return {id = obj.id, name = obj.name, age = obj.age * 2}) do table.insert(objects, obj) end + +objects +--- +- - id: 1 + name: Alexey + age: 40 + - id: 2 + name: Vladimir + age: 28 + - id: 3 + name: Alexander + age: 48 +... ``` **Take example**: ```lua -local tuples = {} -for _, tuple in fun.take(3, crud.pairs('customers', {{'>=', 'age', 18}})) do +tuples = {} +for _, tuple in crud.pairs('customers', {{'>=', 'age', 18}}):take(1) do table.insert(tuples, tuple) end + +tuples +--- +- - - 1 + - 2313 + - Alexey + - 20 +... ``` diff --git a/doc/select.md b/doc/select.md index 6ccb3f6f..a0189efc 100644 --- a/doc/select.md +++ b/doc/select.md @@ -155,7 +155,7 @@ res.rows - [6, 8765, 'Artyom', 51] ``` -With this request, we got objects behind the objects from the [previous example](https://github.com/crud/doc/select#first-parameter) +With this request, we got objects behind the objects from the [previous example](https://github.com/tarantool/crud/doc/select#first-parameter) ### Combine ``first`` and ``after`` From 5785fdf9348fcfd03ec51904b1751ebe0448c10a Mon Sep 17 00:00:00 2001 From: Alexey Romanov Date: Tue, 26 Jan 2021 16:49:58 +0300 Subject: [PATCH 06/11] Fix PR issues --- doc/select.md | 212 +++++++++++++++++++++++++++++++++++--------------- 1 file changed, 151 insertions(+), 61 deletions(-) diff --git a/doc/select.md b/doc/select.md index a0189efc..8f2d229a 100644 --- a/doc/select.md +++ b/doc/select.md @@ -2,16 +2,18 @@ ## Filtering -The second parameter passed to ``crud.select`` is an array of conditions. Below are examples of filtering data using these conditions. +``CRUD`` allows to filter tuples by conditions. Each condition can use field name (or number) or index name. The first condition that uses index name is used to iterate over space. If there is no conditions that match index names, full scan is performed. Other conditions are used as additional filters. -### Getting full space +Below are examples of filtering data using these conditions. -To get a full space without filtering, you need to pass ``nil`` as a condition. +### Getting space + +Let's check ``developers`` space contents to make other examples more clear. Just select first 6 values without conditions. **Example:** ```lua -crud.select('customers', nil) +crud.select('developers', nil, { first = 6 }) --- - metadata: - {'name': 'id', 'type': 'unsigned'} @@ -20,11 +22,12 @@ crud.select('customers', nil) - {'name': 'surname', 'type': 'string'} - {'name': 'age', 'type': 'number'} rows: - - [1, 635, 'John', 'Adams', 65] - - [2, 2364, 'John', 'Sidorov', 28] - - [3, 6517, 'Ronald', 'Dump', 77] - - [4, 563, 'Sergey', 'Lee', 21] - - [5, 2313, 'Tatyana', 'May', 20] + - [1, 7331, 'Alexey', 'Adams', 20] + - [2, 899, 'Sergey', 'Allred', 21] + - [3, 9661, 'Pavel', 'Adams', 27] + - [4, 501, 'Mikhail', 'Liston', 31] + - [5, 1993, 'Dmitry', 'Jacobi', 16] + - [6, 8765, 'Alexey', 'Sidorov', 51] ... ``` @@ -35,11 +38,17 @@ Let's say we have a ``age`` index. Example below gets a list of ``customers`` ov **Example:** ```lua -res, err = crud.select('customers', {{'>=', 'age', 30}}) -res.rows +crud.select('developers', {{'>=', 'age', 30}}) --- -- - [1, 635, 'John', 'Adams', 65] - - [3, 6517, 'Ronald', 'Dump', 77] +- metadata: + - {'name': 'id', 'type': 'unsigned'} + - {'name': 'bucked_id', 'type': 'unsigned'} + - {'name': 'name', 'type': 'string'} + - {'name': 'surname', 'type': 'string'} + - {'name': 'age', 'type': 'number'} + rows: + - [4, 501, 'Mikhail', 'Liston', 31] + - [6, 8765, 'Alexey', 'Sidorov', 51] ... ``` @@ -50,10 +59,16 @@ Suppose we have a composite index consisting of the ``name`` and ``surname`` fie **Example**: ```lua -res, err = crud.select('customers', {{'==', 'full_name', {"John", "Sidorov"}}}) -res.rows +crud.select('developers', {{'==', 'full_name', {"Alexey", "Adams"}}}) --- -- - [1, 2364, 'John', 'Sidorov', 28] +- metadata: + - {'name': 'id', 'type': 'unsigned'} + - {'name': 'bucked_id', 'type': 'unsigned'} + - {'name': 'name', 'type': 'string'} + - {'name': 'surname', 'type': 'string'} + - {'name': 'age', 'type': 'number'} + rows: + - [1, 7331, 'Alexey', 'Adams', 20] ... ``` @@ -64,11 +79,17 @@ Alternatively, you can use a partial key for a composite index. **Example**: ```lua -res, err = crud.select('customers', {{'==', 'full_name', "John"}}) -res.rows +crud.select('developers', {{'==', 'full_name', "Alexey"}}) --- -- - [1, 2364, 'John', 'Sidorov', 28] - - [2, 635, 'John', 'Adams', 65] +- metadata: + - {'name': 'id', 'type': 'unsigned'} + - {'name': 'bucked_id', 'type': 'unsigned'} + - {'name': 'name', 'type': 'string'} + - {'name': 'surname', 'type': 'string'} + - {'name': 'age', 'type': 'number'} + rows: + - [1, 7331, 'Alexey', 'Adams', 20] + - [6, 8765, 'Alexey', 'Sidorov', 51] ... ``` @@ -79,26 +100,37 @@ You can also make a selection using a non-indexed field. **Example:** ```lua -res, err = crud.select('customers', {{'>=', 'id', 3}}) -res.rows +crud.select('developers', {{'==', 'surname', "Adams"}}) --- -- - [3, 6517, 'Ronald', 'Dump', 77] - - [4, 563, 'Sergey', 'Lee', 21] - - [5, 2313, 'Tatyana', 'May', 20] +- metadata: + - {'name': 'id', 'type': 'unsigned'} + - {'name': 'bucked_id', 'type': 'unsigned'} + - {'name': 'name', 'type': 'string'} + - {'name': 'surname', 'type': 'string'} + - {'name': 'age', 'type': 'number'} + rows: + - [1, 7331, 'Alexey', 'Adams', 20] + - [3, 9661, 'Pavel', 'Adams', 27] ... ``` **Note:** in this case full scan is performed. -Note that the search condition for the indexed field must be placed first to avoi a full scan. +Note that the search condition for the indexed field must be placed first to avoid a full scan. **Example:** ```lua -res, err = crud.select('customers', {{'>=', 'id', 3}, {'>=', 'age', 30}}) -res.rows +crud.select('developers', {{'==', 'surname', "Adams"}, {'>=', 'age', 25}}) --- -- - [3, 6517, 'Ronald', 'Dump', 77] +- metadata: + - {'name': 'id', 'type': 'unsigned'} + - {'name': 'bucked_id', 'type': 'unsigned'} + - {'name': 'name', 'type': 'string'} + - {'name': 'surname', 'type': 'string'} + - {'name': 'age', 'type': 'number'} + rows: + - [3, 9661, 'Pavel', 'Adams', 27] ... ``` @@ -107,16 +139,22 @@ In this case, a full scan will be performed, since non-indexed field is placed f **Example:** ```lua -res, err = crud.select('customers', {{'>=', 'age', 30}, {'>=', 'id', 3}}) -res.rows +crud.select('developers', {{'>=', 'age', 30}, {'==', 'surname', "Adams"}}) --- -- - [3, 6517, 'Ronald', 'Dump', 77] +- metadata: + - {'name': 'id', 'type': 'unsigned'} + - {'name': 'bucked_id', 'type': 'unsigned'} + - {'name': 'name', 'type': 'string'} + - {'name': 'surname', 'type': 'string'} + - {'name': 'age', 'type': 'number'} + rows: + - [3, 9661, 'Pavel', 'Adams', 27] ... ``` ## Pagination -The third (but optional) parameter in ``crud.select`` is array of [``options``](https://github.com/tarantool/crud#select). With this parameter, we can implement pagination. +[See more](https://github.com/tarantool/crud#select) about ``opts`` parameter. ### ``First`` parameter @@ -125,16 +163,18 @@ Using the ``first`` option we will get the first **N** results for the query. **Example:** ```lua -crud.select('developers', nil, { first = 3 }) +res, err = crud.select('developers', nil, { first = 3 }) +res - metadata: - {'name': 'id', 'type': 'unsigned'} - {'name': 'bucked_id', 'type': 'unsigned'} - {'name': 'name', 'type': 'string'} + - {'name': 'surname', 'type': 'string'} - {'name': 'age', 'type': 'number'} rows: - - [1, 7331, 'Alexey', 20] - - [2, 899, 'Sergey', 21] - - [3, 9661, 'Pavel', 27] + - [1, 7331, 'Alexey', 'Adams', 20] + - [2, 899, 'Sergey', 'Allred', 21] + - [3, 9661, 'Pavel', 'Adams', 27] ... ``` @@ -148,11 +188,19 @@ Using ``after``, we can get the objects after specified tuple. ```lua res, err = crud.select('developers', nil, { after = res.rows[3] }) -res.rows +res --- -- - [4, 501, 'Mikhail', 31] - - [5, 1997, 'Dmitry', 16] - - [6, 8765, 'Artyom', 51] +- metadata: + - {'name': 'id', 'type': 'unsigned'} + - {'name': 'bucked_id', 'type': 'unsigned'} + - {'name': 'name', 'type': 'string'} + - {'name': 'surname', 'type': 'string'} + - {'name': 'age', 'type': 'number'} + rows: + - [4, 501, 'Mikhail', 'Liston', 31] + - [5, 1993, 'Dmitry', 'Jacobi', 16] + - [6, 8765, 'Alexey', 'Sidorov', 51] +... ``` With this request, we got objects behind the objects from the [previous example](https://github.com/tarantool/crud/doc/select#first-parameter) @@ -164,19 +212,33 @@ To use pagination, we have to combine ``after`` and ``first`` parameters. **Example:** ```lua -res, err = crud.select('developers', nil, { first = 3 }) -res.rows +res, err = crud.select('developers', nil, { first = 3 }) +res --- Got first three objects -- - [1, 7331, 'Alexey', 20] - - [2, 899, 'Sergey', 21] - - [3, 9661, 'Pavel', 27] +- metadata: + - {'name': 'id', 'type': 'unsigned'} + - {'name': 'bucked_id', 'type': 'unsigned'} + - {'name': 'name', 'type': 'string'} + - {'name': 'surname', 'type': 'string'} + - {'name': 'age', 'type': 'number'} + rows: + - [1, 7331, 'Alexey', 'Adams', 20] + - [2, 899, 'Sergey', 'Allred', 21] + - [3, 9661, 'Pavel', 'Adams', 27] ... res, err = crud.select('developers', nil, { after = res.rows[3], first = 3 }) -res.rows ---- Get the next three objects -- - [4, 501, 'Mikhail', 31] - - [5, 1997, 'Dmitry', 16] - - [6, 8765, 'Artyom', 51] +res +--- Got the next three objects +- metadata: + - {'name': 'id', 'type': 'unsigned'} + - {'name': 'bucked_id', 'type': 'unsigned'} + - {'name': 'name', 'type': 'string'} + - {'name': 'surname', 'type': 'string'} + - {'name': 'age', 'type': 'number'} + rows: + - [4, 501, 'Mikhail', 'Liston', 31] + - [5, 1993, 'Dmitry', 'Jacobi', 16] + - [6, 8765, 'Alexey', 'Sidorov', 51] ... ``` @@ -187,18 +249,46 @@ Select also supports reverse pagination. To use it, pass a negative value to the **Example:** ```lua +res, err = crud.select('developers', nil, { first = 3 }) +res +--- Got first three objects +- metadata: + - {'name': 'id', 'type': 'unsigned'} + - {'name': 'bucked_id', 'type': 'unsigned'} + - {'name': 'name', 'type': 'string'} + - {'name': 'surname', 'type': 'string'} + - {'name': 'age', 'type': 'number'} + rows: + - [1, 7331, 'Alexey', 'Adams', 20] + - [2, 899, 'Sergey', 'Allred', 21] + - [3, 9661, 'Pavel', 'Adams', 27] +... res, err = crud.select('developers', nil, { after = res.rows[3], first = 3 }) -res.rows ---- -- - [4, 501, 'Mikhail', 31] - - [5, 1997, 'Dmitry', 16] - - [6, 8765, 'Artyom', 51] +res +--- Got the next three objects +- metadata: + - {'name': 'id', 'type': 'unsigned'} + - {'name': 'bucked_id', 'type': 'unsigned'} + - {'name': 'name', 'type': 'string'} + - {'name': 'surname', 'type': 'string'} + - {'name': 'age', 'type': 'number'} + rows: + - [4, 501, 'Mikhail', 'Liston', 31] + - [5, 1993, 'Dmitry', 'Jacobi', 16] + - [6, 8765, 'Alexey', 'Sidorov', 51] ... res, err = crud.select('developers', nil, { after = res.rows[1], first = -3 }) -res.rows ---- -- - [1, 7331, 'Alexey', 20] - - [2, 899, 'Sergey', 21] - - [3, 9661, 'Pavel', 27] +res +--- Got first three objects again +- metadata: + - {'name': 'id', 'type': 'unsigned'} + - {'name': 'bucked_id', 'type': 'unsigned'} + - {'name': 'name', 'type': 'string'} + - {'name': 'surname', 'type': 'string'} + - {'name': 'age', 'type': 'number'} + rows: + - [1, 7331, 'Alexey', 'Adams', 20] + - [2, 899, 'Sergey', 'Allred', 21] + - [3, 9661, 'Pavel', 'Adams', 27] ... ``` From 99f6afff02207999f93bb4fc665c386a256b8757 Mon Sep 17 00:00:00 2001 From: Alexey Romanov Date: Tue, 26 Jan 2021 18:51:22 +0300 Subject: [PATCH 07/11] Add more pairs examples --- doc/pairs.md | 127 ++++++++++++++++++++++++++++++++++++++------------ doc/select.md | 2 + 2 files changed, 98 insertions(+), 31 deletions(-) diff --git a/doc/pairs.md b/doc/pairs.md index a73f5fa7..0ad7144f 100644 --- a/doc/pairs.md +++ b/doc/pairs.md @@ -10,24 +10,27 @@ With ``use_tomap`` flag, you can choose to iterate over objects or over tuples. ```lua tuples = {} -for _, tuple in crud.pairs('customers', nil, {use_tomap = false}) do +for _, tuple in crud.pairs('developers', nil, { use_tomap = false, first = 3 }) do table.insert(tuples, tuple) end tuples --- - - - 1 - - 2313 + - 7331 - Alexey + - Adams - 20 - - 2 - - 241 - - Vladimir - - 18 + - 899 + - Sergey + - Allred + - 21 - - 3 - - 571 - - Alexander - - 24 + - 9661 + - Pavel + - Adams + - 27 ... ``` @@ -37,24 +40,27 @@ If ``use_tomap = true``, you will iterate over objects. ```lua objects = {} -for _, obj in crud.pairs('customers', nil, {use_tomap = true}) do +for _, obj in crud.pairs('developers', nil, { use_tomap = true, first = 3 }) do table.insert(tuples, tuple) end objects --- - - id: 1 - bucket_id: 2313 + bucket_id: 7331 name: Alexey + surname: Adams age: 20 - id: 2 - bucket_id: 241 - name: Vladimir - age: 14 + bucket_id: 899 + name: Sergey + surname: Allred + age: 21 - id: 3 - bucket_id: 571 - name: Alexander - age: 24 + bucket_id: 9661 + name: Pavel + surname: Adams + age: 27 ... ``` @@ -65,7 +71,50 @@ objects **Example:** ```lua -TODO +tuples = {} +for _, tuple in crud.pairs('developers', nil, { first = 2 }) do + table.insert(tuples, tuple) -- Got first two tuples +end + +tuples +--- +- - - 1 + - 7331 + - Alexey + - Adams + - 20 + - - 2 + - 899 + - Sergey + - Allred + - 21 +... +for _, tuple in crud.pairs('developers', nil, { after = tuples[2], first = 2 }) do + table.insert(tuples, tuple) -- Got next two tuples +end + +tuples +--- +- - - 1 + - 7331 + - Alexey + - Adams + - 20 + - - 2 + - 899 + - Sergey + - Allred + - 21 + - - 3 + - 9661 + - Pavel + - Adams + - 27 + - - 4 + - 501 + - Mikhail + - Liston + - 31 ``` Note that ``crud.pairs``, unlike ``crud.select``, **don't support reverse pagination.** @@ -78,15 +127,16 @@ Note that ``crud.pairs``, unlike ``crud.select``, **don't support reverse pagina ```lua objects = {} -for _, obj in crud.pairs('customers', {{'>=', 'age', 20}}, {use_tomap = true}):filter(function(x) return x.age % 5 == 0 end) do +for _, obj in crud.pairs('developers', {{'>=', 'age', 20}}, { use_tomap = true }):filter(function(x) return x.age % 5 == 0 end) do table.insert(objects, obj) end objects --- - - id: 1 - bucket_id: 2313 + bucket_id: 7331 name: Alexey + surname: Adams age: 20 ... ``` @@ -94,10 +144,10 @@ objects **Reduce (foldl) example:** ```lua -age_sum = crud.pairs('customers', nil, {use_tomap = true}):reduce(function(acc, x) return acc + x.age end, 0) +age_sum = crud.pairs('developers', nil, { use_tomap = true }):reduce(function(acc, x) return acc + x.age end, 0) age_sum --- -- 30 +- 166 .... ``` @@ -105,7 +155,7 @@ age_sum ```lua objects = {} -for _, obj in crud.pairs('customers', nil, {use_tomap = true}):map(function(x) return {id = obj.id, name = obj.name, age = obj.age * 2}) do +for _, obj in crud.pairs('developers', nil, { use_tomap = true }):map(function(x) return {id = obj.id, name = obj.name, age = obj.age * 2}) do table.insert(objects, obj) end @@ -115,11 +165,20 @@ objects name: Alexey age: 40 - id: 2 - name: Vladimir - age: 28 + name: Sergey + age: 42 - id: 3 - name: Alexander - age: 48 + name: Pavel + age: 54 + - id: 4 + name: Mikhail + age: 62 + - id: 5 + name: Dmitry + age: 32 + - id: 6 + name: Alexey + age: 102 ... ``` @@ -127,15 +186,21 @@ objects ```lua tuples = {} -for _, tuple in crud.pairs('customers', {{'>=', 'age', 18}}):take(1) do +for _, tuple in crud.pairs('developers', {{'>=', 'age', 25}}):take(2) do table.insert(tuples, tuple) end tuples --- -- - - 1 - - 2313 - - Alexey - - 20 +- - - 3 + - 9661 + - Pavel + - Adams + - 27 + - - 4 + - 501 + - Mikhail + - Liston + - 31 ... ``` diff --git a/doc/select.md b/doc/select.md index 8f2d229a..f413caad 100644 --- a/doc/select.md +++ b/doc/select.md @@ -4,6 +4,8 @@ ``CRUD`` allows to filter tuples by conditions. Each condition can use field name (or number) or index name. The first condition that uses index name is used to iterate over space. If there is no conditions that match index names, full scan is performed. Other conditions are used as additional filters. +**Note:** If you specify ``sharding key`` or ``bucket_id`` select will be performed on single node. Otherwise Map-Reduce over all nodes will be occurred. + Below are examples of filtering data using these conditions. ### Getting space From 811f93780e51b749b0e0c50d7085080d2b1ea297 Mon Sep 17 00:00:00 2001 From: Alexey Romanov Date: Wed, 27 Jan 2021 16:29:08 +0300 Subject: [PATCH 08/11] Fix PR issues --- doc/pairs.md | 45 ++++++++++++++++++++++----------------------- doc/select.md | 37 +++++++++++++++++++++---------------- 2 files changed, 43 insertions(+), 39 deletions(-) diff --git a/doc/pairs.md b/doc/pairs.md index 0ad7144f..616b8f3c 100644 --- a/doc/pairs.md +++ b/doc/pairs.md @@ -2,16 +2,16 @@ With ``crud.pairs``, you can iterate across a distributed space. The arguments are the same as [``crud.select``](https://github.com/tarantool/crud/docs/select.md), except or the ``use_tomap`` parameter. Below are examples that may help you. -## ``Use_tomap`` parameter +## Getting space -With ``use_tomap`` flag, you can choose to iterate over objects or over tuples. If ``use_tomap = false``, you will iterate over tuples. This parameter is false by default. +Let's check ``developers`` space contents to make other examples more clear. Just select first 4 values without conditions. **Example:** ```lua tuples = {} -for _, tuple in crud.pairs('developers', nil, { use_tomap = false, first = 3 }) do - table.insert(tuples, tuple) +for _, tuple in crud.pairs('developers', nil, { first = 4 }) do + table.insert(tuples, tuple) end tuples @@ -31,10 +31,17 @@ tuples - Pavel - Adams - 27 + - - 4 + - 501 + - Mikhail + - Liston + - 51 ... ``` -If ``use_tomap = true``, you will iterate over objects. +## ``Use_tomap`` parameter + +With ``use_tomap`` flag, you can choose to iterate over objects or over tuples. If ``use_tomap = true``, you will iterate over objects. This parameter is false by default. **Example:** @@ -89,23 +96,14 @@ tuples - Allred - 21 ... +new_tuples = {} for _, tuple in crud.pairs('developers', nil, { after = tuples[2], first = 2 }) do - table.insert(tuples, tuple) -- Got next two tuples + table.insert(new_tuples, tuple) -- Got next two tuples end -tuples +new_tuples --- -- - - 1 - - 7331 - - Alexey - - Adams - - 20 - - - 2 - - 899 - - Sergey - - Allred - - 21 - - - 3 +- - - 3 - 9661 - Pavel - Adams @@ -114,10 +112,11 @@ tuples - 501 - Mikhail - Liston - - 31 + - 51 +... ``` -Note that ``crud.pairs``, unlike ``crud.select``, **don't support reverse pagination.** +Note that ``crud.pairs``, unlike ``crud.select``, **doesn't support reverse pagination.** ## Lua Fun @@ -172,13 +171,13 @@ objects age: 54 - id: 4 name: Mikhail - age: 62 + age: 102 - id: 5 name: Dmitry age: 32 - id: 6 name: Alexey - age: 102 + age: 62 ... ``` @@ -201,6 +200,6 @@ tuples - 501 - Mikhail - Liston - - 31 + - 51 ... ``` diff --git a/doc/select.md b/doc/select.md index f413caad..ebba5e57 100644 --- a/doc/select.md +++ b/doc/select.md @@ -2,7 +2,7 @@ ## Filtering -``CRUD`` allows to filter tuples by conditions. Each condition can use field name (or number) or index name. The first condition that uses index name is used to iterate over space. If there is no conditions that match index names, full scan is performed. Other conditions are used as additional filters. +``CRUD`` allows to filter tuples by conditions. Each condition can use field name (or number) or index name. The first condition that uses index name is used to iterate over space. If there is no conditions that match index names, full scan is performed. Other conditions are used as additional filters. Search condition for the indexed field must be placed first to avoid a full scan. **Note:** If you specify ``sharding key`` or ``bucket_id`` select will be performed on single node. Otherwise Map-Reduce over all nodes will be occurred. @@ -27,9 +27,9 @@ crud.select('developers', nil, { first = 6 }) - [1, 7331, 'Alexey', 'Adams', 20] - [2, 899, 'Sergey', 'Allred', 21] - [3, 9661, 'Pavel', 'Adams', 27] - - [4, 501, 'Mikhail', 'Liston', 31] + - [4, 501, 'Mikhail', 'Liston', 51] - [5, 1993, 'Dmitry', 'Jacobi', 16] - - [6, 8765, 'Alexey', 'Sidorov', 51] + - [6, 8765, 'Alexey', 'Sidorov', 31] ... ``` @@ -49,8 +49,8 @@ crud.select('developers', {{'>=', 'age', 30}}) - {'name': 'surname', 'type': 'string'} - {'name': 'age', 'type': 'number'} rows: - - [4, 501, 'Mikhail', 'Liston', 31] - - [6, 8765, 'Alexey', 'Sidorov', 51] + - [6, 8765, 'Alexey', 'Sidorov', 31] + - [4, 501, 'Mikhail', 'Liston', 51] ... ``` @@ -91,10 +91,12 @@ crud.select('developers', {{'==', 'full_name', "Alexey"}}) - {'name': 'age', 'type': 'number'} rows: - [1, 7331, 'Alexey', 'Adams', 20] - - [6, 8765, 'Alexey', 'Sidorov', 51] + - [6, 8765, 'Alexey', 'Sidorov', 31] ... ``` +**Note:** If you specify partial key not at the first parameter (e.g. ``{{'==', 'full_name', {nil, "Sidorov"}}}``), then full scan will be performed. + ### Select using non-indexed field You can also make a selection using a non-indexed field. @@ -118,7 +120,7 @@ crud.select('developers', {{'==', 'surname', "Adams"}}) **Note:** in this case full scan is performed. -Note that the search condition for the indexed field must be placed first to avoid a full scan. +### Avoiding full scan **Example:** @@ -199,9 +201,9 @@ res - {'name': 'surname', 'type': 'string'} - {'name': 'age', 'type': 'number'} rows: - - [4, 501, 'Mikhail', 'Liston', 31] + - [4, 501, 'Mikhail', 'Liston', 51] - [5, 1993, 'Dmitry', 'Jacobi', 16] - - [6, 8765, 'Alexey', 'Sidorov', 51] + - [6, 8765, 'Alexey', 'Sidorov', 31] ... ``` @@ -238,9 +240,9 @@ res - {'name': 'surname', 'type': 'string'} - {'name': 'age', 'type': 'number'} rows: - - [4, 501, 'Mikhail', 'Liston', 31] + - [4, 501, 'Mikhail', 'Liston', 51] - [5, 1993, 'Dmitry', 'Jacobi', 16] - - [6, 8765, 'Alexey', 'Sidorov', 51] + - [6, 8765, 'Alexey', 'Sidorov', 31] ... ``` @@ -251,9 +253,12 @@ Select also supports reverse pagination. To use it, pass a negative value to the **Example:** ```lua +-- Imagine that user looks at his friends list using very small pages +-- He opens first page, then presses '->' and take next page +-- Then, he wants to return back and presses '<-' res, err = crud.select('developers', nil, { first = 3 }) res ---- Got first three objects +--- Got first page (first three objects) - metadata: - {'name': 'id', 'type': 'unsigned'} - {'name': 'bucked_id', 'type': 'unsigned'} @@ -267,7 +272,7 @@ res ... res, err = crud.select('developers', nil, { after = res.rows[3], first = 3 }) res ---- Got the next three objects +--- Got the next page (next three objects) - metadata: - {'name': 'id', 'type': 'unsigned'} - {'name': 'bucked_id', 'type': 'unsigned'} @@ -275,13 +280,13 @@ res - {'name': 'surname', 'type': 'string'} - {'name': 'age', 'type': 'number'} rows: - - [4, 501, 'Mikhail', 'Liston', 31] + - [4, 501, 'Mikhail', 'Liston', 51] - [5, 1993, 'Dmitry', 'Jacobi', 16] - - [6, 8765, 'Alexey', 'Sidorov', 51] + - [6, 8765, 'Alexey', 'Sidorov', 31] ... res, err = crud.select('developers', nil, { after = res.rows[1], first = -3 }) res ---- Got first three objects again +--- Got first page again - metadata: - {'name': 'id', 'type': 'unsigned'} - {'name': 'bucked_id', 'type': 'unsigned'} From d22f32ff1cb6c55b515d99e2e80b38ff23c8bfdf Mon Sep 17 00:00:00 2001 From: Alexey Romanov Date: Thu, 28 Jan 2021 20:03:46 +0300 Subject: [PATCH 09/11] PR fixes --- doc/pairs.md | 2 +- doc/select.md | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/doc/pairs.md b/doc/pairs.md index 616b8f3c..804b88d0 100644 --- a/doc/pairs.md +++ b/doc/pairs.md @@ -39,7 +39,7 @@ tuples ... ``` -## ``Use_tomap`` parameter +## ``use_tomap`` parameter With ``use_tomap`` flag, you can choose to iterate over objects or over tuples. If ``use_tomap = true``, you will iterate over objects. This parameter is false by default. diff --git a/doc/select.md b/doc/select.md index ebba5e57..f10f77fd 100644 --- a/doc/select.md +++ b/doc/select.md @@ -4,7 +4,7 @@ ``CRUD`` allows to filter tuples by conditions. Each condition can use field name (or number) or index name. The first condition that uses index name is used to iterate over space. If there is no conditions that match index names, full scan is performed. Other conditions are used as additional filters. Search condition for the indexed field must be placed first to avoid a full scan. -**Note:** If you specify ``sharding key`` or ``bucket_id`` select will be performed on single node. Otherwise Map-Reduce over all nodes will be occurred. +**Note:** If you specify sharding key or ``bucket_id`` select will be performed on single node. Otherwise Map-Reduce over all nodes will be occurred. Below are examples of filtering data using these conditions. @@ -54,6 +54,8 @@ crud.select('developers', {{'>=', 'age', 30}}) ... ``` +**Note:** results are sorted by age, because first condition is ``age`` index. + ### Select using composite index Suppose we have a composite index consisting of the ``name`` and ``surname`` fields. See example of select queries using such a composited index below. @@ -160,7 +162,7 @@ crud.select('developers', {{'>=', 'age', 30}, {'==', 'surname', "Adams"}}) [See more](https://github.com/tarantool/crud#select) about ``opts`` parameter. -### ``First`` parameter +### ``first`` parameter Using the ``first`` option we will get the first **N** results for the query. @@ -184,7 +186,7 @@ res Thus, we got the first three objects from the ``developers`` space. -### ``After`` parameter +### ``after`` parameter Using ``after``, we can get the objects after specified tuple. From 61e3b981cd7a90864da57ed69629e7af70775943 Mon Sep 17 00:00:00 2001 From: Alexey Romanov Date: Fri, 29 Jan 2021 18:19:59 +0300 Subject: [PATCH 10/11] PR issues fix --- doc/pairs.md | 17 ++++++++++------- doc/select.md | 6 +++--- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/doc/pairs.md b/doc/pairs.md index 804b88d0..4986aea5 100644 --- a/doc/pairs.md +++ b/doc/pairs.md @@ -1,6 +1,8 @@ # Pairs examples -With ``crud.pairs``, you can iterate across a distributed space. The arguments are the same as [``crud.select``](https://github.com/tarantool/crud/docs/select.md), except or the ``use_tomap`` parameter. Below are examples that may help you. +With ``crud.pairs``, you can iterate across a distributed space. +The arguments are the same as [``crud.select``](https://github.com/tarantool/crud/docs/select.md), except of the ``use_tomap`` parameter. +Below are examples that may help you. ## Getting space @@ -16,11 +18,11 @@ end tuples --- -- - - 1 - - 7331 - - Alexey - - Adams - - 20 +- - - 1 -- id + - 7331 -- bucket_id + - Alexey -- name + - Adams -- surname + - 20 -- age - - 2 - 899 - Sergey @@ -73,7 +75,8 @@ objects ## Pagination -``crud.pairs``, like [``crud.select``](https://github.com/tarantool/crud/doc/select#pagination), supports pagination. To use it, combine the ``first`` and ``after`` parameters. +``crud.pairs``, like [``crud.select``](https://github.com/tarantool/crud/doc/select#pagination), supports pagination. +To use it, combine the ``first`` and ``after`` parameters. **Example:** diff --git a/doc/select.md b/doc/select.md index f10f77fd..d481663b 100644 --- a/doc/select.md +++ b/doc/select.md @@ -10,7 +10,7 @@ Below are examples of filtering data using these conditions. ### Getting space -Let's check ``developers`` space contents to make other examples more clear. Just select first 6 values without conditions. +Let's check ``developers`` space content to make other examples more clear. Just select first 6 values without conditions. **Example:** @@ -164,7 +164,7 @@ crud.select('developers', {{'>=', 'age', 30}, {'==', 'surname', "Adams"}}) ### ``first`` parameter -Using the ``first`` option we will get the first **N** results for the query. +Using the ``first`` option we will get the first **N** results of the query. **Example:** @@ -250,7 +250,7 @@ res ### Reverse pagination -Select also supports reverse pagination. To use it, pass a negative value to the ``first`` parameter. +Select also supports reverse pagination. To use it, pass a negative value to the ``first`` parameter and combine it with ``after`` parameter. **Example:** From b692ef07fb4df1a50d32fac12c258d40cd04bc16 Mon Sep 17 00:00:00 2001 From: Alexey Romanov Date: Fri, 29 Jan 2021 18:21:43 +0300 Subject: [PATCH 11/11] newline fixes --- doc/pairs.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/doc/pairs.md b/doc/pairs.md index 4986aea5..bf3423a3 100644 --- a/doc/pairs.md +++ b/doc/pairs.md @@ -43,7 +43,8 @@ tuples ## ``use_tomap`` parameter -With ``use_tomap`` flag, you can choose to iterate over objects or over tuples. If ``use_tomap = true``, you will iterate over objects. This parameter is false by default. +With ``use_tomap`` flag, you can choose to iterate over objects or over tuples. +If ``use_tomap = true``, you will iterate over objects. This parameter is false by default. **Example:**