-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy path__init__.py
More file actions
87 lines (69 loc) · 2.58 KB
/
__init__.py
File metadata and controls
87 lines (69 loc) · 2.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#
# Copyright 2021 GridGain Systems, Inc. and Contributors.
#
# Licensed under the GridGain Community Edition License (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.gridgain.com/products/software/community-edition/gridgain-community-edition-license
#
# 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.
#
from .dbclient import DBClient
from .errors import *
from .. import constants
from urllib.parse import urlparse, parse_qs
apiLevel = '2.0'
threadsafety = 2
paramstyle = 'qmark'
def connect(dsn=None,
user=None, password=None,
host=constants.IGNITE_DEFAULT_HOST, port=constants.IGNITE_DEFAULT_PORT,
**kwargs):
"""
Create a new database connection.
The connection can be specified via DSN:
``conn = connect("ignite://localhost/test?param1=value1&...")``
or using database and credentials arguments:
``conn = connect(database="test", user="default", password="default",
host="localhost", **kwargs)``
The basic connection parameters are:
- *host*: host with running Ignite server.
- *port*: port Ignite server is bound to.
- *database*: database connect to.
- *user*: database user.
- *password*: user's password.
See defaults in :data:`~pyignite.connection.Connection`
constructor.
DSN or host is required.
Any other keyword parameter will be passed to the underlying Connection
class.
:return: a new connection.
"""
if dsn is not None:
parsed_dsn = _parse_dsn(dsn)
host = parsed_dsn['host']
port = parsed_dsn['port']
client = DBClient()
client.connect(host, port)
return client
def _parse_dsn(dsn):
url_components = urlparse(dsn)
host = url_components.hostname
port = url_components.port or 10800
if url_components.path is not None:
schema = url_components.path.replace('/', '')
else:
schema = 'PUBLIC'
schema = url_components.path
return { 'host':host, 'port':port, 'schema':schema }
__all__ = [
'connect', 'apiLevel', 'threadsafety', 'paramstyle',
'Warning', 'Error', 'DataError', 'DatabaseError', 'ProgrammingError',
'IntegrityError', 'InterfaceError', 'InternalError', 'NotSupportedError',
'OperationalError', 'IgniteDialect'
]