Re: [sqlalchemy] Serialization / De-serialization for SQLAlchemy Declarative ORM

2018-07-11 Thread Jonathan Vanasco
this looks great, and omfg the docs! -- SQLAlchemy - The Python SQL Toolkit and Object Relational Mapper http://www.sqlalchemy.org/ To post example code, please provide an MCVE: Minimal, Complete, and Verifiable Example. See http://stackoverflow.com/help/mcve for a full description. ---

Re: [sqlalchemy] Serialization / De-serialization for SQLAlchemy Declarative ORM

2018-07-11 Thread chris . modzelewski
Hi Mike, Thanks - I really appreciate it! And thanks again for all of the effort you've put into SQLAlchemy! It is a "must have" in most of the Python projects I work on these days, and I regularly sing its praises to my clients. All the best, Chris On Wednesday, July 11, 2018 at 6:26:55 PM

Re: [sqlalchemy] Serialization / De-serialization for SQLAlchemy Declarative ORM

2018-07-11 Thread Mike Bayer
Hi Chris - congratulations! this looks extremely well documented and it's clear you put an enormous amount of effort into it!I will definitely point users your way when they ask for this kind of thing. Looks great. - mike On Wed, Jul 11, 2018 at 4:00 PM, wrote: > Hi Folks, > > First

[sqlalchemy] Serialization / De-serialization for SQLAlchemy Declarative ORM

2018-07-11 Thread chris . modzelewski
Hi Folks, First off, I'd just like to thank everyone here for all of the awesome work you've been doing on SQLAlchemy. I've been using the library for years, and it is a truly fantastic piece of code that I rely on literally every day. Thank you for all the work that you've done and are doing

Re: [sqlalchemy] Declarative API without state management

2017-11-09 Thread Max Rothman
Thanks for the response! > Is this sort of thing possible? Can the declarative API be used without >> binding model classes to a session? > > > The declarative API and the Mapper objects it creates have no > dependency on a Session being present at all. So you're free to > build a new kind

Re: [sqlalchemy] Declarative API without state management

2017-11-02 Thread Mike Bayer
On Thu, Nov 2, 2017 at 3:09 PM, Max Rothman wrote: > I was poking around Elixir's Ecto, and I was curious whether it was possible > to apply their strict separation between data and operations to SQLAlchemy. > One could imagine an API where session.query fetches mutable,

[sqlalchemy] Declarative API without state management

2017-11-02 Thread Max Rothman
I was poking around Elixir's Ecto , and I was curious whether it was possible to apply their strict separation between data and operations to SQLAlchemy. One could imagine an API where session.query fetches mutable, data-only versions of models, and models are

Re: [sqlalchemy] declarative Association table w/ foreign_keys in relationship() still raises "multiple foreign key paths linking the tables"

2016-12-09 Thread bkc
That's a good suggestion, thanks. -- SQLAlchemy - The Python SQL Toolkit and Object Relational Mapper http://www.sqlalchemy.org/ To post example code, please provide an MCVE: Minimal, Complete, and Verifiable Example. See http://stackoverflow.com/help/mcve for a full description. --- You

Re: [sqlalchemy] declarative Association table w/ foreign_keys in relationship() still raises "multiple foreign key paths linking the tables"

2016-12-09 Thread mike bayer
leader/follower is often used in this case. On 12/09/2016 10:33 AM, b...@sfi.ca wrote: Thanks Mike for the quick reply. I have changed the code so it uses backref on one side. The models now get created w/o error. I haven't actually tested using the relationship but I'm sure it's fine now.

Re: [sqlalchemy] declarative Association table w/ foreign_keys in relationship() still raises "multiple foreign key paths linking the tables"

2016-12-09 Thread bkc
Thanks Mike for the quick reply. I have changed the code so it uses backref on one side. The models now get created w/o error. I haven't actually tested using the relationship but I'm sure it's fine now. For anyone else with this problem, here's the 'fixed' code. I didn't change the

[sqlalchemy] declarative Association table w/ foreign_keys in relationship() still raises "multiple foreign key paths linking the tables"

2016-12-08 Thread bkc
Hi, Running SQLAlchemy==1.1.4 I'm getting this AmbiguousForeignKeysError: Could not determine join condition between > parent/child tables on relationship Artifact.slaves - there are multiple > foreign key paths linking the tables. Specify the 'foreign_keys' argument, > providing a list of

[sqlalchemy] Re: Serializing sqlalchemy declarative instances with yaml

2016-09-20 Thread Sergii Nechuiviter
This is Yaml bug: http://pyyaml.org/ticket/245 -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy+unsubscr...@googlegroups.com. To post to this group,

Re: [sqlalchemy] Declarative: defining relationship and column in one line

