connection to the database using Pecan

70 views
Skip to first unread message

john

unread,
Dec 14, 2010, 11:08:02 AM12/14/10
to Pecan Developers List

I have a question about how it should work the connection to the
database using Pecan, when you work in Django and TG2 that is
transparent.

Pecan working with what is the right approach.

Thank you very much.

Alfredo Deza

unread,
Dec 15, 2010, 10:19:09 AM12/15/10
to peca...@googlegroups.com
Hi John,

Right now we are trying to make it really easy to hook a database into
Pecan, but the
bad news is that we are still in the process of implementing it.

There is no current definite way of doing this at the moment.

For some projects I have been using Elixir and SqlAlchemy, and the database
binding functions are in the model. So when the application runs via start.py
I import those binding functions and call them there with whatever
engine I want.

For example a start.py that connects to mysql would have these lines:

from my_app.model import my_binding_func

my_binding_func('mysql://127.0.0.1/my_database')

Again, this might not be straightforward and could be changing a bit later on.

john

unread,
Dec 15, 2010, 10:45:06 AM12/15/10
to Pecan Developers List
Hi Alfredo,

using:
my_app.model import from my_binding_func
my_binding_func ('mysql: / / 127.0.0.1/my_database')

I can use it from the file root.py or should be provided from the file
start.py?

Thank you very much

Alfredo Deza

unread,
Dec 15, 2010, 10:51:19 AM12/15/10
to peca...@googlegroups.com

Ideally, you would want to bind to a database connection before the
application gets to your
root controller.

This might be a question of preference, but in my case, anything
related to the database
I usually add it to the model module of my application.

The reason that goes into start.py is because start.py is in charge of
starting your application.

Now your situation/environment might be different and you *could* do
it in the root controller, like
this example for App Engine:
https://github.com/cleverdevil/pecan/blob/master/docs/0.0.1/source/app_engine.rst

It all depends.

For now there are no strict ways of doing it.

Reply all
Reply to author
Forward
0 new messages