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

Uploaded Source

File details

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

File metadata

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

File hashes

Hashes for d2a-0.0.3.tar.gz
Algorithm Hash digest
SHA256 f8851d74825532089cee660fb5f5ecf4b86bf7f347c4a56968ec4e476125d39f
MD5 ad7dd1e71e3025b245f8bec5b8fd90cf
BLAKE2b-256 298c4f50618a751b5e09ef0b61203f19baf08e67490d351e1fd85912d4fd18a8

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