2015-05-31 Thread Mike Bayer
On 5/31/15 6:11 AM, Fayaz Yusuf Khan wrote: Hi, On Tuesday, May 19, 2015 at 7:41:45 PM UTC+5:30, Michael Bayer wrote: http://techspot.zzzeek.org/2011/05/17/magic-a-new-orm/ http://techspot.zzzeek.org/2011/05/17/magic-a-new-orm/ I had tried this one before but it looked like those

Re: [sqlalchemy] Declarative: defining relationship and column in one line

2015-05-31 Thread Fayaz Yusuf Khan
Hi, On Tuesday, May 19, 2015 at 7:41:45 PM UTC+5:30, Michael Bayer wrote: http://techspot.zzzeek.org/2011/05/17/magic-a-new-orm/ I had tried this one before but it looked like those columns were never added to the underlying table. -- You received this message because you are subscribed

[sqlalchemy] Declarative: defining relationship and column in one line

2015-05-19 Thread Paul Johnston
Hi, Sorry if this is a FAQ, but is it possible to define a relationship and its column all at once. e.g. instead of: type_id = db.Column(db.Integer, db.ForeignKey('linktype.id')) type = db.relationship('LinkType') Something like: type = db.relationship('LinkType',

Re: [sqlalchemy] Declarative: defining relationship and column in one line

2015-05-19 Thread Mike Bayer
On 5/19/15 6:54 AM, Paul Johnston wrote: Hi, Sorry if this is a FAQ, but is it possible to define a relationship and its column all at once. e.g. instead of: type_id = db.Column(db.Integer, db.ForeignKey('linktype.id')) type = db.relationship('LinkType') Something like: type

Re: [sqlalchemy] Declarative setup failing on upgrade to 1.0.1

2015-04-25 Thread Bill Schindler
Still getting the same error with 1.0.2. It's using a custom base class passed to declarative.declarative_base(). The class is pretty simple -- mostly just a declared_attr to set the __tablename__ and a custom __repr__. I'll see if I can pare it down to a simple test case. -- Bill -- You

Re: [sqlalchemy] Declarative setup failing on upgrade to 1.0.1

2015-04-25 Thread Bill Schindler
This may have been an instance of working by accident. In setting up declarative_base, we're passing in a mapper function. Our mapper function wasn't returning the result of the SA mapper(). It didn't cause any (explicit) errors through 0.9.8, but I have a feeling that was just luck. On

[sqlalchemy] Declarative setup failing on upgrade to 1.0.1

2015-04-24 Thread Bill Schindler
I'm trying to upgrade from SA 0.9.8 to 1.0.1 and getting a traceback. I'm not sure what's going on here, but the declarative setup is obviously not happy with something. (On 0.9.8, everything runs fine, so I've obviously run afoul of something new/different/fixed.) File

Re: [sqlalchemy] Declarative setup failing on upgrade to 1.0.1

2015-04-24 Thread Mike Bayer
give 1.0.2 a try since we adjusted some things regarding __declare_first__ and __declare_last__. Further than that it depends a lot on what your basic Base setup looks like, mixins in use, extensions like AbstractConcreteBase, stuff like that. Any details you can share would help. On

Re: [sqlalchemy] Serializing sqlalchemy declarative instances with yaml

2014-10-24 Thread Jonathan Vanasco
Usually for this sort of stuff, I serialize the object's data into a JSON dict ( object columns to JSON dict, object relations to a dict, list of dicts, or reference to another object). ( Custom dump/load is needed to handle Timestamp, Floats, etc). You might be able to iterate over the data

Re: [sqlalchemy] Serializing sqlalchemy declarative instances with yaml

2014-10-24 Thread Peter Waller
Well I was hoping to just use yaml since yaml understands when two objects refer to the same underlying object. That means you don't have to write any logic to de-duplicate objects through relationships, etc. Since json doesn't have the notion of referencing, that doesn't seem straightforward

Re: [sqlalchemy] Serializing sqlalchemy declarative instances with yaml

2014-10-24 Thread Jonathan Vanasco
On Friday, October 24, 2014 10:39:43 AM UTC-4, Peter Waller wrote: I was also hoping to just use yaml to avoid writing custom dumping code, since it seems in general like a useful capability. So I may yet try and find the underlying bug and fix it. It might not be a bug, and the effect of

Re: [sqlalchemy] Serializing sqlalchemy declarative instances with yaml

2014-10-24 Thread Peter Waller
The oddity is that calling `__reduce_ex__` on the instance is fine, but on the class it is not. When serialising a declarative class it finds itself serialising the class type, which fails. This actually fails for the `object`, too (see below). So I think what's happening is that serialisation

Re: [sqlalchemy] Serializing sqlalchemy declarative instances with yaml

2014-10-23 Thread Michael Bayer
On Oct 23, 2014, at 7:42 AM, Peter Waller pe...@scraperwiki.com wrote: We would like to freeze the results of a query to my database in a yaml file, so that we can use the results in an app which isn't connected to the database. It makes sense here to reuse the model classes. Here's an

