MySQL Shell API 8.0.40
Unified development interface for MySQL Products
Methods | List of all members
Schema Class Reference

Represents a Schema as retrieved from a session created using the X Protocol. More...

Methods

List getTables ()
 Returns a list of Tables for this Schema. More...
 
List getCollections ()
 Returns a list of Collections for this Schema. More...
 
Table getTable (String name)
 Returns the Table of the given name for this schema. More...
 
Collection getCollection (String name)
 Returns the Collection of the given name for this schema. More...
 
Table getCollectionAsTable (String name)
 Returns a Table object representing a Collection on the database. More...
 
Collection createCollection (String name, Dictionary options)
 Creates in the current schema a new collection with the specified name and retrieves an object representing the new collection created. More...
 
Undefined modifyCollection (String name, Dictionary options)
 Modifies the schema validation of a collection. More...
 
Undefined dropCollection (String name)
 Drops the specified collection. More...
 
- Methods inherited from DatabaseObject
String getName ()
 Returns the name of this database object.

Returns
The name this database object.

 
Object getSession ()
 Returns the Session object of this database object.

Returns
The Session object used to get to this object.
More...
 
Object getSchema ()
 Returns the Schema object of this database object.

Returns
The Schema object used to get to this object.
More...
 
Bool existsInDatabase ()
 Verifies if this object exists in the database.

Returns
A boolean indicating if the object still exists on 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.
 

Detailed Description

Represents a Schema as retrieved from a session created using the X Protocol.

View Support

MySQL Views are stored queries that when executed produce a result set.

MySQL supports the concept of Updatable Views: in specific conditions are met, Views can be used not only to retrieve data from them but also to update, add and delete records.

For the purpose of this API, Views behave similar to a Table, and so they are treated as Tables.

Tables and Collections as Properties

A Schema object may expose tables and collections as properties, this way they can be accessed as:

This handy way of accessing tables and collections is available if they met the following conditions:

If any of the conditions is not met, the way to access the table or collection is by using the standard DevAPI functions:

Member Function Documentation

◆ getTables()

List getTables ( )

Returns a list of Tables for this Schema.

See also
Table
Returns
A List containing the Table objects available for the Schema.

Pulls from the database the available Tables, Views and Collections.

Does a full refresh of the Tables, Views and Collections cache.

Returns a List of available Table objects.

◆ getCollections()

List getCollections ( )

Returns a list of Collections for this Schema.

See also
Collection
Returns
A List containing the Collection objects available for the Schema.

Pulls from the database the available Tables, Views and Collections.

Does a full refresh of the Tables, Views and Collections cache.

Returns a List of available Collection objects.

◆ getTable()

Table getTable ( String  name)

Returns the Table of the given name for this schema.

Parameters
namethe name of the Table to look for.
Returns
the Table object matching the name.

Verifies if the requested Table exist on the database, if exists, returns the corresponding Table object.

Updates the Tables cache.

See also
Table

◆ getCollection()

Collection getCollection ( String  name)

Returns the Collection of the given name for this schema.

Parameters
namethe name of the Collection to look for.
Returns
the Collection object matching the name.

Verifies if the requested Collection exist on the database, if exists, returns the corresponding Collection object.

Updates the Collections cache.

See also
Collection

◆ getCollectionAsTable()

Collection getCollectionAsTable ( String  name)

Returns a Table object representing a Collection on the database.

Parameters
namethe name of the collection to be retrieved as a table.
Returns
the Table object representing the collection or undefined.

◆ createCollection()

Collection createCollection ( String  name,
Dictionary  options 
)

Creates in the current schema a new collection with the specified name and retrieves an object representing the new collection created.

Parameters
namethe name of the collection.
optionsoptional dictionary with options.
Returns
the new created collection.

To specify a name for a collection, follow the naming conventions in MySQL.

The options dictionary may contain the following attributes:

  • reuseExistingObject: boolean, indicating if the call should succeed when collection with the same name already exists.
  • validation: object defining JSON schema validation for the collection.

The validation object allows the following attributes:

  • level: which can be either 'strict' or 'off'.
  • schema: a JSON schema specification as described at json-schema.org.

◆ modifyCollection()

Undefined modifyCollection ( String  name,
Dictionary  options 
)

Modifies the schema validation of a collection.

Parameters
namethe name of the collection.
optionsdictionary with options.

The options dictionary may contain the following attributes:

  • validation: object defining JSON schema validation for the collection.

The validation object allows the following attributes:

  • level: which can be either 'strict' or 'off'.
  • schema: a JSON schema specification as described at json-schema.org.

◆ dropCollection()

Undefined dropCollection ( String  name)

Drops the specified collection.

Returns
Nothing.