MySQL Shell API 8.4.3
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 get_tables ()
 Returns a list of Tables for this Schema. More...
 
list get_collections ()
 Returns a list of Collections for this Schema. More...
 
Table get_table (str name)
 Returns the Table of the given name for this schema. More...
 
Collection get_collection (str name)
 Returns the Collection of the given name for this schema. More...
 
Table get_collection_as_table (str name)
 Returns a Table object representing a Collection on the database. More...
 
Collection create_collection (str name, dict options)
 Creates in the current schema a new collection with the specified name and retrieves an object representing the new collection created. More...
 
None modify_collection (str name, dict options)
 Modifies the schema validation of a collection. More...
 
None drop_collection (str name)
 Drops the specified collection. More...
 
- Methods inherited from DatabaseObject
str get_name ()
 Returns the name of this database object.

Returns
The name this database object.

 
object get_session ()
 Returns the Session object of this database object.

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

Returns
The Schema object used to get to this object.
More...
 
bool exists_in_database ()
 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
str 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

◆ get_tables()

list get_tables ( )

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.

◆ get_collections()

list get_collections ( )

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.

◆ get_table()

Table get_table ( str  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

◆ get_collection()

Collection get_collection ( str  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

◆ get_collection_as_table()

Collection get_collection_as_table ( str  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.

◆ create_collection()

Collection create_collection ( str  name,
dict  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.

◆ modify_collection()

None modify_collection ( str  name,
dict  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.

◆ drop_collection()

None drop_collection ( str  name)

Drops the specified collection.

Returns
Nothing.