What you are talking about here is somewhat covered in
http://code.djangoproject.com/ticket/6148
But here it is called db_schema instead.

In mysql "schema" is aliased to database. In postgres, (and probably
oracle) it actually is a different schema within the same database.
I made some work on that ticket up to about rel 1.0 and I am currently
using it for solving the
one database per app use case. I just create a base model in my app
that defines db_schema and let all other app models inherit from that
one.
It's not a perfect solution but works for me.

//Peter

p.s. I would really like someone to continue the development of that
ticket since I have been moved to other projects and don't have the
time for it any more.

On Sep 13, 12:18 am, Simon Willison <[EMAIL PROTECTED]> wrote:
> On Sep 12, 7:45 pm, Brent Hagany <[EMAIL PROTECTED]> wrote:
>
> > As far as I can tell, the argument about being portable is a good one,
> > and if that ends up being the reason this doesn't get in right away,
> > then I can't complain.  However, the part about the single server
> > making this more specialized, and the part about performance are non
> > sequiturs.  The vast majority of web applications run with a single
> > database server; I don't see how that can be called specialized.  And,
> > the reasons for wanting to do cross-database joins (from my POV) have
> > nothing to do with performance, so I don't really understand why it's
> > relevant to this part of the proposal.
>
> To be honest, the main reason I proposed avoiding this problem is it
> sounded like it might be difficult so I was trying to constrain the
> scope a bit, plus I don't know if the ability to do cross-database
> joins exists outside of MySQL. From a quick search, it looks like
> PostgreSQL doesn't support it:http://www.postgresql.org/docs/faqs.FAQ.html
> but Oracle does:http://www.remote-dba.cc/oracle_tips_sql_joins.htm
>
> Anyway, it turns out Django supports cross-database joins in MySQL
> already! It's a bit of a hack, but it works right now, with no
> modifications needed to Django at all.
>
> The only difference between a cross-database join and a regular join
> in MySQL is that in cross-database joins the database name is included
> in each table reference:
>
> SELECT database1.table1.column1, database2.table2.column2
> FROM database1.table1 ...
>
> So, my first attempt was to add the database name to the db_table
> property in class Meta:
>
> class Topic(models.Model):
>     name = models.CharField(max_length = 100)
>     slug = models.SlugField()
>
>     class Meta:
>         db_table = "other_database.review_topic"
>
>     def __unicode__(self):
>         return self.name
>
> That didn't work, because Django adds escaping quotes around each
> table reference. Here's the generated SQL:
>
> SELECT
>    `other_database. review_topic `.`id`,
>    `other_database.review_topic`.`name`,
>    `other_database.review_topic`.`slug`
> FROM `other_database.review_topic`
>
> You can probably guess where this is going: if you include the
> backticks around the . in your db_table setting everything works just
> fine!
>
>     class Meta:
>         db_table = "other_database`.`review_topic"
>
> Regular selects, joins and everything else appear to Just Work out of
> the box. It turns out we don't have to do anything special to enable
> cross-database joins / models in different databases accessible
> through the same logical connection on MySQL, which is pretty cool.
> It's a shame the syntax is hacky though. One slight improvement would
> be to allow the db_table property to optionally include its own table
> quoting and only add backticks if that string didn't have them
> already. That way you could do the following, which is slightly less
> hacky:
>
>     class Meta:
>         db_table = "`other_database`.`review_topic`"
>
> Cheers,
>
> Simon
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django developers" group.
To post to this group, send email to django-developers@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to