11# CRUD
22
3- CRUD module allows to perform CRUD operations on the cluster.
4- It also provides ` crud-storage ` role for [ Tarantool Cartridge] ( https://github.com/tarantool/cartridge ) .
3+ The ` CRUD ` module allows to perform CRUD operations on the cluster.
4+ It also provides the ` crud-storage ` role for
5+ [ Tarantool Cartridge] ( https://github.com/tarantool/cartridge ) .
56
67## API
78
89The CRUD operations should be called from storage.
9- All storage replicasets should call ` crud.init() ` (or enable ` crud-storage ` role)
10- first to initialize storage-side functions that are used to manipulate data across the cluster.
10+ All storage replica sets should call ` crud.init() `
11+ (or enable the ` crud-storage ` role)
12+ first to initialize storage-side functions that are used to manipulate data
13+ across the cluster.
1114
12- ** Note ** , that space should have format.
15+ ** Notes: **
1316
14- ** Note ** , that all non-TREE indexes will be ignored .
15-
16- ** Note ** , that ` bucket_id ` is computed as
17- ` vshard.router.bucket_id_mpcrc32(key) ` , where ` key ` is primary key value
17+ * A space should have a format .
18+ * All non-TREE indexes will be ignored.
19+ * ` bucket_id ` is computed as ` vshard.router.bucket_id_mpcrc32(key) ` ,
20+ where ` key ` is the primary key value.
1821
1922### Insert
2023
2124``` lua
2225local object , err = crud .insert (space_name , object , opts )
2326```
2427
25- * ` space_name ` (` string ` ) - name of the space to insert object
26- * ` object ` (` table ` ) - an object to insert
28+ where:
29+
30+ * ` space_name ` (` string ` ) - name of the space to insert an object
31+ * ` object ` (` table ` ) - object to insert
2732* ` opts ` :
2833 * ` timeout ` (` ?number ` ) - ` vshard.call ` timeout (in seconds)
2934
3035Returns inserted object, error.
3136
32- ** Example**
37+ ** Example: **
3338
3439``` lua
3540crud .insert (' customers' , {
@@ -49,14 +54,16 @@ crud.insert('customers', {
4954local object , err = crud .get (space_name , key , opts )
5055```
5156
57+ where:
58+
5259* ` space_name ` (` string ` ) - name of the space
5360* ` key ` (` any ` ) - primary key value
5461* ` opts ` :
5562 * ` timeout ` (` ?number ` ) - ` vshard.call ` timeout (in seconds)
5663
5764Returns object, error.
5865
59- ** Example**
66+ ** Example: **
6067
6168``` lua
6269crud .get (' customers' , 1 )
@@ -74,6 +81,8 @@ crud.get('customers', 1)
7481local object , err = crud .update (space_name , key , operations , opts )
7582```
7683
84+ where:
85+
7786* ` space_name ` (` string ` ) - name of the space
7887* ` key ` (` any ` ) - primary key value
7988* ` operations ` (` table ` ) - update [ operations] ( https://www.tarantool.io/en/doc/latest/reference/reference_lua/box_space/#box-space-update )
@@ -82,7 +91,7 @@ local object, err = crud.update(space_name, key, operations, opts)
8291
8392Returns updated object, error.
8493
85- ** Example**
94+ ** Example: **
8695
8796``` lua
8897crud .update (' customers' , 1 , {{' +' , ' age' , 1 }})
@@ -100,14 +109,16 @@ crud.update('customers', 1, {{'+', 'age', 1}})
100109local object , err = crud .delete (space_name , key , opts )
101110```
102111
112+ where:
113+
103114* ` space_name ` (` string ` ) - name of the space
104115* ` key ` (` any ` ) - primary key value
105116* ` opts ` :
106117 * ` timeout ` (` ?number ` ) - ` vshard.call ` timeout (in seconds)
107118
108119Returns deleted object, error.
109120
110- ** Example**
121+ ** Example: **
111122
112123``` lua
113124crud .delete (' customers' , 1 )
@@ -125,12 +136,14 @@ crud.delete('customers', 1)
125136local objects , err = crud .select (space_name , conditions , opts )
126137```
127138
139+ where:
140+
128141* ` space_name ` (` string ` ) - name of the space
129- * ` conditions ` (` ?table ` ) - an array of [ select conditions] ( #select-conditions )
142+ * ` conditions ` (` ?table ` ) - array of [ select conditions] ( #select-conditions )
130143* ` opts ` :
131- * ` limit ` (` ?number ` ) - the maximum limit of the result objects
132- * ` after ` (` ?table ` ) - an object after which object should be selected
133- * ` batch_size ` (` ?number ` ) - a number of tuples to process per one request to storage
144+ * ` limit ` (` ?number ` ) - the maximum limit of the objects to return
145+ * ` after ` (` ?table ` ) - object after which objects should be selected
146+ * ` batch_size ` (` ?number ` ) - number of tuples to process per one request to storage
134147 * ` timeout ` (` ?number ` ) - ` vshard.call ` timeout (in seconds)
135148
136149Returns selected objects, error.
@@ -142,10 +155,10 @@ Select conditions are very similar to Tarantool update
142155
143156Each condition is a table ` {operator, field-identifier, value} ` :
144157
145- * supported operators are: ` = ` (or ` == ` ), ` > ` , ` >= ` , ` < ` , ` <= ` .
146- * field identifier can be field name, field number or index name.
158+ * Supported operators are: ` = ` (or ` == ` ), ` > ` , ` >= ` , ` < ` , ` <= ` .
159+ * Field identifier can be field name, field number, or index name.
147160
148- ** Example**
161+ ** Example: **
149162
150163``` lua
151164crud .select (' customers' , {{' <=' , ' age' , 35 }})
@@ -174,26 +187,26 @@ crud.select('customers', {{'<=', 'age', 35}})
174187
175188### Pairs
176189
177- You can iterate across the distributed space using ` crud.pairs ` function.
178- It's arguments are the same as [ ` crud.select ` ] ( #select ) arguments.
190+ You can iterate across a distributed space using the ` crud.pairs ` function.
191+ Its arguments are the same as [ ` crud.select ` ] ( #select ) arguments.
179192
180- ** Example**
193+ ** Example: **
181194
182195``` lua
183- for _ , obj in crud .pairs (' customers' , {{' <=' , ' age' , 35 }}) do
184- -- do smth with object
196+ for _ , obj in crud .pairs (' customers' , {{' <=' , ' age' , 35 }}) do
197+ -- do smth with the object
185198end
186199```
187200
188201## Cartridge role
189202
190- ` cartridge.roles.crud-storage ` is a Tarantool Cartridge role that depends on
203+ ` cartridge.roles.crud-storage ` is a Tarantool Cartridge role that depends on the
191204` vshard-storage ` role, but also initializes functions that
192- are used on storage- side to perform CRUD operations.
205+ are used on the storage side to perform CRUD operations.
193206
194207### Usage
195208
196- 1 . Add the ` crud ` to dependencies in the project rockspec.
209+ 1 . Add ` crud ` to dependencies in the project rockspec.
197210
198211``` lua
199212-- <project-name>-scm-1.rockspec
@@ -241,10 +254,11 @@ return {
241254```
242255
2432563 . Start the application and create ` customers-storage ` and
244- ` vshard-router ` replicasets .
257+ ` vshard-router ` replica sets .
245258
2462594 . Don't forget to bootstrap vshard.
247260
248261Now your cluster contains storages that are configured to be used for
249262CRUD-operations.
250- You can simply call CRUD functions on the router to insert, select and update data across the cluster.
263+ You can simply call CRUD functions on the router to insert, select, and update
264+ data across the cluster.
0 commit comments