Giter VIP home page Giter VIP logo

aldjemy's Introduction

Aldjemy

Whats new?

2011-12-15:

  • Add M2M models generations. Storing them on core.Cache.models.

2011-12-14:

  • Added M2M fields generation. Now we dont generate models for m2m tables.
  • Sqlite datetime double conversion fix

Before:

  • mixins support

Base

Small package for integration SQLAlchemy into an existent Django project. The primary use case of this package is building complex queries that are not possible with the Django ORM.

You need to include aldjemy at the end of INSTALLED_APPS. When models are imported, aldjemy will read all models and contribute sa attribute to them. sa attribute is a class, mapped to Table class.

Internally, aldjemy generates tables from Django models. This is an important distinction from the standard decision of using SQLAlchemy reflection.

Code example:

User.sa.query().filter(User.sa.username=='Brubeck')

M2M sample:

User.sa.query().join(User.sa.groups).filter(Group.sa.name=="GROUP_NAME")

Explicit joins is part of SQLAlchemy philosophy, so aldjemy can't get you exactly the same experience as Django. But aldjemy is not positioned as Django ORM drop-in replacement. It's a helper for special situations.

We have some stuff in the aldjemy cache too:

from aldjemy import core
core.Cache.models # All generated models
core.get_tables() # All tables, and M2M tables too

You can use this stuff if you need - maybe you want to build queries with tables, or something like this.

Settings

You can add your own field types to map django types to sqlalchemy ones with ALDJEMY_DATA_TYPES settings parameter. Parameter must be a dict, key is result of field.get_internal_type(), value must be a one arg function. You can get idea from aldjemy.types.

Also it is possible to extend/override list of supported SQLALCHEMY engines using ALDJEMY_ENGINES settings parameter. Parameter should be a dict, key is substring after last dot from Django database engine setting (e.g. sqlite3 from django.db.backends.sqlite3), value is SQLAlchemy driver which will be used for connection (e.g. sqlite, sqlite+pysqlite). It could be helpful if you want to use django-postgrespool.

Mixins

Often django models have helper function and properties that helps to represent the model's data (__unicode__), or represent some model based logic.

To integrate it with aldjemy models you can put these methods into a separate mixin:

class TaskMixin(object):
    def __unicode__(self):
        return self.code

class Task(TaskMixin, models.Model):
    aldjemy_mixin = TaskMixin
    code = models.CharField(_('code'), max_length=32, unique=True)

Voilà! You can use unicode on aldjemy classes, because this mixin will be mixed into generated aldjemy model.

aldjemy's People

Contributors

deepwalker avatar vpotter avatar ildus avatar kipanshi avatar lucian1900 avatar nvlbud avatar erikcw avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.