or should be a little better
q=q1.union_all(q2,q3)
--
Mike Conley
On Thu, Aug 27, 2009 at 12:14 AM, Mike Conley wrote:
> Did you try something like this?
>
> q1=session.query(P1.userid, P1.extra, P1.title, P1.body)
> q2=session.query(P2.userid, "'X'", P2.ti
Did you try something like this?
q1=session.query(P1.userid, P1.extra, P1.title, P1.body)
q2=session.query(P2.userid, "'X'", P2.title, P2.body)
q3=session.query(P3.userid, "'X'", P3.title, P3.body)
q=q1.union_all(q2).union_all(q3)
--
Mike Conley
Add cascade='delete-orphan' to the relation definition for children.
cascade='all,delete-orphan' is also a fairly common option.
See the documentation for other options in cascade.
http://www.sqlalchemy.org/docs/05/reference/orm/mapping.html#sqlalchemy.orm.relation
--
M
x...94f0 COMMIT
Implied rule is: when inserting many records, provide same value list for
each row.
--
Mike Conley
On Wed, Aug 26, 2009 at 5:36 AM, menuge wrote:
>
> Hi all,
>
> I d like to insert a list of dictionary in a simple MySQL table but, I
> have a problem,
You might want to start here
http://www.sqlalchemy.org/trac/wiki/UsageRecipes/LogVersions
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegrou
>
> but I thought somehow that meta.reflect() would pick up on the fk
> constraints ...
>
Class MetaData is part of the core api that ORM builds on top of, and
meta.reflect() does pick up the fk constraints from the database.
Think of it this way, MetaData, whether reflected or declared in its
en
u read the documentation for Query.delete() to understand the
impact of the 'synchronize_session' keyword
--
Mike Conley
On Wed, Aug 19, 2009 at 5:54 PM, wrote:
>
> Hello,
>
> I have several objects from a relation that I'd like to delete. To me,
> this would be a natural
skills related to a profile, and each skill
related to a user.
--
Mike Conley
On Sat, Aug 15, 2009 at 5:19 PM, Sid wrote:
>
> Hi,
>
> I'm new to SQLAlchemy and ORMs in general so I have a couple of
> questions.
>
> Basically I have a class called Profile that conta
kt,ut.c.uid==ukt.c.uid)).\
filter(case([(ut.c.uid=='mike','M'),
(ut.c.uid=='sue','F')],
else_='X') == 'M')
--
Mike Conley
--~--~-~--~~~---~--~~
You received this message
I can do this by adding a method to People
def marries(self, other):
self.spouse = other
other.spouse = self
and then saying
sue.marries(sam)
to record the two way relationship
Question:
Adding the method is very simple and clear. For my education, is there
(a AND b) OR c
are equivalent.
When a or b is a complex condition that also has OR then parenthesis are
probably needed.
In this case, it appears that the condition is an OR of two conditions that
consist entirely of AND conditions. If that is the case then parenthesis are
not required.
eed to use the join(), construct a selectable that explicitly names
the columns you want to select.
--
Mike Conley
On Tue, Aug 4, 2009 at 8:44 AM, Nathan Harmston <
iwanttobeabad...@googlemail.com> wrote:
>
> Hi everyone, I am trying to get access to attributes which are hidden b
> What are the advantages of using declarative way of setting table
> definitions? vs
> addressbook_table = sqlalchemy.Table("Addressbook", metadata,
>sqlalchemy.Column('Address_Sid', sqlalchemy.Integer, primary_key=True),
>sqlalchemy.Column('FirstName', sqlalchemy.Unicode(40),nullable=Fals
2 lines before metadata.create_all(), then you don't
need to separately create the index.
--
Mike Conley
On Wed, Jul 29, 2009 at 5:34 PM, Lukasz Szybalski wrote:
>
> Hello,
> How can I do
> Index('myindex', xyz.c.type, xyz.c.name, unique=True)
>
> in
different value
session.add(newobj)
session.commit()
This seems to work for the simple cases I ran so far, just wondering if
there are any hidden problems or simplifications.
--
Mike Conley
--~--~-~--~~~---~--~~
You received this message because you are subscribed to
ord==O.onum)))
If needed this can probably be optimized for efficiency
--
Mike Conley
On Fri, Jul 24, 2009 at 4:32 AM, Noufal wrote:
>
> Hello everyone,
> I've been using sqlalchemy with elixir for a legacy project for a
> while now and recently needed to write some more
= query.options(contains_eager(Slide.bullets))
The problem with this is that I lost much of the relational simplicity. I
had to add join and ordering
clauses to my query that were already specified in the relation definition.
Am I missing something? Maybe another way of specifying order_by in th
like this.
boston_addresses = relation('Address',
primaryjoin = "and_(User.user_id==Address.user_id,Address.city=='Boston')"
)
--
Mike Conley
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Gro
uct also?
http://www.sqlalchemy.org/docs/05/mappers.html#specifying-alternate-join-conditions-to-relation
I can reproduce GHZ's error with declarative, but also can run the
documentation example using mappers.
Can we express the alternate joins with declarative?
--
Mike Conley
On Wed, Jul 15, 2009
straint is right, then it looks like you are getting correct
behavior.
Posting your table definitions also would help.
--
Mike Conley
On Tue, Jul 7, 2009 at 12:12 PM, Nathan Harmston <
iwanttobeabad...@googlemail.com> wrote:
>
> Hi,
> Currently I have a mapper like this:
>
uot; would work, but this would not: "u.room.name =
'kitchen'"
I don't think so, someone else would have to give a definitive answer
--
Mike Conley
On Wed, Jun 17, 2009 at 10:14 AM, allen.fowler wrote:
>
>
> > 3) Can this relation's objects be
now room is a pointer to a room object identified in the database by room_id
and
u.room = r
will work OK
--
Mike Conley
On Wed, Jun 17, 2009 at 2:44 AM, AF wrote:
>
> I'm probably just missing something... here is my code:
>
> engine = create_engine('sqlit
Since the id will only be available after a database insert; some flavor of
session.flush() is needed. I like to keep object constructors limited to
actual object construction; so putting it in get_person() after
instantiating the person seems best approach.
--
Mike Conley
On Mon, Jun 15
and return
it; only a pointer to the list is being returned. The list is not copied to
another memory location unless the caller does that themselves, and they
should be working with and understand the same memory constraints you are
dealing with.
--
Mike Conley
On Mon, Jun 8, 2009 at 11:34
g'),)
insdata = [dict(zip(cols,datum)) for datum in data]
conn.execute(dept.insert(), insdata)
## or in a single statement ##
conn.execute(dept.insert(), [
dict(zip(('deptid','deptname',), datum)) for datum in (
(31,'Sales'),
(33,'Enginee
where you expect it to.
The revised code says "append a Blog to the already existing list in
user.blogs". This causes SQLAlchemy to issue an insert adding a new row to
the blog table, and no updates to prior existing blog records.
--
Mike Conley
On Sat, Jun 6, 2009 at 11:56
Looks like the culprit is:
user.blogs = [Blog(title=input['blog_title']
this replaces your user.blogs relation with a single entry list containing
the last Blog
try this to add a Blog to the relation list
user.blogs.append(Blog(title=input['blog_title'))
--
Mike Conley
could be something in SQL generation.
--
Mike Conley
On Fri, Jun 5, 2009 at 6:15 AM, outlier wrote:
>
> I'm not even sure where to start studying this problem but here goes:
> I have an application that uses a MySQL db wrapped with SA and it
> works fine. While writing n
This looks like an association proxy. Have you tried that?
http://www.sqlalchemy.org/docs/05/reference/ext/associationproxy.html
--
Mike Conley
On Mon, Jun 1, 2009 at 11:46 PM, George Sakkis wrote:
>
> I can't for the life of me figure out how to specify a relation
> spanni
I need to compare database schemas (tables, column names, types,
constraints, etc.). Is there anything out there that uses SQLAlchemy
metadata to compare database schemas? or should I start working on one?
--
Mike Conley
--~--~-~--~~~---~--~~
You received this
Harish said it was an embedded system, probably all resources are pretty
severely restricted.
--
Mike Conley
On Fri, May 29, 2009 at 9:44 AM, Randy Syring wrote:
>
> Mike,
>
> Well...I am not sure. I thought SQLite held transaction details in
> a .journal file and not in mem
igger.
--
Mike Conley
On Fri, May 29, 2009 at 8:47 AM, Randy Syring wrote:
>
> Another solution is to use triggers in SQLite to enforce FK
> relationships.
>
> http://www.sqlite.org/cvstrac/wiki?p=ForeignKeyTriggers
> http://code.google.com/p/sqlitefktg4sa/
>
> On May 29
session.commit()
if count > 0:
session.commit() # this gets the last group of deletes
The disadvantage of this approach is that you lose the ability to rollback
the entire delete process, and now must handle that problem with application
design.
--
Mike Conley
On Fri, May 29, 2009 at 4:08
ush()
session.commit()
--
Mike Conley
On Wed, May 27, 2009 at 9:13 AM, Gregg Lind wrote:
>
> I believe by "map function", Timothy may be implying that you should
> use any of the python idioms for converting iterables of tuples to a
> straight tuple. The one I like best
>
&
ptimizing this
delete process.
--
Mike Conley
On Wed, May 27, 2009 at 7:25 AM, Harish Vishwanath wrote:
> Thanks!
>
> Could you elaborate on how you use the map function? I couldn't find it
> myself in the docs.
>
> Regards,
> Harish
>
>
>
> On Wed, May
On Tue, May 26, 2009 at 5:11 AM, Marcin Krol wrote:
>
>
> What I do not get is why after this query takes place, SQLA runs a lot
> those small queries - I included all (most?) the necessary columns in
> the big initial query, so Host data should be filled in by SQLA eager
> loading (which is defa
I found that you need to call
eng.dispose()
to disconnect from the database before deleting the file.
Not sure about what is happening under the covers at that point, but it
seems to work.
--
Mike Conley
On Fri, May 15, 2009 at 1:35 PM, RusPython wrote:
>
> Hi guys,
>
> I ha
like the query.join() documentation describes. The
problem is how to express a single join when it depends on 2 foreign keys to
2 different targets.
Am I missing something, or do I always have to use a SQL expression in this
case?
--
Mike Conley
On Thu, May 7, 2009 at 1:34 PM, Michael
Ahh yes, I use autoflush almost exclusively and forget that you can separate
the flush() and commit().
--
Mike Conley
On Tue, May 5, 2009 at 6:31 PM, Michael Bayer wrote:
>
> Mike Conley wrote:
> > Does the idea of last_inserted_ids exist for ORM?
> >
> > I do
>
attributes, but I can't figure
out the syntax when 2 foreign keys are present.
http://www.sqlalchemy.org/docs/05/reference/orm/query.html?highlight=#sqlalchemy.orm.query.Query.join
A full example can be found at http://pastebin.com/m120d486a
--
Mike Conley
--~--~-~--~~~
:
result = conn.execute(table.insert(etc..
I can directly access the inserted id as
result.last_inserted_ids()
without another database call.
Can I get the id directly when using the ORM?
--
Mike Conley
--~--~-~--~~~---~--~~
You received this
Look at the primary_key attribute of the table instance.
uu = Table('u',meta,
Column('id',Integer,primary_key=True),
Column('data',Integer))
print uu.primary_key.columns
['u.id']
Mike
On Tue, Apr 28, 2009 at 7:53 PM, Paul Rigor (gmail) wrote:
> Hi gang,
> I've recently started
)
class CST_LEVEL(Base):
etc...
or (2) access the internal metadata directly
Base = declarative_base()
class CST_LEVEL(Base):
etc...
Base.metadata.create_all()
--
Mike Conley
On Sun, Apr 26, 2009 at 2:07 AM, Paul Hemans wrote:
>
> Hi Newbie here,
> If, using the declarative
problem.
--
Mike Conley
On Sun, Apr 19, 2009 at 2:45 PM, Alessandro Dentella wrote:
>
> Hi,
>
> i'm playing with outerjoin defined in the mapper. I'm getting results
> different from what I expected, so that I would like to understand which is
> the underline logic.
&g
wiki. Maybe I'll look at that as an exercise.
--
Mike Conley
On Mon, Apr 13, 2009 at 1:27 PM, Michael Bayer wrote:
>
> Its possible that SQLite doesn't respect the "scale" argument. I'd look
> at the full SQL generated to ensure its what you'd expect, then
This will teach me to run a test it first, I don't think this is exactly
right, but it should be close.
--
Mike Conley
On Fri, Apr 10, 2009 at 9:43 AM, Mike Conley wrote:
> Try this, has one nested query
> sub = session.query(C.id.label('c_id'),
>
in q:
print 'D-id:%s C-id:%s C-max:%s'%(row.id, row.c_id, row.c_maxvalue)
--
Mike Conley
On Fri, Apr 10, 2009 at 8:55 AM, Joril wrote:
>
> On 10 Apr, 12:52, a...@svilendobrev.com wrote:
> > that's what i have in bitemporal queries.
> > u need a groupby and
roperly encapsulates inserting and removing the entry in a single
operation. I can imagine that there would be many variations on business
rules for moving an item that would be difficult to encapsulate in a common
operation within SA.
--
Mike Conley
On Mon, Apr 6, 2009 at 2:10 AM, jean-ph
conn = eng.connect()
conn.execute(users.insert(), [{'name':'joe', '10:00':'1200'}])
--
Mike Conley
On Fri, Apr 3, 2009 at 12:07 AM, Tanmoy wrote:
> Tried that...dosent work
>
>
>
>
> Tom
>
> >
>
-
tant using the same idea in more complex
associations.
--
Mike Conley
On Fri, Mar 27, 2009 at 11:51 AM, David Gardner
wrote:
> Try this:
>
> mapper(Parent, parent_table, properties = {
> 'boys':relation(Child, backref='parent',
> pri
cify a relation that gives a list of the boys
Parent.boys = relation(Child, ??)
I suspect it is something pretty straight forward, but can't figure it out
--
Mike Conley
--~--~-~--~~~---~--~~
You received this message because you are subscr
Have you tried adding echo=True to the engine to observe the actual SQL?
--
Mike Conley
On Fri, Mar 20, 2009 at 8:23 PM, davidlmontgomery <
davidlmontgom...@gmail.com> wrote:
>
> I'm using sqlalchemy with sql server express. Client-side
> is also Windows, running pyth
I believe #1 will iterate on the cursor retrieving one object from cursor
on each iteration, while #2 retrieves all objects then processes the
entire result set in Python.
Try changing #1 to use
for o in session.query(Object).all()
to retrieve all objects before doing the iteration, same as
On Wed, Mar 18, 2009 at 11:00 AM, Michael Bayer wrote:
>
> Sanjay wrote:
> >
> > Hi,
> >
> > I want to write something like
> >
> > query.filter(BizObj.col.in_("SELECT col FROM some_table")).
> >
> > Could not find out how to do it. The code on neither the above nor the
> > below worked.
> >
> > q
If you use
rows = cursor.fetchall()
you have already executed the query and the result is a list of RowProxy's
returned by the query. Count then is simply
count = len(rows)
Otherwise, the count(*) approach is correct.
--
Mike Conley
On Fri, Mar 13, 2009 at 4:42 PM, jeff
query has both bulk delete and update methods
http://www.sqlalchemy.org/docs/05/reference/orm/query.html#the-query-object
count = session.query(Person).filter(... whatever criteria
...).delete(synchronize_session=False)
On Fri, Feb 20, 2009 at 5:22 AM, Ids wrote:
>
> Hello,
>
> I'm using the
101 - 156 of 156 matches
Mail list logo