[sqlalchemy] Re: flushing and saving data using default_metadata
another thing, g does not work from websetup.py, which I would have liked thanks --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalchemy@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Re: flushing and saving data using default_metadata
I have found a solution which works, but what is the correct way Michael? I created in base.py: metadata = DynamicMetaData() then in my websetup.py : uri = conf['sqlalchemy.dburi'] engine = create_engine(uri) metadata.connect(uri) metadata.create_all() this works, but you mentioned that I should use MetaData() in my case, which I am having problems with, could you detail at where and what I should import to use Metadata()? Why the preference over Dynamic? thanks --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalchemy@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Re: flushing and saving data using default_metadata
almost there: I put this in base.py from sqlalchemy import * metadata = MetaData() so anywhere I need it I just import: from gameolymp.lib.base import * I have no errors, but no databases are created or dropped, this is what I added to my websetup.py from sqlalchemy import * from myapp.lib.base import * uri = conf['sqlalchemy.dburi'] engine = create_engine(uri) metadata = BoundMetaData(engine) metadata.create_all() no errors, but no reaction Thanks for your patience Michael On Jun 13, 7:58 pm, Michael Bayer <[EMAIL PROTECTED]> wrote: > dont use "g". just get at it via .base.metadata. > > if you want to use "g", put it in app_globals.py. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalchemy@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Re: flushing and saving data using default_metadata
dont use "g". just get at it via .base.metadata. if you want to use "g", put it in app_globals.py. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalchemy@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Re: flushing and saving data using default_metadata
Actually I thought that global_metadata was deprecated not Dynamic since you said i should not be using it. creating metadata in the base.py causes a trace, using: from sqlalchemy import * g.metadata = MetaData() D:\Projects\Pylons_projects\gameolymp>paster setup-app development.ini Traceback (most recent call last): File "C:\Python24\Scripts\paster-script.py", line 7, in ? sys.exit( File "c:\python24\lib\site-packages\PasteScript-1.3.4-py2.4.egg\paste \script\c ommand.py", line 76, in run invoke(command, command_name, options, args[1:]) File "c:\python24\lib\site-packages\PasteScript-1.3.4-py2.4.egg\paste \script\c ommand.py", line 115, in invoke exit_code = runner.run(args) File "c:\python24\lib\site-packages\PasteScript-1.3.4-py2.4.egg\paste \script\a ppinstall.py", line 65, in run return super(AbstractInstallCommand, self).run(new_args) File "c:\python24\lib\site-packages\PasteScript-1.3.4-py2.4.egg\paste \script\c ommand.py", line 210, in run result = self.command() File "c:\python24\lib\site-packages\PasteScript-1.3.4-py2.4.egg\paste \script\a ppinstall.py", line 451, in command installer.setup_config( File "c:\python24\lib\site-packages\PasteScript-1.3.4-py2.4.egg\paste \script\a ppinstall.py", line 579, in setup_config mod = import_string.try_import_module(mod_name) File "c:\python24\lib\site-packages\Paste-1.3-py2.4.egg\paste\util \import_stri ng.py", line 81, in try_import_module return import_module(module_name) File "c:\python24\lib\site-packages\Paste-1.3-py2.4.egg\paste\util \import_stri ng.py", line 67, in import_module mod = __import__(s) File "D:\Projects\Pylons_projects\gameolymp\gameolymp\websetup.py", line 4, in ? from gameolymp.maf.models.models import * File "D:\Projects\Pylons_projects\gameolymp\gameolymp\maf\models \models.py", l ine 23, in ? from user import * File "D:\Projects\Pylons_projects\gameolymp\gameolymp\maf\models \user.py", lin e 6, in ? from gameolymp.lib.base import * File "D:\Projects\Pylons_projects\gameolymp\gameolymp\lib\base.py", line 16, i n ? g.metadata = MetaData() File "c:\python24\lib\site-packages\Paste-1.3-py2.4.egg\paste \registry.py", li ne 128, in __setattr__ setattr(self._current_obj(), attr, value) File "c:\python24\lib\site-packages\Paste-1.3-py2.4.egg\paste \registry.py", li ne 177, in _current_obj raise TypeError( TypeError: No object (name: G) has been registered for this thread On Jun 13, 6:15 pm, Michael Bayer <[EMAIL PROTECTED]> wrote: > On Jun 13, 2007, at 12:07 PM, voltron wrote: > > > > > aha, ok, thanks, but I saw it in the docs, ist it deprecated? Then I > > ´m in a spot > > DynamicMetaData is not deprecated. but when you connect to it, its > a thread-local connection. other threads that access it wont have > any engine. you just want to use a regular MetaData, which these days > has a connect() method. but you might not even need to do that with > a pylons configuration. > > > > > If I go the route of creating meta first I would have to create it in > > every table file, in users.py, addresses.py e.tc. I tried using a file > > called _initmodels.py and created the metadata only once and made alle > > the separate table files import from it, but that ultimately failed > > because when I imported it in websetup.py in pylons so I can use it to > > setup my databses and app, it did not find the metadata properly, it > > assumed it was another metadata, and naturally, no dtabases were > > created > > that sounds like you need to get control of your application > modules. you should declare your metadata in some common place, like > for pylons in base.py or app_globals.py, where everyone else can get > to it. > > but additionally, Pylons connects the database to the session, so > typically in a pylons app theres not even any need to connect the > engine to the metadata. to issue a create_all() just do > metadata.create_all(connectable=sessioncontext.current.connect()). --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalchemy@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Re: flushing and saving data using default_metadata
On Jun 13, 2007, at 12:07 PM, voltron wrote: > > aha, ok, thanks, but I saw it in the docs, ist it deprecated? Then I > ´m in a spot DynamicMetaData is not deprecated. but when you connect to it, its a thread-local connection. other threads that access it wont have any engine. you just want to use a regular MetaData, which these days has a connect() method. but you might not even need to do that with a pylons configuration. > > If I go the route of creating meta first I would have to create it in > every table file, in users.py, addresses.py e.tc. I tried using a file > called _initmodels.py and created the metadata only once and made alle > the separate table files import from it, but that ultimately failed > because when I imported it in websetup.py in pylons so I can use it to > setup my databses and app, it did not find the metadata properly, it > assumed it was another metadata, and naturally, no dtabases were > created that sounds like you need to get control of your application modules. you should declare your metadata in some common place, like for pylons in base.py or app_globals.py, where everyone else can get to it. but additionally, Pylons connects the database to the session, so typically in a pylons app theres not even any need to connect the engine to the metadata. to issue a create_all() just do metadata.create_all(connectable=sessioncontext.current.connect()). --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalchemy@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Re: flushing and saving data using default_metadata
aha, ok, thanks, but I saw it in the docs, ist it deprecated? Then I ´m in a spot I have a pool of tables and class in different files, When I start a new application, all I want to do is for example: from mymodels import Addresses from mymodels import import users and so on to select the types of tables I would want to use for the application in this pool, I cannot code the tables with a metadata beforehand because it has to be created first meta = DynamicMetaData() users = Table("users",meta Column("id",Integer,primary_key=True), Column("username", String(255),unique=True, nullable=False) ) If I go the route of creating meta first I would have to create it in every table file, in users.py, addresses.py e.tc. I tried using a file called _initmodels.py and created the metadata only once and made alle the separate table files import from it, but that ultimately failed because when I imported it in websetup.py in pylons so I can use it to setup my databses and app, it did not find the metadata properly, it assumed it was another metadata, and naturally, no dtabases were created What should be used in this case? thanks On Jun 13, 3:11 pm, Michael Bayer <[EMAIL PROTECTED]> wrote: > On Jun 13, 2007, at 7:54 AM, voltron wrote: > > > > > I have decided to use the global_metada to setup the tables in my app, > > in one of the tables, users, I setup an admin account > > > user = User("john doe", "[EMAIL PROTECTED]") > > > how do I flush the the above object? user.flush() does not work in > > this context because the User object does not have the attribute > > "flush" ( traceback) > > first of all, global_metadata is being removed in version 0.4. not > to mention, being able to say user.flush() (which only occurs now > when you use assignmapper). global_metadata is hardcoded to the > "dynamicmetadata" which is an object most people shouldnt be using. > shortcuts to configuration like that lead to people not understanding > very well what they're doing. > > but beyond that, global_metadata has nothing to do with the object > relational mapper. you would still have to create an explicit > session with the example code above, in which to save your User object. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalchemy@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Re: flushing and saving data using default_metadata
On Jun 13, 2007, at 7:54 AM, voltron wrote: > > I have decided to use the global_metada to setup the tables in my app, > in one of the tables, users, I setup an admin account > > user = User("john doe", "[EMAIL PROTECTED]") > > how do I flush the the above object? user.flush() does not work in > this context because the User object does not have the attribute > "flush" ( traceback) > first of all, global_metadata is being removed in version 0.4. not to mention, being able to say user.flush() (which only occurs now when you use assignmapper). global_metadata is hardcoded to the "dynamicmetadata" which is an object most people shouldnt be using. shortcuts to configuration like that lead to people not understanding very well what they're doing. but beyond that, global_metadata has nothing to do with the object relational mapper. you would still have to create an explicit session with the example code above, in which to save your User object. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalchemy@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---