Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #142 from dimagi/cz/data-types
Add explicit data type support
- Loading branch information
Showing
13 changed files
with
262 additions
and
97 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import sqlalchemy | ||
|
||
DATA_TYPE_TEXT = 'text' | ||
DATA_TYPE_BOOLEAN = 'boolean' | ||
DATA_TYPE_DATE = 'date' | ||
DATA_TYPE_DATETIME = 'datetime' | ||
DATA_TYPE_INTEGER = 'integer' | ||
|
||
DATA_TYPES_TO_SQLALCHEMY_TYPES = { | ||
DATA_TYPE_BOOLEAN: sqlalchemy.Boolean(), | ||
DATA_TYPE_DATETIME: sqlalchemy.DateTime(), | ||
DATA_TYPE_DATE: sqlalchemy.Date(), | ||
DATA_TYPE_INTEGER: sqlalchemy.Integer(), | ||
} | ||
|
||
class UnknownDataType(Exception): | ||
pass | ||
|
||
|
||
def get_sqlalchemy_type(data_type): | ||
if data_type not in DATA_TYPES_TO_SQLALCHEMY_TYPES: | ||
raise UnknownDataType(data_type) | ||
else: | ||
return DATA_TYPES_TO_SQLALCHEMY_TYPES[data_type] |
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
|
||
|
||
class TableSpec: | ||
|
||
def __init__(self, name, headings, rows, data_types=None): | ||
self.name = name | ||
self.headings = headings | ||
self.rows = rows | ||
self.data_types = data_types or [] | ||
|
||
def __eq__(self, other): | ||
return ( | ||
isinstance(other, TableSpec) | ||
and other.name == self.name | ||
and other.headings == self.headings | ||
and other.rows == self.rows | ||
and other.data_types == self.data_types | ||
) | ||
|
||
def toJSON(self): | ||
return { | ||
'name': self.name, | ||
'headings': self.headings, | ||
'rows': self.rows, | ||
'data_types': self.data_types, | ||
} |
Oops, something went wrong.