__init__.py 1.98 KB
Newer Older
Lukáš Lalinský's avatar
Lukáš Lalinský committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14
# Copyright 2015 Lukas Lalinsky
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

Lukáš Lalinský's avatar
Lukáš Lalinský committed
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
from phoenixdb import errors, types
from phoenixdb.avatica import AvaticaClient
from phoenixdb.connection import Connection
from phoenixdb.errors import *
from phoenixdb.types import *

__all__ = ['connect', 'apilevel', 'threadsafety', 'paramstyle'] + types.__all__ + errors.__all__


apilevel = "2.0"
"""
This module supports the `DB API 2.0 interface <https://www.python.org/dev/peps/pep-0249/>`_.
"""

threadsafety = 1
"""
Multiple threads can share the module, but neither connections nor cursors.
"""

paramstyle = 'qmark'
"""
Parmetrized queries should use the question mark as a parameter placeholder.

For example::

40
 cursor.execute("SELECT * FROM table WHERE id = ?", [my_id])
Lukáš Lalinský's avatar
Lukáš Lalinský committed
41 42 43
"""


44
def connect(url, max_retries=None, **kwargs):
Lukáš Lalinský's avatar
Lukáš Lalinský committed
45 46 47 48 49 50 51 52 53 54 55
    """Connects to a Phoenix query server.

    :param url:
        URL to the Phoenix query server, e.g. ``http://localhost:8765/``

    :param autocommit:
        Switch the connection to autocommit mode.

    :param readonly:
        Switch the connection to readonly mode.

56 57 58
    :param max_retries:
        The maximum number of retries in case there is a connection error.

59 60 61
    :param cursor_factory:
        If specified, the connection's :attr:`~phoenixdb.connection.Connection.cursor_factory` is set to it.

Lukáš Lalinský's avatar
Lukáš Lalinský committed
62 63 64
    :returns:
        :class:`~phoenixdb.connection.Connection` object.
    """
65
    client = AvaticaClient(url, max_retries=max_retries)
Lukáš Lalinský's avatar
Lukáš Lalinský committed
66 67
    client.connect()
    return Connection(client, **kwargs)