當前位置: 首頁>>代碼示例>>Python>>正文


Python Connection.begin方法代碼示例

本文整理匯總了Python中sqlalchemy.engine.Connection.begin方法的典型用法代碼示例。如果您正苦於以下問題:Python Connection.begin方法的具體用法?Python Connection.begin怎麽用?Python Connection.begin使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在sqlalchemy.engine.Connection的用法示例。


在下文中一共展示了Connection.begin方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: update

# 需要導入模塊: from sqlalchemy.engine import Connection [as 別名]
# 或者: from sqlalchemy.engine.Connection import begin [as 別名]
def update(connection: Connection, data: dict):
    """
    Update a survey (title, questions). You can also add or modify questions
    here. Note that this creates a new survey (with new submissions, etc),
    copying everything from the old survey. The old survey's title will be
    changed to end with "(new version created on <time>)".

    :param connection: a SQLAlchemy Connection
    :param data: JSON containing the UUID of the survey and fields to update.
    """
    survey_id = data['survey_id']
    email = data['email']
    existing_survey = survey_select(connection, survey_id, email=email)
    if 'survey_metadata' not in data:
        data['survey_metadata'] = existing_survey.survey_metadata
    update_time = datetime.datetime.now()

    with connection.begin():
        new_title = '{} (new version created on {})'.format(
            existing_survey.survey_title, update_time.isoformat())
        executable = update_record(survey_table, 'survey_id', survey_id,
                                   survey_title=new_title)
        exc = [('survey_title_survey_owner_key',
                SurveyAlreadyExistsError(new_title))]
        execute_with_exceptions(connection, executable, exc)

        new_survey_id = _create_survey(connection, data)

    return get_one(connection, new_survey_id, email=email)
開發者ID:juniorsilver,項目名稱:dokomoforms,代碼行數:31,代碼來源:survey.py

示例2: refresh_and_diff_materialized_view

# 需要導入模塊: from sqlalchemy.engine import Connection [as 別名]
# 或者: from sqlalchemy.engine.Connection import begin [as 別名]
def refresh_and_diff_materialized_view(
        connection: Connection, view: Table, copy: Table,
        result_columns: Iterable[Column]) -> Tuple[
        List[Tuple], List[Tuple], List[Tuple]]:
    with connection.begin():
        lock_table(connection, view)
        create_temp_copy(connection, view, copy)
        refresh_materialized_view(connection, view)
        return diff_tables(connection, view, copy, result_columns)
開發者ID:agdsn,項目名稱:hades,代碼行數:11,代碼來源:db.py

示例3: delete

# 需要導入模塊: from sqlalchemy.engine import Connection [as 別名]
# 或者: from sqlalchemy.engine.Connection import begin [as 別名]
def delete(connection: Connection, survey_id: str):
    """
    Delete the survey specified by the given survey_id

    :param connection: a SQLAlchemy connection
    :param survey_id: the UUID of the survey
    """
    with connection.begin():
        connection.execute(delete_record(survey_table, 'survey_id', survey_id))
    return json_response('Survey deleted')
開發者ID:juniorsilver,項目名稱:dokomoforms,代碼行數:12,代碼來源:survey.py

示例4: create

# 需要導入模塊: from sqlalchemy.engine import Connection [as 別名]
# 或者: from sqlalchemy.engine.Connection import begin [as 別名]
def create(connection: Connection, data: dict) -> dict:
    """
    Create a survey with questions.

    :param connection: a SQLAlchemy Connection
    :param data: a JSON representation of the survey to be created
    :return: a JSON representation of the created survey
    """
    with connection.begin():
        survey_id = _create_survey(connection, data)

    return get_one(connection, survey_id, email=data['email'])
開發者ID:juniorsilver,項目名稱:dokomoforms,代碼行數:14,代碼來源:survey.py

示例5: create_user

# 需要導入模塊: from sqlalchemy.engine import Connection [as 別名]
# 或者: from sqlalchemy.engine.Connection import begin [as 別名]
def create_user(connection: Connection, data: dict) -> dict:
    """
    Registers a new user account.

    :param connection: a SQLAlchemy Connection
    :param data: the user's e-mail
    :return: a response containing the e-mail and whether it was created or
    already exists in the database
    """
    email = data['email']
    try:
        get_auth_user_by_email(connection, email)
    except UserDoesNotExistError:
        with connection.begin():
            connection.execute(create_auth_user(email=email))
        return json_response({'email': email, 'response': 'Created'})
    return json_response({'email': email, 'response': 'Already exists'})
開發者ID:juniorsilver,項目名稱:dokomoforms,代碼行數:19,代碼來源:user.py

示例6: generate_token

# 需要導入模塊: from sqlalchemy.engine import Connection [as 別名]
# 或者: from sqlalchemy.engine.Connection import begin [as 別名]
def generate_token(connection: Connection, data: dict) -> dict:
    """
    Generates a new API token for a user specified by e-mail address. You
    can supply a duration in seconds.

    :param connection: a SQLAlchemy Connection
    :param data: the user's e-mail and an optional duration
    :return: the generated token and the token's expiration time
    """
    user = get_auth_user_by_email(connection, data['email'])
    token = generate_api_token()
    params = {'token': token,
              'auth_user_id': user.auth_user_id}
    if 'duration' in data:
        duration = float(data['duration'])
        if duration > 31536000:
            raise TokenDurationTooLong(data['duration'])
        params['expiration'] = timedelta(seconds=duration)

    with connection.begin():
        connection.execute(set_api_token(**params))
    updated_user = get_auth_user_by_email(connection, data['email'])
    return json_response(
        {'token': token, 'expires_on': updated_user.expires_on.isoformat()})
開發者ID:juniorsilver,項目名稱:dokomoforms,代碼行數:26,代碼來源:user.py


注:本文中的sqlalchemy.engine.Connection.begin方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。