• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

georgia-tech-db / eva / #820

01 Oct 2023 02:22AM UTC coverage: 0.0% (-73.7%) from 73.748%
#820

push

circle-ci

Jiashen Cao
fix lint error

0 of 12361 relevant lines covered (0.0%)

0.0 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/evadb/third_party/databases/interface.py
1
# coding=utf-8
2
# Copyright 2018-2023 EvaDB
3
#
4
# Licensed under the Apache License, Version 2.0 (the "License");
5
# you may not use this file except in compliance with the License.
6
# You may obtain a copy of the License at
7
#
8
#     http://www.apache.org/licenses/LICENSE-2.0
9
#
10
# Unless required by applicable law or agreed to in writing, software
11
# distributed under the License is distributed on an "AS IS" BASIS,
12
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
# See the License for the specific language governing permissions and
14
# limitations under the License.
15
import importlib
×
16
import os
×
17
from contextlib import contextmanager
×
18

19
from evadb.executor.executor_utils import ExecutorError
×
20

21

22
def _get_database_handler(engine: str, **kwargs):
×
23
    """
24
    Return the database handler. User should modify this function for
25
    their new integrated handlers.
26
    """
27

28
    # Dynamically import the top module.
29
    try:
×
30
        mod = dynamic_import(engine)
×
31
    except ImportError:
32
        req_file = os.path.join(os.path.dirname(__file__), engine, "requirements.txt")
33
        if os.path.isfile(req_file):
34
            with open(req_file) as f:
35
                raise ImportError(f"Please install the following packages {f.read()}")
36

37
    if engine == "postgres":
×
38
        return mod.PostgresHandler(engine, **kwargs)
×
39
    elif engine == "sqlite":
×
40
        return mod.SQLiteHandler(engine, **kwargs)
×
41
    elif engine == "mysql":
×
42
        return mod.MysqlHandler(engine, **kwargs)
×
43
    elif engine == "mariadb":
×
44
        return mod.MariaDbHandler(engine, **kwargs)
×
45
    else:
46
        raise NotImplementedError(f"Engine {engine} is not supported")
47

48

49
@contextmanager
×
50
def get_database_handler(engine: str, **kwargs):
×
51
    handler = _get_database_handler(engine, **kwargs)
×
52
    try:
×
53
        resp = handler.connect()
×
54
        if not resp.status:
×
55
            raise ExecutorError(f"Cannot establish connection due to {resp.error}")
56
        yield handler
×
57
    finally:
58
        handler.disconnect()
×
59

60

61
def dynamic_import(handler_dir):
×
62
    import_path = f"evadb.third_party.databases.{handler_dir}.{handler_dir}_handler"
×
63
    return importlib.import_module(import_path)
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc