Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.11/site-packages/sqlalchemy_utils/types/bit.py: 93%

Shortcuts on this page

r m x   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

14 statements  

1import sqlalchemy as sa 

2from sqlalchemy.dialects.postgresql import BIT 

3 

4 

5class BitType(sa.types.TypeDecorator): 

6 """ 

7 BitType offers way of saving BITs into database. 

8 """ 

9 

10 impl = sa.types.BINARY 

11 

12 cache_ok = True 

13 

14 def __init__(self, length=1, **kwargs): 

15 self.length = length 

16 sa.types.TypeDecorator.__init__(self, **kwargs) 

17 

18 def load_dialect_impl(self, dialect): 

19 # Use the native BIT type for drivers that has it. 

20 if dialect.name == 'postgresql': 

21 return dialect.type_descriptor(BIT(self.length)) 

22 elif dialect.name == 'sqlite': 

23 return dialect.type_descriptor(sa.String(self.length)) 

24 else: 

25 return dialect.type_descriptor(type(self.impl)(self.length))