mysqlx.Schema

class mysqlx.Schema(session: Session, name: str)

Bases: DatabaseObject

A client-side representation of a database schema. Provides access to the schema contents.

Parameters:
  • session (mysqlx.XSession) – Session object.

  • name (str) – The Schema name.

am_i_real() Any

Verifies if this object exists in the database.

Returns:

True if object exists in database.

Return type:

bool

Raises:

NotImplementedError – This method must be implemented.

Deprecated since version 8.0.12: Use exists_in_database() method instead.

create_collection(name: str, reuse_existing: bool = False, validation: Dict[str, str | Dict] | None = None, **kwargs: Any) Collection

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

Parameters:
  • name (str) – The name of the collection.

  • reuse_existing (bool) – True to reuse an existing collection.

  • validation (Optional[dict]) – A dict, containing the keys level with the validation level and schema with a dict or a string representation of a JSON schema specification.

Returns:

Collection object.

Return type:

mysqlx.Collection

Raises:

Changed in version 8.0.21.

drop_collection(name: str) None

Drops a collection.

Parameters:

name (str) – The name of the collection to be dropped.

exists_in_database() bool

Verifies if this object exists in the database.

Returns:

True if object exists in database.

Return type:

bool

get_collection(name: str, check_existence: bool = False) Collection

Returns the collection of the given name for this schema.

Returns:

Collection object.

Return type:

mysqlx.Collection

get_collection_as_table(name: str, check_existence: bool = False) Table

Returns a a table object for the given collection

Returns:

Table object.

Return type:

mysqlx.Table

get_collections() List[Collection]

Returns a list of collections for this schema.

Returns:

List of Collection objects.

Return type:

list

get_connection() Connection

Returns the underlying connection.

Returns:

The connection object.

Return type:

mysqlx.connection.Connection

get_name() str

Returns the name of this database object.

Returns:

The name of this database object.

Return type:

str

get_schema() Schema

Returns the Schema object of this database object.

Returns:

The Schema object.

Return type:

mysqlx.Schema

get_session() Session

Returns the session of this database object.

Returns:

The Session object.

Return type:

mysqlx.Session

get_table(name: str, check_existence: bool = False) Table

Returns the table of the given name for this schema.

Returns:

Table object.

Return type:

mysqlx.Table

get_tables() List[Table]

Returns a list of tables for this schema.

Returns:

List of Table objects.

Return type:

list

get_view(name: str, check_existence: bool = False) View

Returns the view of the given name for this schema.

Returns:

View object.

Return type:

mysqlx.View

modify_collection(name: str, validation: Dict[str, str | Dict] | None = None) None

Modifies a collection using a JSON schema validation.

Parameters:
  • name (str) – The name of the collection.

  • validation (Optional[dict]) – A dict, containing the keys level with the validation level and schema with a dict or a string representation of a JSON schema specification.

Raises:

New in version 8.0.21.

property name: str

The name of this database object.

Type:

str

property schema: Schema

The Schema object.

Type:

mysqlx.Schema

property session: Session

The Session object.

Type:

mysqlx.Session

who_am_i() str

Returns the name of this database object.

Returns:

The name of this database object.

Return type:

str

Deprecated since version 8.0.12: Use get_name() method instead.