Multiple database servers

Visto 2 veces
Saltar al primer mensaje no leído

james

no leída,
2 ene 2007, 16:15:542/1/07
a web.py
Hi,

I'm new to Python, so hopefully this isn't too obvious a question. I'm
just wondering if it's possible to use two database servers with
web.py? I've added basic support for odbtpapi to web.py, and I also
have a mysql database.

Say I want to do something like:

a_results = web.select(...select from odbtapi data source...)
for a in a_results:
b_results = web.select(...select from mysql data source...)
...

tit...@gmail.com

no leída,
3 ene 2007, 16:09:553/1/07
a web.py
Well, what you probably need to do is hack in 2 DB instances to ctx
(the connection object). It gets built for each connection. It
requires editing web.py itself.

You'd want something like:
web.ctx.db.select(blah)
web.ctx.db1.select(blah)

Hope this helps,
Ccraig

james

no leída,
3 ene 2007, 20:18:443/1/07
a web.py
Thanks, I'm glad web.py is so small as it makes learning how things
work that much easier!

Anand

no leída,
3 ene 2007, 20:48:243/1/07
a we...@googlegroups.com

On 04-Jan-07, at 2:39 AM, cr...@yuma.ca wrote:

>
> Well, what you probably need to do is hack in 2 DB instances to ctx
> (the connection object). It gets built for each connection. It
> requires editing web.py itself.
>
> You'd want something like:
> web.ctx.db.select(blah)
> web.ctx.db1.select(blah)

How about this.

import dbhack

db1 = dbhack.db(dbn="mysql", db="", user=...)
db2 = dbhack.db(....)

db1.select(blah)
db2.select(blah)


here is the code. (caution: i havent tested this).

dbhack.py

Anand

no leída,
3 ene 2007, 21:42:593/1/07
a we...@googlegroups.com

there were some bugs and mistakes. fixed now.
i have tested this with 2 databases one mysql and one postgres. it
works fine.

dbhack.py

james

no leída,
4 ene 2007, 11:32:104/1/07
a web.py
Sweet, thanks! Wish I could hack up code like that!

james

no leída,
4 ene 2007, 13:29:414/1/07
a web.py
Anand wrote:
> there were some bugs and mistakes. fixed now.
> i have tested this with 2 databases one mysql and one postgres. it
> works fine.

Are you considering adding something like this to web.py?

Thanks again.

Responder a todos
Responder al autor
Reenviar
0 mensajes nuevos