Skip to content

Add support for SET column type [wishlist]  #31

Open
@ernstki

Description

@ernstki

sqlacodegen seems to work fine with ENUM types; SETs are a different story.

If you attempt to run on a database with a SET column type, such as the following:

CREATE TABLE `tools_datasets` (
    `tool_id` int(11) NOT NULL,
    `dataset_id` int(11) NOT NULL,
    `status` SET('p','i','e') DEFAULT 'i,e',
    PRIMARY KEY (`tool_id`,`dataset_id`),
);

you'll get an error like this:

$ flask-sqlacodegen --version
1.1.6.1
$ flask-sqlacodegen --tables tools_datasets $DBCONN
Traceback (most recent call last):
  File "/Users/user/path/to/project/venv/bin/flask-sqlacodegen", line 11, in <module>
    sys.exit(main())
  File "/Users/user/path/to/project/venv/lib/python2.7/site-packages/sqlacodegen/main.py", line 59, in main
    args.flask, ignore_cols, args.noclasses)
  File "/Users/user/path/to/project/venv/lib/python2.7/site-packages/sqlacodegen/codegen.py", line 606, in __init__
    model = ModelClass(table, links[table.name], inflect_engine, not nojoined)
  File "/Users/user/path/to/project/venv/lib/python2.7/site-packages/sqlacodegen/codegen.py", line 309, in __init__
    super(ModelClass, self).__init__(table)
  File "/Users/user/path/to/project/venv/lib/python2.7/site-packages/sqlacodegen/codegen.py", line 248, in __init__
    column.type = column.type.adapt(cls)
  File "/Users/user/path/to/project/venv/lib/python2.7/site-packages/sqlalchemy/dialects/mysql/enumerated.py", line 310, in adapt
    **kw
  File "/Users/user/path/to/project/venv/lib/python2.7/site-packages/sqlalchemy/util/langhelpers.py", line 1045, in constructor_copy
    return cls(*args, **kw)
TypeError: __init__() got an unexpected keyword argument 'retrieve_as_bitwise'

I know that the SET column type is kind of out in the weeds (maybe it's better to just use a many-to-many relationship), but honestly, is ENUM is kind of in that category, too , so maybe we could work to support SET as well.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions