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

xzkostyan / clickhouse-sqlalchemy / 11405726556

18 Oct 2024 02:28PM UTC coverage: 85.988% (-0.09%) from 86.082%
11405726556

push

github

xzkostyan
Version bumped to 0.2.7

1 of 1 new or added line in 1 file covered. (100.0%)

63 existing lines in 11 files now uncovered.

2332 of 2712 relevant lines covered (85.99%)

20.04 hits per line

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

95.24
/clickhouse_sqlalchemy/ext/declarative.py
1
import re
16✔
2

3
from sqlalchemy import Column
24✔
4
from sqlalchemy.ext.declarative import DeclarativeMeta, declarative_base
24✔
5

6
from ..sql.schema import Table
24✔
7

8

9
class ClickHouseDeclarativeMeta(DeclarativeMeta):
24✔
10
    """
11
    Generates __tablename__ automatically. Taken from flask-sqlalchemy.
12
    Also adds custom __table_cls__.
13
    """
14
    _camelcase_re = re.compile(r'([A-Z]+)(?=[a-z0-9])')
24✔
15

16
    def __new__(cls, name, bases, d):
24✔
17
        tablename = d.get('__tablename__')
24✔
18

19
        has_pks = any(
24✔
20
            v.primary_key for k, v in d.items() if isinstance(v, Column)
21
        )
22

23
        # generate a table name automatically if it's missing and the
24
        # class dictionary declares a primary key.  We cannot always
25
        # attach a primary key to support model inheritance that does
26
        # not use joins.  We also don't want a table name if a whole
27
        # table is defined
28
        if not tablename and d.get('__table__') is None and has_pks:
24✔
29
            def _join(match):
24✔
30
                word = match.group()
24✔
31
                if len(word) > 1:
24✔
UNCOV
32
                    return ('_%s_%s' % (word[:-1], word[-1])).lower()
×
33
                return '_' + word.lower()
24✔
34
            d['__tablename__'] = cls._camelcase_re.sub(_join, name).lstrip('_')
24✔
35

36
        if '__table_cls__' not in d:
24✔
37
            d['__table_cls__'] = Table
24✔
38

39
        return DeclarativeMeta.__new__(cls, name, bases, d)
24✔
40

41

42
def get_declarative_base(metadata=None):
24✔
43
    return declarative_base(
24✔
44
        metadata=metadata, metaclass=ClickHouseDeclarativeMeta
45
    )
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