[sqlalchemy] declarative polymorphic inheritance abstraction problem

2014-02-10 Thread Chris Withers
Hi All, I'm trying to be efficient with my code, but it seems to tripping SQLAlchemy up. So, basically I want to have a schema with two tables, content and project, to represent two three types of object: - article has a set of fields as found in the 'content' table - project has fields

Re: [sqlalchemy] declarative polymorphic inheritance abstraction problem

2014-02-10 Thread Michael Bayer
On Feb 10, 2014, at 2:36 PM, Chris Withers ch...@simplistix.co.uk wrote: Hi All, I'm trying to be efficient with my code, but it seems to tripping SQLAlchemy up. So, basically I want to have a schema with two tables, content and project, to represent two three types of object: if you

[sqlalchemy] declarative, reflection, and secondary tables.

2013-11-16 Thread Jon Nelson
I've been experiencing a weirdness. Using SQLAlchemy 0.8.3 and PostgreSQL with declarative (and deferred reflection), if I don't manually force a reflection *before* I call prepare then - when I use certain objects - I get an error which indicates that SQLAlchemy did not reflect secondary tables.

Re: [sqlalchemy] declarative, reflection, and secondary tables.

2013-11-16 Thread Michael Bayer
On Nov 16, 2013, at 4:08 PM, Jon Nelson jnel...@jamponi.net wrote: I've been experiencing a weirdness. Using SQLAlchemy 0.8.3 and PostgreSQL with declarative (and deferred reflection), if I don't manually force a reflection *before* I call prepare then - when I use certain objects - I get

Re: [sqlalchemy] How to define metaclass for a class that extends from sqlalchemy declarative base ?

2013-08-26 Thread Praveen
The problem with using Mixins is that you need to know the definition of columns already for creating the mixin class. What I am trying to do is more like get the definition dynamically on the fly.Take a look at this: def get_properties(tablename, map): table_inspector =

Re: [sqlalchemy] How to define metaclass for a class that extends from sqlalchemy declarative base ?

2013-08-26 Thread Praveen
Sorry, it should've been: class Enum_Sample(Base): Typo. On Mon, Aug 26, 2013 at 4:35 PM, Praveen praveen.venk...@gmail.com wrote: The problem with using Mixins is that you need to know the definition of columns already for creating the mixin class. What I am trying to do is more like get

Re: [sqlalchemy] How to define metaclass for a class that extends from sqlalchemy declarative base ?

2013-08-26 Thread Michael Bayer
On Aug 26, 2013, at 4:35 PM, Praveen praveen.venk...@gmail.com wrote: The problem with using Mixins is that you need to know the definition of columns already for creating the mixin class. What I am trying to do is more like get the definition dynamically on the fly.Take a look at this:

Re: [sqlalchemy] How to define metaclass for a class that extends from sqlalchemy declarative base ?

2013-08-26 Thread Michael Bayer
On Aug 26, 2013, at 5:16 PM, Michael Bayer mike...@zzzcomputing.com wrote: On Aug 26, 2013, at 4:35 PM, Praveen praveen.venk...@gmail.com wrote: The problem with using Mixins is that you need to know the definition of columns already for creating the mixin class. What I am trying to do

Re: [sqlalchemy] How to define metaclass for a class that extends from sqlalchemy declarative base ?

2013-08-26 Thread Michael Bayer
OK here we are, had to switch approaches due to a bug with the column reflect event, to use the aforementioned __mapper_cls__ (had the name wrong), so I think you'll see this is a pretty open-ended way to control how something maps as you're given total access to mapper() here: from sqlalchemy

Re: [sqlalchemy] How to define metaclass for a class that extends from sqlalchemy declarative base ?

2013-08-26 Thread Praveen
Does this work in sqlalchemy 0.6.1 ? On Mon, Aug 26, 2013 at 5:36 PM, Michael Bayer mike...@zzzcomputing.comwrote: OK here we are, had to switch approaches due to a bug with the column reflect event, to use the aforementioned __mapper_cls__ (had the name wrong), so I think you'll see this is

Re: [sqlalchemy] How to define metaclass for a class that extends from sqlalchemy declarative base ?

2013-08-26 Thread Praveen
I am getting ImportError for the following: from sqlalchemy.ext.declarative import DeferredReflection from sqlalchemy import event I use sqlalchemy 0.6.1. Is there any way I can make it work in 0.6.1 ? On Mon, Aug 26, 2013 at 5:38 PM, Praveen praveen.venk...@gmail.com wrote: Does this work

Re: [sqlalchemy] How to define metaclass for a class that extends from sqlalchemy declarative base ?

