Created
July 3, 2018 08:58
-
-
Save vincepota-zz/cffc43b297616d346e1999d84b9abdd9 to your computer and use it in GitHub Desktop.
Get vendor-specific data types in sqlalchemy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import importlib | |
class VendorType: | |
""" | |
Return a list of vendor-specific datatype as a list. | |
Parameters | |
---------- | |
vendor :str | |
One of: | |
-oracle | |
-mysql | |
-postgresql | |
-sqlite | |
-mssql | |
""" | |
def __init__(self, vendor): | |
self.vendor = vendor | |
def type_path(self): | |
return 'sqlalchemy.dialects.{}'.format(self.vendor) | |
def get_types(self): | |
mt = importlib.import_module(self.type_path()) | |
type_list = mt.__all__ | |
# only return uppercase types. This step also removes non-datatypes | |
# that somehow end up in __all__ | |
return [t for t in type_list if t.isupper()] | |
# For example : | |
vt = VendorType('sqlite').get_types() | |
print(vt) | |
# ['BLOB', 'BOOLEAN', 'CHAR', 'DATE', 'DATETIME', 'DECIMAL', 'FLOAT', 'INTEGER', 'NUMERIC', 'SMALLINT', 'TEXT', 'TIME', 'TIMESTAMP', 'VARCHAR', 'REAL'] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment