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.BookCategory(      models_sqla.CategoryRelation(  models_sqla.models
    models_sqla.Book(              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 declare
>>> from demo.models import Sales
>>> sales = declare(Sales)
>>> sales
<class 'd2a.alchemy.sales'>
>>> sales.__table__
Table('sales', MetaData(bind=None), Column('id', BIGINT(), table=<sales>, primary_key=True, nullable=False), Column('book_id', CHAR(length=32), ForeignKey('book.id'), table=<sales>), Column('sold', DateTime(), table=<sales>), 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.

0.0.3:
  • it got easy to declare custom field.

  • transfer method can define secondary table.

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

Uploaded Source

File details

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

File metadata

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

File hashes

Hashes for d2a-0.0.4.tar.gz
Algorithm Hash digest
SHA256 977ff69ba23888a69834afd6c99d9dbc027c5102fd1632751df16c53cae2327c
MD5 93a85f14154c8fc40faca87322c8ee50
BLAKE2b-256 24f9807a5e9b72603ed9104468729b0450815f0ba5bd2d683d447ec2936941ef

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