Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BIT column type raises NotImplementedError #1

Closed
rmackinnon opened this issue May 23, 2015 · 7 comments
Closed

BIT column type raises NotImplementedError #1

rmackinnon opened this issue May 23, 2015 · 7 comments

Comments

@rmackinnon
Copy link
Contributor

Using SQLAlchemy to process MySQL tables for an API I'm building, and one of the columns in my table happens to be type 'BIT'. This apparently isn't supported Marshmallow, but is a valid column type for SQLAlchemy's MySQL dialect. Any chance of a fix, or is there an easier work around in the Marshmallow-SQLAlchemy connector that I'm missing?

@hartror
Copy link

hartror commented May 23, 2015

Looks like there is a mapping dictionary that doesn't contain any MySQL specific columns. But it looks simple to add to.

What is the incoming/outgoing (json?) data for that field look like? Some sort of bitarray/bitstring?

@rmackinnon
Copy link
Contributor Author

When assigning value via MySQL you prefix it with a b and wrap it in a single quotes. When pushing via an API the value would be just an integer range of [0-1]*.

@rmackinnon
Copy link
Contributor Author

Added the following to convert.py, and looks pretty good. I'll can put together a patch tomorrow-ish:
mysql.BIT: fields.Integer,
mysql.TINYINT: fields.Integer,
mysql.SMALLINT: fields.Integer,
mysql.INTEGER: fields.Integer,
mysql.BIGINT: fields.Integer,
mysql.NUMERIC: fields.Decimal,
mysql.DECIMAL: fields.Decimal,
mysql.DATETIME: fields.DateTime,
mysql.DATE: fields.Date,
mysql.TIME: fields.Time,
mysql.YEAR: fields.Integer,
mysql.TEXT: fields.String,
mysql.TINYTEXT: fields.String,
mysql.MEDIUMTEXT: fields.String,
mysql.LONGTEXT: fields.String,
mysql.BLOB: fields.String,
mysql.TINYBLOB: fields.String,
mysql.MEDIUMBLOB: fields.String,
mysql.LONGBLOB: fields.String,
mysql.SET: fields.List,
mysql.ENUM: fields.Enum

@sloria
Copy link
Member

sloria commented May 23, 2015

@rmackinnon I would welcome the patch. Thanks in advance!

@rmackinnon
Copy link
Contributor Author

--- marshmallow_sqlalchemy/convert.py.orig  2015-05-23 13:01:14.798873745 -0700
+++ marshmallow_sqlalchemy/convert.py   2015-05-23 13:05:46.860472507 -0700
@@ -4,7 +4,7 @@
 import marshmallow as ma
 from marshmallow import validate, fields
 from marshmallow.compat import text_type
-from sqlalchemy.dialects import postgresql
+from sqlalchemy.dialects import postgresql, mysql
 from sqlalchemy.orm.util import identity_key
 import sqlalchemy as sa

@@ -37,9 +37,38 @@
         sa.Numeric: fields.Decimal,
         sa.Float: fields.Decimal,
         sa.Date: fields.Date,
+
         postgresql.UUID: fields.UUID,
         postgresql.MACADDR: fields.String,
         postgresql.INET: fields.String,
+
+        mysql.BIT: fields.Integer,
+        mysql.TINYINT: fields.Integer,
+        mysql.SMALLINT: fields.Integer,
+        mysql.INTEGER: fields.Integer,
+        mysql.BIGINT: fields.Integer,
+
+        mysql.NUMERIC: fields.Decimal,
+        mysql.DECIMAL: fields.Decimal,
+
+        mysql.DATETIME: fields.DateTime,
+        mysql.DATE: fields.Date,
+        mysql.TIME: fields.Time,
+        mysql.YEAR: fields.Integer,
+
+        mysql.TEXT: fields.String,
+        mysql.TINYTEXT: fields.String,
+        mysql.MEDIUMTEXT: fields.String,
+        mysql.LONGTEXT: fields.String,
+
+        mysql.BLOB: fields.String,
+        mysql.TINYBLOB: fields.String,
+        mysql.MEDIUMBLOB: fields.String,
+        mysql.LONGBLOB: fields.String,
+
+        mysql.SET: fields.List,
+        mysql.ENUM: fields.Enum
+
     }

     DIRECTION_MAPPING = {

@sloria
Copy link
Member

sloria commented May 24, 2015

@rmackinnon Would you like to send a pull request with the above change?

rmackinnon added a commit to rmackinnon/marshmallow-sqlalchemy that referenced this issue May 26, 2015
@rmackinnon
Copy link
Contributor Author

:D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants