Skip to main content

it converts a django model to a sqlalchemy declaration

Project description

it converts a django model to a sqlalchemy declaration.

Requirements

  • Python 3.6 (not tested)

  • Django 1.4 ~ 1.11 (not tested)

Install

$ pip install d2a

Usage

  • For example you make models_sqla.py at a directory which models.py has been placed on.

  • And write like the following to the models_sqla.py:

    from d2a import copy
    from . import models
    copy(models, globals())
  • That’s all, you can import sqlalchemy declaration made from django model.

    • Example: demo/models.py and demo/models_sqla.py exist.

    >>> from demo import models
    <module 'demo.models' from 'djangomodel2alchemymap/sample/demo/models.py'>
    >>> models.  # tab tab tab -> Test is declared.
    models.Test(   models.models  models.uuid
    >>> from demo import models_sqla
    >>> models_sqla.Test  # Test is declared as sqlalchemy declaration !
    <class 'd2a.alchemy.test_table'>
    >>> models_sqla.Test.__table__  # and got Table ! yatta!
    Table('test_table', MetaData(bind=None), Column('id', CHAR(length=32), table=<test_table>, primary_key=True, nullable=False), Column('no', INTEGER(), table=<test_table>, nullable=False), Column('created', DateTime(), table=<test_table>, nullable=False), Column('updated', DateTime(), table=<test_table>, nullable=False), Column('type', VARCHAR(length=20), table=<test_table>, nullable=False), Column('description', Text(), table=<test_table>), Column('status', VARCHAR(length=10), table=<test_table>), Column('category', VARCHAR(length=255), table=<test_table>), schema=None)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

d2a-0.0.1.tar.gz (3.5 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page