관리-도구
편집 파일: crud.cpython-38.pyc
U )�e�B � @ s� d Z ddlmZ ddlmZmZmZmZmZm Z m Z mZmZm Z mZmZmZ dZdZdZdZdZd ZG d d� de�ZG dd � d e�ZG dd� de�ZG dd� de�ZG dd� de�ZdS )z,Implementation of the CRUD database objects.� )�ProgrammingError) � FindStatement�AddStatement�RemoveStatement�ModifyStatement�SelectStatement�InsertStatement�DeleteStatement�UpdateStatement�CreateCollectionIndexStatement�DropCollectionIndexStatement�CreateViewStatement�AlterViewStatement�CreateTableStatementz_SELECT COUNT(*) FROM information_schema.views WHERE table_schema = '{0}' AND table_name = '{1}'z`SELECT COUNT(*) FROM information_schema.tables WHERE table_schema = '{0}' AND table_name = '{1}'zMSELECT COUNT(*) FROM information_schema.schemata WHERE schema_name like '{0}'z SELECT COUNT(*) FROM `{0}`.`{1}`z DROP TABLE IF EXISTS `{0}`.`{1}`zDROP VIEW IF EXISTS `{0}`.`{1}`c @ sX e Zd ZdZdd� Zedd� �Zedd� �Zdd � Zd d� Z dd � Z dd� Zdd� ZdS )�DatabaseObjectz�Provides base functionality for database objects. Args: schema (mysqlx.Schema): The Schema object. name (str): The database object name. c C s || _ || _| j �� j| _d S �N)�_schema�_name�get_session�_connection��self�schema�name� r �`/opt/hc_python/lib64/python3.8/site-packages/../../../lib/python3.8/site-packages/mysqlx/crud.py�__init__5 s zDatabaseObject.__init__c C s | j S )z3:class:`mysqlx.Schema`: The Schema object. �r �r r r r r : s zDatabaseObject.schemac C s | j S )z/str: The name of this database object. �r r r r r r @ s zDatabaseObject.namec C s | j S )z{Returns the Schema object of this database object. Returns: mysqlx.Schema: The Schema object. r r r r r � get_schemaF s zDatabaseObject.get_schemac C s | j S )zwReturns the name of this database object. Returns: str: The name of this database object. r r r r r �get_nameN s zDatabaseObject.get_namec C s t �dS )z�Verifies if this object exists in the database. Returns: bool: `True` if object exists in database. Raises: NotImplementedError: This method must be implemented. N)�NotImplementedErrorr r r r �exists_in_databaseV s z!DatabaseObject.exists_in_databasec C s | � � S r )r# r r r r � am_i_reala s zDatabaseObject.am_i_realc C s | � � S r )r! r r r r �who_am_id s zDatabaseObject.who_am_iN) �__name__� __module__�__qualname__�__doc__r �propertyr r r r! r# r$ r% r r r r r . s r c s� e Zd ZdZ� fdd�Zdd� Zdd� Zdd � Zd#dd�Zd d� Z d$dd�Z d%dd�Zd&dd�Zdd� Z dd� Zdd� Zd'dd�Zd(dd�Zdd � Zd)d!d"�Z� ZS )*�Schemaz�A client-side representation of a database schema. Provides access to the schema contents. Args: session (mysqlx.XSession): Session object. name (str): The Schema name. c s || _ tt| ��| |� d S r )�_session�superr+ r )r �sessionr �� __class__r r r p s zSchema.__init__c C s t �| j�}| j�|�dkS �z�Verifies if this object exists in the database. Returns: bool: `True` if object exists in database. r )�_COUNT_SCHEMAS_QUERY�formatr r �execute_sql_scalar�r �sqlr r r r# t s zSchema.exists_in_databasec C s | j S )zuReturns the session of this Schema object. Returns: mysqlx.Session: The Session object. )r, r r r r r } s zSchema.get_sessionc C s~ | j �d| j�}|�� g }|D ]X}|�d�dkr4q zt| |�d��}W n$ tk rl t| |�d��}Y nX |�|� q |S )zwReturns a list of collections for this schema. Returns: list: List of Collection objects. �list_objects�typeZ COLLECTION� TABLE_NAMEr )r �get_row_resultr � fetch_all� get_string� Collection� ValueError�append)r �rows�collections�row� collectionr r r �get_collections� s zSchema.get_collectionsFc C s | � ||�S )zuReturns a a table object for the given collection Returns: mysqlx.Table: Table object. )� get_table)r r �check_existencer r r �get_collection_as_table� s zSchema.get_collection_as_tablec C s� | j �d| j�}|�� g }d}|D ]V}|�d�|kr$zt| |�d��}W n$ tk rn t| |�d��}Y nX |�|� q$|S )zmReturns a list of tables for this schema. Returns: list: List of Table objects. r7 )ZTABLEZVIEWr8 r9 r )r r: r r; r<