MySQL Shell API 9.2.0
Unified development interface for MySQL Products
Classes | Functions
mysqlx

Encloses the functions and classes available to interact with an X Protocol enabled MySQL Product. More...

Classes

class  Type
 Constants to represent data types of Column objects. More...
 
class  LockContention
 Constants to represent lock contention types. More...
 

Functions

Session getSession (ConnectionData connectionData, String password)
 Creates a Session instance using the provided connection data. More...
 
Expression expr (String expressionStr)
 Creates an Expression object based on a string. More...
 
Date dateValue (Integer year, Integer month, Integer day, Integer hour, Integer minutes, Integer seconds, Integer milliseconds)
 Creates a Date object which represents a date time. More...
 

Detailed Description

Encloses the functions and classes available to interact with an X Protocol enabled MySQL Product.

The objects contained on this module provide a full API to interact with the different MySQL Products implementing the X Protocol.

In the case of a MySQL Server the API will enable doing operations on the different database objects such as schema management operations and both table and collection management and CRUD operations. (CRUD: Create, Read, Update, Delete).

Intention of the module is to provide a full API for development through scripting languages such as JavaScript and Python, this would be normally achieved through a normal session.

To use the properties and functions available on this module you first need to import it.

mysql-js> var mysqlx = require('mysqlx');
// Then you can use the module functions and properties
// for example to create a session
mysql-js> var mySession = mysqlx.getSession('admin@localhost');
Any require(String module_name_or_path)
Loads the specified JavaScript module.
Definition: mod_shell.cc:70

When running the shell in interactive mode, this module is automatically imported.

Function Documentation

◆ getSession()

Session getSession ( ConnectionData  connectionData,
String  password 
)

Creates a Session instance using the provided connection data.

Parameters
connectionDataThe connection data for the session
passwordOptional password for the session
Returns
A Session

A Session object uses the X Protocol to allow executing operations on the connected MySQL Server.

Connection Data

The connection data may be specified in the following formats:

  • A URI string
  • A dictionary with the connection options

A basic URI string has the following format:

[scheme://][user[:password]@]<host[:port]|socket>[/schema][?option=value&option=value...]

For additional information about MySQL connection data, see Connection Data.

◆ expr()

Expression expr ( String  expressionStr)

Creates an Expression object based on a string.

Parameters
expressionStrThe expression to be represented by the object

An expression object is required in many operations on the X DevAPI.

Some applications of the expression objects include:

  • Creation of documents based on a JSON string
  • Defining calculated fields when inserting data on the database
  • Defining calculated fields when pulling data from the database

◆ dateValue()

Date dateValue ( Integer  year,
Integer  month,
Integer  day,
Integer  hour,
Integer  minutes,
Integer  seconds,
Integer  milliseconds 
)

Creates a Date object which represents a date time.

Parameters
yearThe year to be used in the new Date object.
monthThe month to be used in the new Date object.
dayThe month to be used in the new Date object.
hourOptional hour to be used in the new Date object.
minutesOptional minutes to be used in the new Date object.
secondsOptional seconds to be used in the new Date object.
millisecondsOptional milliseconds to be used in the new Date object.

This function creates a Date object containing:

  • A date value.
  • A date and time value.
  • A date and time value with milliseconds.