Beispiel #1
0
    def _init_db(self, engine):
        """Connect to database and create tables.

        Parameters
        ----------
        txn : sa.engine.Connection, optional
            The transaction to execute in. If this is not provided, a new
            transaction will be started with the engine provided.

        Returns
        -------
        metadata : sa.MetaData
            The metadata that describes the new asset db.
        """
        with ExitStack() as stack:
            # if txn is None:
            txn = stack.enter_context(engine.connect())
            tables_already_exist = self._all_tables_present(txn)
            # Create the SQL tables if they do not already exist.
            if not tables_already_exist:
                metadata.create_all(txn, checkfirst=True)
            # 将table
            metadata.reflect(only=asset_db_table_names)
            for table_name in asset_db_table_names:
                setattr(self, table_name, metadata.tables[table_name])
Beispiel #2
0
    def _init_db(self, txn=None):
        """Connect to database and create tables.

        Parameters
        ----------
        txn : sa.engine.Connection, optional
            The transaction to execute in. If this is not provided, a new
            transaction will be started with the engine provided.

        Returns
        -------
        metadata : sa.MetaData
            The metadata that describes the new asset db.
        """
        with ExitStack() as stack:
            if txn is None:
                txn = stack.enter_context(self.engine.begin())
            tables_already_exist = self._all_tables_present(txn)
            if not tables_already_exist:
                # Create the SQL tables if they do not already exist.
                metadata.create_all(txn, checkfirst=True)
Beispiel #3
0
    def _init_db(self, engine):
        """Connect to database and create tables.

        with ExitStack() as stack:
            由于已注册的回调是按注册的相反顺序调用的,因此最终行为就好像with 已将多个嵌套语句与已注册的一组回调一起使用。
            这甚至扩展到异常处理-如果内部回调抑制或替换异常,则外部回调将基于该更新状态传递自变量。
            enter_context  输入一个新的上下文管理器,并将其__exit__()方法添加到回调堆栈中。返回值是上下文管理器自己的__enter__()方法的结果。
            callback(回调,* args,** kwds )接受任意的回调函数和参数,并将其添加到回调堆栈中。
            stack.callback(on_exit())
            stack.enter_context(ZiplineAPI(self.algo))

        Parameters
        ----------
        txn : sa.engine.Connection, optional
            The transaction to execute in. If this is not provided, a new
            transaction will be started with the engine provided.

        Returns
        -------
        metadata : sa.MetaData
            The metadata that describes the new asset db.


        """

        with ExitStack() as stack:
            # if txn is None:
            txn = stack.enter_context(engine.connect())
            tables_already_exist = self._all_tables_present(txn)
            # Create the SQL tables if they do not already exist.
            if not tables_already_exist:
                metadata.create_all(txn, checkfirst=True)
            # 将table
            metadata.reflect(only=asset_db_table_names)
            for table_name in asset_db_table_names:
                setattr(self, table_name, metadata.tables[table_name])
Beispiel #4
0
    # 融券余额
    sa.Column('rqye', sa.Numeric(15, 8), nullable=False),
    extend_existing=True)

# 版本
version_info = sa.Table(
    'version_info',
    metadata,
    sa.Column('id', sa.Integer, default=0, autoincrement=True),
    sa.Column(
        'version',
        sa.Integer,
        unique=True,
        nullable=False,
    ),
    # This constraint ensures a single entry in this table
    sa.CheckConstraint('id <= 1'),
    extend_existing=True)

asset_db_table_names = frozenset(
    ['asset_router', 'equity_status', 'equity_basics', 'convertible_basics'])

metadata.create_all(bind=engine)

__all__ = [
    'm_cap', 'holder', 'unfreeze', 'massive', 'ownership', 'fund_price',
    'version_info', 'asset_router', 'equity_status', 'equity_basics',
    'equity_price', 'equity_splits', 'equity_rights', 'convertible_basics',
    'convertible_price', 'asset_db_table_names'
]