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: ? (not tested)

  • Django: 1.9 ~ 2.0 (not tested)

  • SQLAlchemy: 0.9 ~ 1.2 (not tested)

Installation

$ pip install d2a

Usage

altogether

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 transfer
    from . import models
    transfer(models, globals())
  • That’s all, you can import sqlalchemy declaration made from django model.

    >>> from demo import models
    >>> models.  # tab completion
    models.Author(            models.Category(          models.Sales(             models.uuid
    models.Book(              models.CategoryRelation(  models.models
    
    >>> models.Book
    <class 'demo.models.Book'>
    >>> models.Book.  # tab completion
    models.Book.DoesNotExist(             models.Book.delete(                   models.Book.price
    models.Book.MultipleObjectsReturned(  models.Book.description               models.Book.refresh_from_db(
    models.Book.add_to_class(             models.Book.from_db(                  models.Book.sales
    models.Book.author                    models.Book.full_clean(               models.Book.save(
    models.Book.author_id                 models.Book.get_deferred_fields(      models.Book.save_base(
    models.Book.category                  models.Book.id                        models.Book.serializable_value(
    models.Book.check(                    models.Book.mro(                      models.Book.title
    models.Book.clean(                    models.Book.objects                   models.Book.unique_error_message(
    models.Book.clean_fields(             models.Book.pk                        models.Book.validate_unique(
    
    >>> from demo import models_sqla
    >>> models_sqla.  # tab completion
    models_sqla.Author(            models_sqla.Category(          models_sqla.Sales(             models_sqla.transfer(
    models_sqla.Book(              models_sqla.CategoryRelation(  models_sqla.models
    
    >>> models_sqla.Book
    <class 'd2a.alchemy.book'>
    >>> models_sqla.Book.  # tab completion
    models_sqla.Book.author_id    models_sqla.Book.description  models_sqla.Book.metadata     models_sqla.Book.price
    models_sqla.Book.category     models_sqla.Book.id           models_sqla.Book.mro(         models_sqla.Book.title

single

You should write like the following:

>>> from d2a import copy
>>> from demo.models import Sales
>>> sales = copy(Sales)
>>> sales
<class 'd2a.alchemy.sales'>
>>> sales.__table__
Table('sales', MetaData(bind=None), Column('id', BigInteger(), table=<sales>, primary_key=True, nullable=False, default=ColumnDefault(<function ColumnDefault._maybe_wrap_callable.<locals>.<lambda> at 0x7f50bd7eb598>)), Column('book_id', CHAR(length=32), ForeignKey('book.id'), table=<sales>, nullable=False, default=ColumnDefault(<function ColumnDefault._maybe_wrap_callable.<locals>.<lambda> at 0x7f50bd7eb7b8>)), Column('sold', DateTime(), table=<sales>, nullable=False, default=ColumnDefault(<function ColumnDefault._maybe_wrap_callable.<locals>.<lambda> at 0x7f50bd7eb9d8>)), schema=None)

History

0.0.1:

first release (2017-12-27)

0.0.2:
  • it supported m2m field.

  • it limited django version less than 1.9.

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.2.tar.gz (4.5 kB view details)

Uploaded Source

File details

Details for the file d2a-0.0.2.tar.gz.

File metadata

  • Download URL: d2a-0.0.2.tar.gz
  • Upload date:
  • Size: 4.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for d2a-0.0.2.tar.gz
Algorithm Hash digest
SHA256 a30cafcaea2d4ff4745a3c6995395dc1ba0509e66aaf7cb89f9ea5b61989f994
MD5 dec7d15ebc7229922d89492c5f7ff1d8
BLAKE2b-256 308622e2ff732e12f03eaced88d463d15d11a63e9888ffb2c416e8710806fcd4

See more details on using hashes here.

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