2013-08-26 Thread Michael Bayer
you'd need to hand-roll the deferred reflection part, there's an example in 0.7 called declarative_reflection but it might require features that aren't in 0.6. I'd not be looking to add any kind of slick/magic systems to an 0.6 app, 0.6 is very early in the curve for declarative techniques.

Re: [sqlalchemy] How to define metaclass for a class that extends from sqlalchemy declarative base ?

2013-08-26 Thread Praveen
Could you please point me to the link where I can find the example ? On Mon, Aug 26, 2013 at 5:41 PM, Michael Bayer mike...@zzzcomputing.comwrote: you'd need to hand-roll the deferred reflection part, there's an example in 0.7 called declarative_reflection but it might require features that

Re: [sqlalchemy] How to define metaclass for a class that extends from sqlalchemy declarative base ?

2013-08-26 Thread Praveen
nvm... i found it. On Mon, Aug 26, 2013 at 5:46 PM, Praveen praveen.venk...@gmail.com wrote: Could you please point me to the link where I can find the example ? On Mon, Aug 26, 2013 at 5:41 PM, Michael Bayer mike...@zzzcomputing.comwrote: you'd need to hand-roll the deferred reflection

Re: [sqlalchemy] How to define metaclass for a class that extends from sqlalchemy declarative base ?

2013-08-26 Thread Praveen
I tried your example in sqlalchemy 0.6 by manually plugging in api.py library (attached) that I got from herehttps://bitbucket.org/miracle2k/sqlalchemy/src/2d28ed97d3221a133b4b297a229deb294088affe/lib/sqlalchemy/ext/declarative/api.py?at=default . I get this error: File path\to\sample_orm.py,

Re: [sqlalchemy] How to define metaclass for a class that extends from sqlalchemy declarative base ?

2013-07-03 Thread Michael Bayer
your metaclass must derive from the DeclarativeMeta class. Also, I disagree that you need this metaclass, what you're trying to do is very easy using mixins, which are supported in version 0.6: http://docs.sqlalchemy.org/en/rel_0_6/orm/extensions/declarative.html#mixing-in-columns On Jul

[sqlalchemy] How to define metaclass for a class that extends from sqlalchemy declarative base ?

2013-07-02 Thread Ven Karri
I use: Python 2.6 and sqlalchemy 0.6.1 This is what I am trying to do: from sqlalchemy.types import ( Integer, String, Boolean ) from sqlalchemy.ext.declarative import declarative_base Base = declarative_base() class SampleMeta(type): def __new__(cls, name, bases,

[sqlalchemy] Declarative Sequences

2013-06-26 Thread Mat Mathews
Apologies if I'm posting a question to this group incorrectly or with bad etiquette. I've been reading the emails from this group for a few years and now have a question myself. I am automating the creation of our models and business objects by reading a schema definition from YAML. We use

Re: [sqlalchemy] Declarative Sequences

2013-06-26 Thread Michael Bayer
On Jun 26, 2013, at 12:02 PM, Mat Mathews m...@miga.me wrote: I would like to do something like this: class User(object): id = Column(Integer, Sequence('user_id_seq', start=1), primary_key=True) This does work, and emits the CREATE SEQUENCE, but does not set the owned table

Re: [sqlalchemy] Declarative Sequences

2013-06-26 Thread Mat Mathews
Thanks for the quick reply. If I modify the name of the sequence in the test, it reproduces what I have experienced. When I check the details on the sequence in postgres, there is no table owner or column specified by the sequence 'test_user_id_seq'.. and I would expect to see both tables

Re: [sqlalchemy] Declarative Sequences

2013-06-26 Thread Michael Bayer
On Jun 26, 2013, at 1:26 PM, Mat Mathews m...@miga.me wrote: Thanks for the quick reply. If I modify the name of the sequence in the test, it reproduces what I have experienced. When I check the details on the sequence in postgres, there is no table owner or column specified by the

Re: [sqlalchemy] Declarative Sequences

2013-06-26 Thread Mat Mathews
That absolutely solves my issue. I had a serious suspicion I was missing something, and it was to look at the Column options, not just the Sequence. Thanks a ton. On Jun 26, 2013, at 7:44 PM, Michael Bayer mike...@zzzcomputing.com wrote: On Jun 26, 2013, at 1:26 PM, Mat Mathews

[sqlalchemy] Declarative and deferred

2012-08-11 Thread David McKeone
Short: --- Is there a way to backfill multiple deferred columns in a declarative object result instance in a dynamic way when groups can't be predicted in the model? Long: First, let me just say thanks for SQLAlchemy. This is my first post to this list and after working with it

Re: [sqlalchemy] Declarative and deferred

2012-08-11 Thread Michael Bayer
On Aug 11, 2012, at 10:08 AM, David McKeone wrote: so with this helper I can context sensitively build up a result object with just the stuff I need (but without losing the benefits of the associated methods): deferred = User.get_deferred_except('id', 'password') # Get list of defer()

Re: [sqlalchemy] Declarative and deferred

2012-08-11 Thread David McKeone
session.refresh(user, [title, first_name, last_name]) This was the part that I was missing. It's fairly readable and it does exactly what I'd need. also, if the columns you're actually using are along these lines, that is, they aren't 10K text files, I'd strongly encourage you to

Re: [sqlalchemy] Declarative and deferred

2012-08-11 Thread Michael Bayer
On Aug 11, 2012, at 3:43 PM, David McKeone wrote: Plus I imagine that session.refresh() would load the entire group if an attribute from a group was passed to it. So that could be an interesting way to chunk it. I think the attributes to session.refresh() trump any deferred rules. It

[sqlalchemy] Declarative Models: Can they be used with two databases and two schema names?

2012-06-06 Thread Shawn Wheatley
Hi, I'm trying to use my declarative models to copy data from an Oracle database with a non-default schema name to a SQLite database (which has no schema name, or at least a default name that can't be changed). Copying from Oracle to Oracle has not been a problem for me, but Oracle to SQLite

