views:

76

answers:

3

... vs declarative sqlalchemy ?

+2  A: 

You could say that Elixir has been made because SQLAlchemy is not declarative enough for some people.

From the Elixir website:

Elixir is intended to replace the ActiveMapper SQLAlchemy extension, and the TurboEntity project but does not intend to replace SQLAlchemy's core features, and instead focuses on providing a simpler syntax for defining model objects when you do not need the full expressiveness of SQLAlchemy's manual mapper definitions.

Toni Ruža
A: 

The Elixir syntax is something I find useful when building a database for a given app from scratch and everything is all figured out beforehand.

I have had my best luck with SQLAlchemy when using it on legacy databases (and on other similarly logistically immutable schemas). Particularly useful is the plugin SQLSoup, for read-only one-time extractions of data in preparation for migrating it elsewhere.

YMMV but Elixir isn't really designed to adapt to older schemas -- and SQLAlchemy proper is overkill for most small- to mid-size projects (in my opinion of course).

fish2000
+1  A: 

I have started a list here on practical (technical) differences / advantages of elixir vs. sqlalchmey, but I don't know if my claims are right because my knowledge about sqlalchemy is very restricted (I use a very small portion of elixir and sqla).

It would be very proof-wise that answers show a code example in sqla and the equivalent in elixir to show differences, as some comparison questions were answered here in stackoverflow (I think of mako vs jinja2 for example)

Anyway, here's my list, I would really appreciate if people correct me (correct my assumptions on sqlalchemy)

  • Elixir implements the Active Record Pattern and is intended to replace the ActiveMapper SQLAlchemy extension. (out dated : sqlalchemy caught up ?)

  • Relations b/w models are clear(er) : OneToMany, ManyToOne, ManyToMany and OneToOne is clearer than sqla's relation. At a glance, you can see the relations b/w your models.

  • Inhertience is more convinient than in sqlalchemys. It is also more visible since you derive from classes. In sqla, you'll have to tweak with_polymorphisme and polymorphic_on attributes.

  • Inhertience : in elixir, tables, columns, and foreign keys are created automatically, but not in sqlalchemy. (is it 100% true ?)

  • Elixir automatically creates an ID column for all tables (if no other primary_key is declared)

  • Elixir creates FK for relations automatically, sql does not (?)

  • In elixir, most of times, you don't have to specify the backref in you relations. In sqla, you always have to (?)

  • Elixir has a versionning extension (sql haven't ?)

  • Elixir has an associable extension that creates ManyToMany relations and provides nice select_by_XXX methods where XXX is the name of the "associated" class. Sqla dosen't have this kind of extension (?)

  • Inheriting relations is done transparently in Elixir. In sqla, it's not, you have to do this : http://www.sqlalchemy.org/docs/reference/ext/declarative.html#mixing-...)

ychaouche