how to query

17 vues
Accéder directement au premier message non lu

Jarrett Chisholm

non lue,
26 juin 2012, 14:32:4126/06/2012
à sqle...@googlegroups.com
hey all,

I'm pretty new to elixir (and python).  I'm trying to figure out how to query my new table.

I've got a model that looks like this (it's in it's own folder called 'model', the file is called 'demographic.py')
from elixir import *

metadata.bind = 'mysql://root:THEPASSWORD@localhost/test'
metadata.bind.echo = True

class Demographic(Entity):
    name = Field(Unicode(30))
    yob = Field(Integer)
    description = Field(UnicodeText)
   
    def __repr__(self):
        if (self.yob is None):
            self.yob = 0000
        return '<Demographic "%s" (%d)>' % (self.name, self.yob)

I've got another file that imports the demographic and then tries to query and get all of the entries:

from model import demographic

...

def get_demographic():
    patients = demographic.Demographic.query.all()
    print patients

However, I'm getting the following error:

AttributeError: type object 'Demographic' has no attribute 'query'

When I add 'demographic.setup_all()' to the start of the get_demographic() function, it works.  Do I need to call 'demographic.setup_all()' every time I want to query?

Thanks all!

Cheers

-- 
Jarrett Chisholm

Erik Janssens

non lue,
27 juin 2012, 03:07:3527/06/2012
à sqle...@googlegroups.com
you forgot to call :

setup_all( True )

between definition of the model and the query
> --
> You received this message because you are subscribed to the Google
> Groups "SQLElixir" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/sqlelixir/-/OFRg1oADNzEJ.
> To post to this group, send email to sqle...@googlegroups.com.
> To unsubscribe from this group, send email to sqlelixir
> +unsub...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/sqlelixir?hl=en.


Jarrett Chisholm

non lue,
27 juin 2012, 11:00:5627/06/2012
à sqle...@googlegroups.com
Ahhh I see. I now call 'setup_all()' after my import call and it seems
to do the trick.

Does sending 'True' as a parameter do anything special that I should be
doing?

Jarrett Chisholm
Prylynx Corporation
IT should be this simple

j.chi...@prylynx.com
www.prylynx.com
T: (519) 895-0600

Jarrett Chisholm

non lue,
27 juin 2012, 11:08:3927/06/2012
à sqle...@googlegroups.com
also, thanks for the reply! :)

Jarrett Chisholm
Prylynx Corporation
IT should be this simple

j.chi...@prylynx.com
www.prylynx.com
T: (519) 895-0600


On 27/06/12 03:07 AM, Erik Janssens wrote:

Erik Janssens

non lue,
27 juin 2012, 11:17:1327/06/2012
à sqle...@googlegroups.com
it creates the tables in the database

on a side note : if you're starting a new project, you might want
to consider using Declarative instead of Elixir, as Elixir is rather
unmaintained.

I'm building a set of Declarative classes that mimic Elixir behavior
to port over my projects, but if you're starting now ...

Jarrett Chisholm

non lue,
27 juin 2012, 15:08:0627/06/2012
à sqle...@googlegroups.com
ahh ok, using declarative might make it easier in terms of getting
support too :) I'm assuming you're talking about the SQLAlchemy
declarative plugin?

Also, are your Declarative classes part of an open source project? :)

thanks for getting back to me Erik!

cheers

Jarrett Chisholm
Prylynx Corporation
IT should be this simple

j.chi...@prylynx.com
www.prylynx.com
T: (519) 895-0600


Erik Janssens

non lue,
27 juin 2012, 15:42:3327/06/2012
à sqle...@googlegroups.com
On Wed, 2012-06-27 at 15:08 -0400, Jarrett Chisholm wrote:
> ahh ok, using declarative might make it easier in terms of getting
> support too :) I'm assuming you're talking about the SQLAlchemy
> declarative plugin?

indeed

>
> Also, are your Declarative classes part of an open source project? :)

yes, they are part of Camelot

http://www.python-camelot.com/

The Elixir mimicing classes are in :

https://www.gitorious.org/camelot/camelot/blobs/master/camelot/core/orm.py

The 'Entity' class is ready for production use, but the relationship
classes are still work in progress.

>
> thanks for getting back to me Erik!
>

sure, that's what this mailing list is for
Répondre à tous
Répondre à l'auteur
Transférer
0 nouveau message