Re: [sqlalchemy] Declarative Models: Can they be used with two databases and two schema names?

2012-06-06 Thread Michael Bayer
By far the easiest approach is to modify the username you're coming into Oracle as so that the schema in question is the default. Or if you can, create Oracle synonyms (i.e. CREATE SYNONYM) in the default schema that link to the schema-qualified tables. Otherwise SQLA doesn't have a lot of

[sqlalchemy] Re: How do I patch SQLAlchemy declarative model dynamically with Columns of different type?

2012-05-14 Thread gostones
Does anyone have an idea what I may be doing wrong? Thanks for your help in advance. On May 11, 4:29 pm, gostones gosto...@gmail.com wrote: I am running mysql in production but would like to run a simple tests in a sqlite in memory db. The legacy mysql db has tables with columns that are

Re: [sqlalchemy] Re: How do I patch SQLAlchemy declarative model dynamically with Columns of different type?

2012-05-14 Thread Michael Bayer
mutation of Table objects in-place is not something SQLAlchemy supports. I would advise using an extension method to TypeEngine called with_variant() (search the docs for it, cut and paste is not working on this terminal ) which allows a single type object, like a String(), to produce multiple

[sqlalchemy] How do I patch SQLAlchemy declarative model dynamically with Columns of different type?

2012-05-12 Thread gostones
I am running mysql in production but would like to run a simple tests in a sqlite in memory db. The legacy mysql db has tables with columns that are mysql specific types, Which are declared in declarative models (subclassing declarative_base). I would like to run some simple tests without going

[sqlalchemy] declarative versus classes mapped to multiple engines

2012-02-09 Thread Chris Withers
Hi Again, I'm wondering if the use case I have is one that is supported... So, the situation is that I have a bunch of classes that I need to map to a bunch of tables, and I'd prefer to do that declaratively. The spicey bit is that I need to connect to several environments a lot of the time

Re: [sqlalchemy] declarative versus classes mapped to multiple engines

2012-02-09 Thread Michael Bayer
On Feb 9, 2012, at 1:42 PM, Chris Withers wrote: Hi Again, I'm wondering if the use case I have is one that is supported... So, the situation is that I have a bunch of classes that I need to map to a bunch of tables, and I'd prefer to do that declaratively. The spicey bit is that I

Re: [sqlalchemy] declarative versus classes mapped to multiple engines

2012-02-09 Thread Chris Withers
On 09/02/2012 19:51, Michael Bayer wrote: So, my plan is to have one engine per database I connect to. But what to do about tables? So what does it mean for your application to import a module, that has a class MyClass, which should be mapped to a table, but when the app is running, that

Re: [sqlalchemy] declarative versus classes mapped to multiple engines

2012-02-09 Thread Michael Bayer
On Feb 9, 2012, at 3:02 PM, Chris Withers wrote: Almost, but... We can't have per-connection models, that would be semantically weird. Using a different metadata at session creation time, keyed off the dsn of the database connected to, and with irrelevant classes blowing up if used but

Re: [sqlalchemy] declarative versus classes mapped to multiple engines

2012-02-09 Thread Chris Withers
On 09/02/2012 20:06, Michael Bayer wrote: On Feb 9, 2012, at 3:02 PM, Chris Withers wrote: Almost, but... We can't have per-connection models, that would be semantically weird. Using a different metadata at session creation time, keyed off the dsn of the database connected to, and with

Re: [sqlalchemy] declarative and late reflection?

2011-12-27 Thread peter sabaini
Cool -- works nicely, thanks again! On Fri, Dec 23, 2011 at 2:56 AM, Michael Bayer mike...@zzzcomputing.comwrote: On Dec 22, 2011, at 7:28 PM, Michael Bayer wrote: this could work really nicely with extend_existing, which has been enhanced in 0.7.4, but there seem to be some glitches

[sqlalchemy] declarative and late reflection?

2011-12-22 Thread peter sabaini
Hey list, this sounds like it should be a FAQ, didn't find anything though: I want to use the ORM in a declarative style and have the table definition reflected, eg sth like: class A(declarative_base()): __tablename__ = 'A' __table_args__ = {'autoload' : True} However to do this SA

Re: [sqlalchemy] declarative and late reflection?

2011-12-22 Thread Michael Bayer
On Dec 22, 2011, at 9:37 AM, peter sabaini wrote: Hey list, this sounds like it should be a FAQ, didn't find anything though: I want to use the ORM in a declarative style and have the table definition reflected, eg sth like: class A(declarative_base()): __tablename__ = 'A'

Re: [sqlalchemy] declarative and late reflection?

2011-12-22 Thread peter sabaini
Hey! This works for me -- almost :-) In my use case I need to override a column (to provide an artificial FK -- some *erm old school mysql db) which seems to trigger SA into trying to reflect early Observe: from sqlalchemy import * from sqlalchemy.orm import * from sqlalchemy.ext.declarative

Re: [sqlalchemy] declarative and late reflection?

2011-12-22 Thread Michael Bayer
On Dec 22, 2011, at 11:48 AM, peter sabaini wrote: Hey! This works for me -- almost :-) In my use case I need to override a column (to provide an artificial FK -- some *erm old school mysql db) which seems to trigger SA into trying to reflect early Observe: from sqlalchemy

Re: [sqlalchemy] declarative and late reflection?

2011-12-22 Thread Michael Bayer
On Dec 22, 2011, at 7:28 PM, Michael Bayer wrote: this could work really nicely with extend_existing, which has been enhanced in 0.7.4, but there seem to be some glitches preventing it from being super nice, so I can't get that to work right now. Just send in those columns via your own

[sqlalchemy] Declarative Mapping vs Classic Mapping

2011-10-17 Thread Manav Goel
My question is regarding sqlalchemy version 0.7.2. Are there any limitations in using declarative or classic mapping while using sqlalchemy? My main concern is there any limitation of declarative mapping which can put me in some situation where I am stuck with the tables it will create? Also

Re: [sqlalchemy] Declarative Mapping vs Classic Mapping

2011-10-17 Thread Michael Bayer
On Oct 17, 2011, at 1:05 PM, Manav Goel wrote: My question is regarding sqlalchemy version 0.7.2. Are there any limitations in using declarative or classic mapping while using sqlalchemy? there's not, a declarative mapping is nothing more than a small organizing layer on top of the

Re: [sqlalchemy] Declarative Mapping vs Classic Mapping

2011-10-17 Thread Manav Goel
Thanks for the quick reply. One question here, suppose I add column using Alter Table command and then in class declaration the attribute. Will it see the newly added column then or not? Concern is not issuing ALTER command by hand but is the class can see the newly added column. Regards,

Re: [sqlalchemy] Declarative Mapping vs Classic Mapping

2011-10-17 Thread Michael Bayer
The usual development model encouraged by SQLAlchemy is that class and table definitions are a fixed element of your program, declared at the module level. So typically, adding new columns means you're modifying the source code of your app, then rerunning. That said, if you add a column to

[sqlalchemy] declarative __table__ columns

2011-08-12 Thread Mark Erbaugh
Is there a way to access the parameters to the Column() call used to set up a database table when given either an instance field or class field? For example: class MyClass(Base): ... f1 = Column(Integer, nullable=False, info={'min':0}) ... If I have MyClass.f1 or

Re: [sqlalchemy] declarative __table__ columns

2011-08-12 Thread Michael Bayer
On Aug 12, 2011, at 5:05 PM, Mark Erbaugh wrote: Is there a way to access the parameters to the Column() call used to set up a database table when given either an instance field or class field? For example: class MyClass(Base): ... f1 = Column(Integer, nullable=False,

Re: [sqlalchemy] declarative __table__ columns

2011-08-12 Thread Mark Erbaugh
On Aug 12, 2011, at 5:26 PM, Michael Bayer wrote: Is there a way to access the parameters to the Column() call used to set up a database table when given either an instance field or class field? For example: class MyClass(Base): ... f1 = Column(Integer, nullable=False,

Re: [sqlalchemy] Declarative Field Type 'Alias'

2011-08-06 Thread Wichert Akkerman
On 08/05/2011 10:46 PM, Mark Erbaugh wrote: This is more of a Python issue than a SA issue, but I had trouble getting this to work. I did, but the code seems a little awkard to mesigh. In addition to the requirements already, I also wanted toe default value to be a class level 'constant'.

[sqlalchemy] Declarative Field Type 'Alias'

2011-08-05 Thread Mark Erbaugh
In my application, some tables have several fields that need to have the same type and default value, i.e.: field1 = Column(Integer, default=2) field2 = Column(Integer, default=2) ... Is there some way to refactor the Common(Integer, default=2), short of creating a custom column type? I could

Re: [sqlalchemy] Declarative Field Type 'Alias'

2011-08-05 Thread Michael Bayer
On Aug 5, 2011, at 1:36 PM, Mark Erbaugh wrote: In my application, some tables have several fields that need to have the same type and default value, i.e.: field1 = Column(Integer, default=2) field2 = Column(Integer, default=2) ... Is there some way to refactor the Common(Integer,

Re: [sqlalchemy] Declarative Field Type 'Alias'

2011-08-05 Thread Mark Erbaugh
On Aug 5, 2011, at 3:51 PM, Michael Bayer wrote: On Aug 5, 2011, at 1:36 PM, Mark Erbaugh wrote: In my application, some tables have several fields that need to have the same type and default value, i.e.: field1 = Column(Integer, default=2) field2 = Column(Integer, default=2) ...

[sqlalchemy] Declarative: Joined Inheritance + Two Tables To One Object

2011-05-23 Thread Israel Ben Guilherme Fonseca
I have the following: class Person(Base): __tablename__ = 'pessoa' id = Column(id_person), Integer, primary_key = True) name = Column(String) class Teacher(Person): __tablename__ = 'teacher' id = Column(id_teacher, Integer, ForeignKey(Person.id), primary_key=True) info =

Re: [sqlalchemy] Declarative Class registry ?

2011-03-08 Thread Michael Bayer
there's no registry of tables to mappers. You'd need to track that yourself, or otherwise scan through all mappers (non-public attribute sqlalchemy.orm._mapper_registry) looking for tables (each mapper has a .local_table attribute). Note that many mappers can be created against a single

Re: [sqlalchemy] Declarative Class registry ?

2011-03-08 Thread James Mills
On Wed, Mar 9, 2011 at 2:16 AM, Michael Bayer mike...@zzzcomputing.com wrote: there's no registry of tables to mappers.   You'd need to track that yourself, or otherwise scan through all mappers (non-public attribute sqlalchemy.orm._mapper_registry)  looking for tables (each mapper has a

[sqlalchemy] Declarative Class registry ?

2011-03-07 Thread James Mills
Hello, Given a scenario where you're using declarative_base(...) and defining classes Is there a way to ask SA what the mapper class (declarative) is for a given table by inspecting something in metadata[table_name] ? cheers James -- You received this message because you are subscribed to

[sqlalchemy] Declarative, Imports and Base

2011-02-08 Thread Martijn Moeling
Hi, I am having a small issue with multiple python modules and declarative... I might miss something but Consider: a.py: 8--- Base = declarative_base() class A(Base): ... 8--- b.py Base = declarative_base() class B(Base):

Re: [sqlalchemy] Declarative, Imports and Base

2011-02-08 Thread Michael Bayer
On Feb 8, 2011, at 1:19 PM, Martijn Moeling wrote: Hi, I am having a small issue with multiple python modules and declarative... I might miss something but Consider: a.py: 8--- Base = declarative_base() class A(Base): ...

Re: [sqlalchemy] Declarative, Imports and Base

2011-02-08 Thread Martijn Moeling
Michael, Do you ever sleep? I am not sure I get your point. How do I set up a common Base. I could do Base= Declarative_base() from a import A (or * not sure how this differs in this case) from b import B (or *) If I do not declare Base in module a I get an Import Error on class A(Base),

Re: [sqlalchemy] Declarative, Imports and Base

2011-02-08 Thread Chris Withers
Hi Martin, On 08/02/2011 19:25, Martijn Moeling wrote: I am not sure I get your point. How do I set up a common Base. I could do Base= Declarative_base() from a import A (or * not sure how this differs in this case) from b import B (or *) If I do not declare Base in module a I get an Import

Re: [sqlalchemy] Declarative, Imports and Base

2011-02-08 Thread Michael Bayer
the idea is like this: myproject/ myproject/__init__.py myproject/meta.py myproject/somepackage/__init__.py myproject/somepackage/a.py myproject/someotherpackage/__init__.py myproject/someotherpackage/b.py myproject/__init__.py: from myproject.somepackage import a from

Re: [sqlalchemy] Declarative, Imports and Base

2011-02-08 Thread Martijn Moeling
Clear, if all packages are in the same project that is.. and what if in a.py I want to inherit some class mapped with b.py mixin does not allways work as a solution subclassing (DeclarativeMeta) is an option, not sure Once I do a base=declarative_base(metadata=BaseB) every class

Re: [sqlalchemy] Declarative, Imports and Base

2011-02-08 Thread Michael Bayer
On Feb 8, 2011, at 3:57 PM, Martijn Moeling wrote: Clear, if all packages are in the same project that is.. and what if in a.py I want to inherit some class mapped with b.py mixin does not allways work as a solution subclassing (DeclarativeMeta) is an option, not sure Once

Re: [sqlalchemy] Declarative, Imports and Base

2011-02-08 Thread Martijn Moeling
Clear! On Feb 8, 2011, at 10:21 PM, Michael Bayer wrote: On Feb 8, 2011, at 3:57 PM, Martijn Moeling wrote: Clear, if all packages are in the same project that is.. and what if in a.py I want to inherit some class mapped with b.py mixin does not allways work as a solution

Re: [sqlalchemy] declarative one to many relationship with composite primary key

2010-11-17 Thread Adrien Saladin
On Wed, Nov 17, 2010 at 1:16 AM, Michael Bayer mike...@zzzcomputing.com wrote: ForeignKeyConstraint needs to go into __table_args__ when using declarative. http://www.sqlalchemy.org/docs/orm/extensions/declarative.html#table-configuration Thanks for the note. I have updated my test script to

Re: [sqlalchemy] declarative one to many relationship with composite primary key

2010-11-17 Thread Michael Bayer
On Nov 17, 2010, at 9:07 AM, Adrien Saladin wrote: On Wed, Nov 17, 2010 at 1:16 AM, Michael Bayer mike...@zzzcomputing.com wrote: ForeignKeyConstraint needs to go into __table_args__ when using declarative. http://www.sqlalchemy.org/docs/orm/extensions/declarative.html#table-configuration

Re: [sqlalchemy] declarative one to many relationship with composite primary key

2010-11-17 Thread Adrien Saladin
On Wed, Nov 17, 2010 at 4:58 PM, Michael Bayer mike...@zzzcomputing.com wrote: OK its actually a huge SQLA bug that an error isn't raised for that, which is surprising to me, so I created and resolved #1972 in r67d8f4e2fcb9.   __table_args__ is expected to be a tuple or dict, so now an error

[sqlalchemy] declarative one to many relationship with composite primary key

2010-11-16 Thread Adrien
Hi list, Sorry if this is trivial, I'm relatively new to sqlalchemy. I'm trying to set a one to many relationship between class Foo and class Bar (ie Foo should have a list of Bars). Foo has a composite primary key. # from sqlalchemy import * from sqlalchemy.orm

Re: [sqlalchemy] declarative one to many relationship with composite primary key

2010-11-16 Thread Michael Bayer
ForeignKeyConstraint needs to go into __table_args__ when using declarative. http://www.sqlalchemy.org/docs/orm/extensions/declarative.html#table-configuration On Nov 16, 2010, at 6:28 PM, Adrien wrote: Hi list, Sorry if this is trivial, I'm relatively new to sqlalchemy. I'm trying to set

[sqlalchemy] declarative - automatically add a primary key if the table doesn't have one

2010-09-22 Thread Yap Sok Ann
This is related to topic need 0.6_beta2-compat declarative meta http://groups.google.com/group/sqlalchemy/browse_thread/thread/ae7cb9d2ab0b9cca Prior to version 0.6, I use the following code to automatically add a primary key if the table doesn't have one defined: from sqlalchemy.ext.declarative

Re: [sqlalchemy] declarative - automatically add a primary key if the table doesn't have one

2010-09-22 Thread Michael Bayer
On Sep 22, 2010, at 4:30 AM, Yap Sok Ann wrote: This is related to topic need 0.6_beta2-compat declarative meta http://groups.google.com/group/sqlalchemy/browse_thread/thread/ae7cb9d2ab0b9cca Prior to version 0.6, I use the following code to automatically add a primary key if the table

[sqlalchemy] Declarative classproperty member problem in 0.6.4, not 0.6.3

2010-09-15 Thread Nikolaj
The following test fails in 0.6.4 but not 0.6.3 with AttributeError: type object 'Person' has no attribute 'foo'. Is this a deliberate change? It seems a bit weird that every @classproperty on a declarative subclass is accessed/run on import. from sqlalchemy import create_engine, Column, String

Re: [sqlalchemy] Declarative classproperty member problem in 0.6.4, not 0.6.3

2010-09-15 Thread Michael Bayer
On Sep 15, 2010, at 10:04 AM, Nikolaj wrote: The following test fails in 0.6.4 but not 0.6.3 with AttributeError: type object 'Person' has no attribute 'foo'. Is this a deliberate change? It seems a bit weird that every @classproperty on a declarative subclass is accessed/run on import.

Re: [sqlalchemy] Declarative classproperty member problem in 0.6.4, not 0.6.3

2010-09-15 Thread Chris Withers
On 15/09/2010 15:04, Nikolaj wrote: Base = declarative_base() class Person(Base): __tablename__ = 'people' name = Column(String, primary_key=True) @classproperty def bar(cls): return cls.foo Can you explain why you'd want to do something like this? Chris --

  1   2   >