MySQL Shell API 9.1.0
Unified development interface for MySQL Products
|
Represents a Table on an Schema, retrieved with a session created using mysqlx module. More...
Methods | |
TableInsert | insert (...) |
Creates TableInsert object to insert new records into the table. More... | |
TableSelect | select (...) |
Creates a TableSelect object to retrieve rows from the table. More... | |
TableUpdate | update () |
Creates a record update handler. More... | |
TableDelete | delete () |
Creates a record deletion handler. More... | |
Bool | isView () |
Indicates whether this Table object represents a View on the database. More... | |
Integer | count () |
Returns the number of records in the table. | |
Methods inherited from DatabaseObject | |
String | getName () |
Returns the name of this database object.
| |
Object | getSession () |
Returns the Session object of this database object.
| |
Object | getSchema () |
Returns the Schema object of this database object.
| |
Bool | existsInDatabase () |
Verifies if this object exists in the database.
| |
Additional Inherited Members | |
Properties inherited from DatabaseObject | |
String | name |
The name of this database object. | |
Object | session |
The Session object of this database object. | |
Object | schema |
The Schema object of this database object. | |
TableInsert insert | ( | ... | ) |
Creates TableInsert object to insert new records into the table.
Table | .insert(...) |
[.values(value[, value, ...])] | |
.execute() |
An insert operation requires the values to be inserted, optionally the target columns can be defined.
If this function is called without any parameter, no column names will be defined yet.
The column definition can be done by three ways:
If the columns are defined using either an array or multiple parameters, the values must match the defined column names in order and data type.
If a JSON document was used, the operation is ready to be completed and it will insert the associated values into the corresponding columns.
If no columns are defined, insertion will succeed if the provided values match the database columns in number and data types.
Each parameter represents the value for a column in the target table.
If the columns were defined on the insert() function, the number of values on this function must match the number of defined columns.
If no column was defined, the number of parameters must match the number of columns on the target Table.
This function is not available when the insert() is called passing a JSON object with columns and values.
Using Expressions As Values
If a mysqlx.expr(...) object is defined as a value, it will be evaluated in the server, the resulting value will be inserted into the record.
Executes the insert operation.
TableSelect select | ( | ... | ) |
Creates a TableSelect object to retrieve rows from the table.
Table | .select(...) |
[.where(expression)] | |
[.groupBy(...)[.having(condition)]] | |
[.orderBy(...)] | |
[.limit(numberOfRows)[.offset(numberOfRows)]] | |
[.lockShared(lockContention)|.lockExclusive(lockContention)] <tr><td></td><td>[.bind(name, value)]</td></tr> <tr><td></td><td>.execute()</td></tr> |
Defines the columns that will be retrieved from the Table.
To define the column list either use a list object containing the column definitions or pass each column definition on a separate parameter.
If the function is called without specifying any column definition, all the columns in the table will be retrieved.
If used, only those rows satisfying the expression will be retrieved.
The expression supports Parameter Binding.
If used the TableSelect operation will only consider the records matching the established criteria.
The condition supports Parameter Binding.
Every defined sort criterion follows the format:
name [ ASC | DESC ]
ASC is used by default if the sort order is not specified.
If used, the operation will return at most numberOfRows rows.
This function can be called every time the statement is executed.
If used, the first numberOfRows records will not be included on the result.
When this function is called, the selected rows will be locked for write operations, they may be retrieved on a different session, but no updates will be allowed.
The acquired locks will be released when the current transaction is committed or rolled back.
The lockContention parameter defines the behavior of the operation if another session contains an exclusive lock to matching rows.
The lockContention can be specified using the following constants:
The lockContention can also be specified using the following string literals (no case sensitive):
If no lockContention or the default is specified, the operation will block if another session already holds an exclusive lock on matching rows until the lock is released.
If lockContention is set to NOWAIT and another session already holds an exclusive lock on matching rows, the operation will not block and an error will be generated.
If lockContention is set to SKIP_LOCKED and another session already holds an exclusive lock on matching rows, the operation will not block and will return only those rows not having an exclusive lock.
This operation only makes sense within a transaction.
When this function is called, the selected rows will be locked for read operations, they will not be retrievable by other session.
The acquired locks will be released when the current transaction is committed or rolled back.
The lockContention parameter defines the behavior of the operation if another session contains a lock to matching rows.
The lockContention can be specified using the following constants:
The lockContention can also be specified using the following string literals (no case sensitive):
If no lockContention or the default is specified, the operation will block if another session already holds a lock on matching rows until the lock is released.
If lockContention is set to NOWAIT and another session already holds a lock on matching rows, the operation will not block and an error will be generated.
If lockContention is set to SKIP_LOCKED and another session already holds a lock on matching rows, the operation will not block and will return only those rows not having an exclusive lock.
This operation only makes sense within a transaction.
Binds the given value to the placeholder with the specified name.
An error will be raised if the placeholder indicated by name does not exist.
This function must be called once for each used placeholder or an error will be raised when the execute() method is called.
Executes the select operation with all the configured options.
TableUpdate update | ( | ) |
Creates a record update handler.
Table | .update() |
.set(attribute, value) | |
[.where(expression)] | |
[.orderBy(...)] <tr><td></td><td>[.limit(numberOfRows)]</td></tr> <tr><td></td><td>[.bind(name, value)]</td></tr> <tr><td></td><td>.execute()</td></tr> |
Initializes the update operation.
attribute | Identifies the column to be updated by this operation. |
value | Defines the value to be set on the indicated column. |
Adds an operation into the update handler to update a column value in the records that were included on the selection filter and limit.
Using Expressions As Values
If a mysqlx.expr(...) object is defined as a value, it will be evaluated in the server, the resulting value will be set at the indicated column.
The expression also can be used for Parameter Binding.
If used, only those rows satisfying the expression will be updated
The expression supports Parameter Binding.
Every defined sort criterion follows the format:
name [ ASC | DESC ]
ASC is used by default if the sort order is not specified.
If used, the operation will update only numberOfRows rows.
This function can be called every time the statement is executed.
Binds the given value to the placeholder with the specified name.
An error will be raised if the placeholder indicated by name does not exist.
This function must be called once for each used placeholder or an error will be raised when the execute method is called.
Executes the delete operation with all the configured options.
TableDelete delete | ( | ) |
Creates a record deletion handler.
Table | .delete() |
[.where(expression)] | |
[.orderBy(...)] <tr><td></td><td>[.limit(numberOfRows)]</td></tr> <tr><td></td><td>[.bind(name, value)]</td></tr> <tr><td></td><td>.execute()</td></tr> |
Initializes the deletion operation.
If used, only those rows satisfying the expression will be deleted
The expression supports Parameter Binding.
Every defined sort criterion follows the format:
name [ ASC | DESC ]
ASC is used by default if the sort order is not specified.
If used, the operation will delete only numberOfRows rows.
This function can be called every time the statement is executed.
Binds the given value to the placeholder with the specified name.
An error will be raised if the placeholder indicated by name does not exist.
This function must be called once for each used placeholder or an error will be raised when the execute method is called.
Executes the delete operation with all the configured options.