1/*
2 * Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License, version 2.0,
6 * as published by the Free Software Foundation.
7 *
8 * This program is also distributed with certain software (including
9 * but not limited to OpenSSL) that is licensed under separate terms,
10 * as designated in a particular file or component or in included license
11 * documentation.  The authors of MySQL hereby grant you an additional
12 * permission to link the program and your derivative works with the
13 * separately licensed software that they have included with MySQL.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 * GNU General Public License, version 2.0, for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA
23 */
24syntax = "proto2";
25
26
27// ifdef PROTOBUF_LITE: option optimize_for = LITE_RUNTIME;
28
29// Basic CRUD operations
30package Mysqlx.Crud;
31option java_package = "com.mysql.cj.x.protobuf";
32
33import "mysqlx.proto"; // comment_out_if PROTOBUF_LITE
34import "mysqlx_expr.proto";
35import "mysqlx_datatypes.proto";
36
37// column definition
38message Column {
39  optional string name = 1;
40  optional string alias = 2;
41  repeated Mysqlx.Expr.DocumentPathItem document_path = 3;
42}
43
44// a projection
45//
46// :param source: the expression identifying an element from the source data
47//                which can include a column identifier or any expression
48// :param alias: optional alias. Required for DOCUMENTs (clients may use
49//              the source string as default)
50message Projection {
51    required Mysqlx.Expr.Expr source = 1;
52    optional string alias = 2;
53}
54
55// DataModel to use for filters, names, ...
56enum DataModel {
57  DOCUMENT = 1;
58  TABLE = 2;
59};
60
61// collection
62message Collection {
63  required string name = 1;
64  optional string schema = 2;
65}
66
67// limit
68//
69// :param row_count: maximum rows to filter
70// :param offset: maximum rows to skip before applying the row_count
71message Limit {
72  required uint64 row_count = 1 /* ifdef PROTOBUF3 [jstype = JS_STRING] */;
73  optional uint64 offset = 2 /* ifdef PROTOBUF3 [jstype = JS_STRING] */;
74}
75
76// limit expression
77//
78// LimitExpr in comparison to Limit, is able to specify that row_count and
79// offset are placeholders.
80// This message support expressions of following types Expr/literal/UINT,
81// Expr/PLACEHOLDER.
82//
83// :param row_count: maximum rows to filter
84// :param offset: maximum rows to skip before applying the row_count
85message LimitExpr {
86  required Mysqlx.Expr.Expr row_count = 1;
87  optional Mysqlx.Expr.Expr offset = 2;
88}
89
90// sort order
91message Order {
92  enum Direction {
93    ASC = 1;
94    DESC = 2;
95  };
96
97  required Mysqlx.Expr.Expr expr = 1;
98  optional Direction direction = 2 [ default=ASC ];
99}
100
101// update operations
102//
103// :param source: specification of the value to be updated
104//      if data_model is TABLE, a column name may be specified and also a document path, if the column has type JSON
105//      if data_model is DOCUMENT, only document paths are allowed
106//      in both cases, schema and table must be not set
107// :param operation: the type of operation to be performed
108// :param value: an expression to be computed as the new value for the operation
109message UpdateOperation {
110  enum UpdateType {
111    SET = 1;            // only allowed for TABLE
112    ITEM_REMOVE = 2;    // no value (removes the identified path from a object or array)
113    ITEM_SET = 3;       // sets the new value on the identified path
114    ITEM_REPLACE = 4;   // replaces a value if the path exists
115    ITEM_MERGE = 5;     // source and value must be documents
116    ARRAY_INSERT = 6;   // insert the value in the array at the index identified in the source path
117    ARRAY_APPEND = 7;   // append the value on the array at the identified path
118    MERGE_PATCH = 8;    // merge JSON object value with the provided patch expression
119  }
120  required Mysqlx.Expr.ColumnIdentifier source = 1;
121  required UpdateType operation = 2;
122  optional Mysqlx.Expr.Expr value = 3;
123}
124
125// Find Documents/Rows in a Collection/Table
126//
127// .. uml::
128//
129//   client -> server: Find
130//   ... one or more Resultset ...
131//
132// :param collection: collection to insert into
133// :param data_model: datamodel that the operations refer to
134// :param projection: list of column projections that shall be returned
135// :param args: values for parameters used in filter expression
136// :param criteria: filter criteria
137// :param limit: numbers of rows that shall be skipped and returned (user can set one of: limit, limit_expr)
138// :param order: sort-order in which the rows/document shall be returned in
139// :param grouping: column expression list for aggregation (GROUP BY)
140// :param grouping_criteria: filter criteria for aggregated groups
141// :param locking: perform row locking on matches
142// :param locking_options: additional options how to handle locked rows
143// :param limit_expr: numbers of rows that shall be skipped and returned (user can set one of: limit, limit_expr)
144// :Returns: :protobuf:msg:`Mysqlx.Resultset::`
145message Find {
146  enum RowLock {
147    SHARED_LOCK = 1;   // Lock matching rows against updates
148    EXCLUSIVE_LOCK = 2;  // Lock matching rows so no other transaction can read or write to it
149  };
150
151  enum RowLockOptions {
152    NOWAIT = 1;   // Do not wait to acquire row lock, fail with an error if a requested row is locked
153    SKIP_LOCKED = 2;  // Do not wait to acquire a row lock, remove locked rows from the result set
154  };
155
156  required Collection collection = 2;
157
158  optional DataModel data_model = 3;
159  repeated Projection projection = 4;
160  optional Mysqlx.Expr.Expr criteria = 5;
161  repeated Mysqlx.Datatypes.Scalar args = 11;
162  repeated Order order = 7;
163  repeated Mysqlx.Expr.Expr grouping = 8;
164  optional Mysqlx.Expr.Expr grouping_criteria = 9;
165  optional RowLock locking = 12;
166  optional RowLockOptions locking_options = 13;
167  optional Limit limit = 6;
168  optional LimitExpr limit_expr = 14;
169
170  option (client_message_id) = CRUD_FIND; // comment_out_if PROTOBUF_LITE
171};
172
173// Insert documents/rows into a collection/table
174//
175// :param collection: collection to insert into
176// :param data_model: datamodel that the operations refer to
177// :param projection: name of the columns to insert data into (empty if data_model is DOCUMENT)
178// :param row: set of rows to insert into the collection/table (a single expression with a JSON document literal or an OBJECT expression)
179// :param args: values for parameters used in row expressions
180// :param upsert: true if this should be treated as an Upsert (that is, update on duplicate key)
181// :Returns: :protobuf:msg:`Mysqlx.Resultset::`
182message Insert {
183  required Collection collection = 1;
184
185  optional DataModel data_model = 2;
186  repeated Column projection = 3;
187
188  message TypedRow {
189    repeated Mysqlx.Expr.Expr field = 1;
190  };
191  repeated TypedRow row = 4;
192  repeated Mysqlx.Datatypes.Scalar args = 5;
193  optional bool upsert = 6 [default = false];
194
195  option (client_message_id) = CRUD_INSERT; // comment_out_if PROTOBUF_LITE
196};
197
198// Update documents/rows in a collection/table
199//
200// :param collection: collection to change
201// :param data_model: datamodel that the operations refer to
202// :param criteria: filter expression to match rows that the operations will apply on
203// :param args: values for parameters used in filter expression
204// :param limit: limits the number of rows to match (user can set one of: limit, limit_expr)
205// :param order: specifies order of matched rows
206// :param operation: list of operations to be applied. Valid operations will depend on the data_model.
207// :param limit_expr: limits the number of rows to match (user can set one of: limit, limit_expr)
208// :Returns: :protobuf:msg:`Mysqlx.Resultset::`
209message Update {
210  required Collection collection = 2;
211
212  optional DataModel data_model = 3;
213  optional Mysqlx.Expr.Expr criteria = 4;
214  repeated Mysqlx.Datatypes.Scalar args = 8;
215  repeated Order order = 6;
216
217  repeated UpdateOperation operation = 7;
218
219  optional Limit limit = 5;
220  optional LimitExpr limit_expr = 9;
221
222  option (client_message_id) = CRUD_UPDATE; // comment_out_if PROTOBUF_LITE
223};
224
225// Delete documents/rows from a Collection/Table
226//
227// :param collection: collection to change
228// :param data_model: datamodel that the operations refer to
229// :param criteria: filter expression to match rows that the operations will apply on
230// :param args: values for parameters used in filter expression
231// :param limit: limits the number of rows to match (user can set one of: limit, limit_expr)
232// :param order: specifies order of matched rows
233// :param limit_expr: limits the number of rows to match (user can set one of: limit, limit_expr)
234// :Returns: :protobuf:msg:`Mysqlx.Resultset::`
235message Delete {
236  required Collection collection = 1;
237
238  optional DataModel data_model = 2;
239  optional Mysqlx.Expr.Expr criteria = 3;
240  repeated Mysqlx.Datatypes.Scalar args = 6;
241  repeated Order order = 5;
242
243  optional Limit limit = 4;
244  optional LimitExpr limit_expr = 7;
245
246  option (client_message_id) = CRUD_DELETE; // comment_out_if PROTOBUF_LITE
247};
248
249
250// ViewAlgorithm defines how MySQL Server processes the view
251enum ViewAlgorithm {
252  UNDEFINED =1;   // MySQL chooses which algorithm to use
253  MERGE = 2;      // the text of a statement that refers to the view and the view definition are merged
254  TEMPTABLE = 3;  // the view are retrieved into a temporary table
255}
256
257// ViewSqlSecurity defines the security context in which the view is going to be
258// executed, this means that VIEW can be executed with current user permissions or
259// with permissions of the uses who defined the VIEW
260enum ViewSqlSecurity {
261  INVOKER = 1;
262  DEFINER = 2;
263}
264
265
266// ViewCheckOption limits the write operations done on a `VIEW`
267// (`INSERT`, `UPDATE`, `DELETE`) to rows in which the `WHERE` clause is `TRUE`
268enum ViewCheckOption {
269  LOCAL = 1;     // the view WHERE clause is checked, but no underlying views are checked
270  CASCADED = 2;  // the view WHERE clause is checked, then checking recurses to underlying views
271}
272
273
274// CreateView create view based on indicated Mysqlx.Crud.Find message
275//
276// param collection: name of the VIEW object, which should be created
277// param definer: user name of the definer, if the value isn't set then the definer is current user
278// param algorithm: defines how MySQL Server processes the view
279// param security: defines the security context in which the view is going be executed
280// param check: limits the write operations done on a VIEW
281// param column: defines the list of aliases for column names specified in `stmt`
282// param stmt: Mysqlx.Crud.Find message from which the SELECT statement is going to be build
283// param replace_existing: if true then suppress error when created view already exists; just replace it
284
285message CreateView {
286  required Collection collection = 1;
287
288  optional string definer = 2;
289  optional ViewAlgorithm algorithm = 3 [default = UNDEFINED];
290  optional ViewSqlSecurity security = 4 [default = DEFINER];
291  optional ViewCheckOption check = 5;
292
293  repeated string column = 6;
294  required Find stmt = 7;
295  optional bool replace_existing = 8 [default = false];
296
297  option (client_message_id) = CRUD_CREATE_VIEW; // comment_out_if PROTOBUF_LITE
298}
299
300
301// ModifyView modify existing view based on indicated Mysqlx.Crud.Find message
302//
303// param collection: name of the VIEW object, which should be modified
304// param definer: user name of the definer, if the value isn't set then the definer is current user
305// param algorithm: defined how MySQL Server processes the view
306// param security: defines the security context in which the view is going be executed
307// param check: limits the write operations done on a VIEW
308// param column: defines the list of aliases for column names specified in `stmt`
309// param stmt: Mysqlx.Crud.Find message from which the SELECT statement is going to be build
310
311message ModifyView {
312  required Collection collection = 1;
313
314  optional string definer = 2;
315  optional ViewAlgorithm algorithm = 3;
316  optional ViewSqlSecurity security = 4;
317  optional ViewCheckOption check = 5;
318
319  repeated string column = 6;
320  optional Find stmt = 7;
321
322  option (client_message_id) = CRUD_MODIFY_VIEW; // comment_out_if PROTOBUF_LITE
323}
324
325
326// DropView removing existing view
327//
328// param collection: name of the VIEW object, which should be deleted
329// param if_exists: if true then suppress error when deleted view does not exists
330
331message DropView {
332  required Collection collection = 1;
333  optional bool if_exists = 2 [ default = false ];
334
335  option (client_message_id) = CRUD_DROP_VIEW; // comment_out_if PROTOBUF_LITE
336}
337