mysqlx.Schema¶
- class mysqlx.Schema(session: SessionType, name: str)¶
 Bases:
DatabaseObjectA 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:
 - Raises:
 mysqlx.ProgrammingError – If
reuse_existingis False and collection exists or the collection name is invalid.mysqlx.NotSupportedError – If schema validation is not supported by the server.
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:
 
- 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:
 
- get_collections() List[Collection]¶
 Returns a list of collections for this schema.
- Returns:
 List of Collection objects.
- Return type:
 list
- get_connection() ConnectionType¶
 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:
 
- get_session() SessionType¶
 Returns the session of this database object.
- Returns:
 The Session object.
- Return type:
 
- get_table(name: str, check_existence: bool = False) Table¶
 Returns the table of the given name for this schema.
- Returns:
 Table object.
- Return type:
 
- 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:
 
- 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:
 mysqlx.ProgrammingError – If the collection name or validation is invalid.
mysqlx.NotSupportedError – If schema validation is not supported by the server.
New in version 8.0.21.
- property name: str¶
 The name of this database object.
- Type:
 str
- property session: SessionType¶
 The Session object.
- Type:
 
- 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.