[sqlalchemy] SQLAlchemy-ImageAttach: an extension for attaching images to entity objects
Hi, I am glad to introduce SQLAlchemy-ImageAttach, a new extension for attaching images to entity objects. It provides the following features: - Storage backend interface: Yu can use file system backend on your local development box, and switch it to AWS S3 when it’s deployed to the production box. Or you can add a new backend implementation by yourself. - Maintaining multiple image sizes: Any size of thumbnails can be generated from the original size without assuming the fixed set of sizes. You can generate a thumbnail of a particular size if it doesn't exist yet when the size is requested. Use RRS (Reduced Redundancy Storage) for reproducible thumbnails on S3. - Every image has its URL: Attached images can be exposed as a URL. - SQLAlchemy transaction aware: Saved file are removed when the ongoing transaction has been rolled back. - Tested on various environments: Python 2.6, 2.7, 3.2, 3.3, PyPy / PostgreSQL, MySQL, SQLite / SQLAlchemy 0.8 or higher On the other hand, it does not provide: - General file attachment: It only supports images. - BLOB storage: It doesn’t use BLOB data type at all. - Image preprocessing: It simply does resizing, but any other image processings like crop aren’t provided. (Although you can do such things using Wand, SQLAlchemy-ImageAttach depends on.) Today I released SQLAlchemy-ImageAttach 0.8.0 which is its first stable version. You can install it using pip or easy_install: $ pip install SQLAlchemy-ImageAttach Docs and repository can be found at the following urls: https://sqlalchemy-imageattach.readthedocs.org/ https://github.com/crosspop/sqlalchemy-imageattach Please try it out and give me feedback! Thanks, Hong Minhee smime.p7s Description: S/MIME cryptographic signature
[sqlalchemy] Specifying foreign_keys and remote_side in self-referential many-to-many relationship
Hi, I have two tables User and Following, and User has two relationships followings and followers. It’s so typical, and next I want is readonly relationship to union of followings and followers. I tried like: friends = relationship( 'User', collection_class=set, primaryjoin='''or_( and_(foreign(User.id) == Following.follower_id, remote(User.id) == Following.followee_id), and_(foreign(User.id) == Following.followee_id, remote(User.id) == Following.follower_id) )''', viewonly=True ) but it seems to no work because foreign_keys and remote_side are the same columns (User.id). The error message is: sqlalchemy.exc.ArgumentError: Can't determine relationship direction for relationship 'User.friends' - foreign key columns within the join condition are present in both the parent and the child's mapped tables. Ensure that only those columns referring to a parent column are marked as foreign, either via the foreign() annotation or via the foreign_keys argument. Basically I want to find how to specify foreign_keys and remote_side in such self-referential many-to-many relationships, but it’s okay if there’re any other ways to implement the same thing. I just need to use such relationship in query expressions e.g. query.filter(User.friends.any(…)), query.options(joinedload(User.friends)) and instance properties e.g. map(make_json, user.friends). (If I implement it using @property decorator it won’t work with query expressions.) I read these two chapters in the docs: http://docs.sqlalchemy.org/en/rel_0_8/orm/relationships.html#self-referential-many-to-many-relationship http://docs.sqlalchemy.org/en/rel_0_8/orm/relationships.html#creating-custom-foreign-conditions Are there any other resources to get more hints about it? Thanks, Hong Minhee -- 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, send email to sqlalchemy@googlegroups.com. Visit this group at http://groups.google.com/group/sqlalchemy?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
[sqlalchemy] Re: Specifying foreign_keys and remote_side in self-referential many-to-many relationship
It seems I found the most close solution: http://stackoverflow.com/a/9119764/383405 I haven’t been aware that secondary can take select() query as well. Might there be another way to achieve the same by any chance? On Jun 5, 2013, at 9:27 PM, Hong Minhee min...@dahlia.kr wrote: Hi, I have two tables User and Following, and User has two relationships followings and followers. It’s so typical, and next I want is readonly relationship to union of followings and followers. I tried like: friends = relationship( 'User', collection_class=set, primaryjoin='''or_( and_(foreign(User.id) == Following.follower_id, remote(User.id) == Following.followee_id), and_(foreign(User.id) == Following.followee_id, remote(User.id) == Following.follower_id) )''', viewonly=True ) but it seems to no work because foreign_keys and remote_side are the same columns (User.id). The error message is: sqlalchemy.exc.ArgumentError: Can't determine relationship direction for relationship 'User.friends' - foreign key columns within the join condition are present in both the parent and the child's mapped tables. Ensure that only those columns referring to a parent column are marked as foreign, either via the foreign() annotation or via the foreign_keys argument. Basically I want to find how to specify foreign_keys and remote_side in such self-referential many-to-many relationships, but it’s okay if there’re any other ways to implement the same thing. I just need to use such relationship in query expressions e.g. query.filter(User.friends.any(…)), query.options(joinedload(User.friends)) and instance properties e.g. map(make_json, user.friends). (If I implement it using @property decorator it won’t work with query expressions.) I read these two chapters in the docs: http://docs.sqlalchemy.org/en/rel_0_8/orm/relationships.html#self-referential-many-to-many-relationship http://docs.sqlalchemy.org/en/rel_0_8/orm/relationships.html#creating-custom-foreign-conditions Are there any other resources to get more hints about it? Thanks, Hong Minhee -- 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, send email to sqlalchemy@googlegroups.com. Visit this group at http://groups.google.com/group/sqlalchemy?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
[sqlalchemy] How to set the column which has default value to explicitly None
Hi, I have a model class which contains a nullable DateTime column, and its default value is now(). Its value is None immediately after it’s instantiated with Model(col=None), but it becomes filled to the current time after the session gets flushed. (Note: I’m using sqlalchemy.ext.declarative with its default constructor.) Does defaultvalue mean just alternative value to None? I want to make the column to be set to the current time by default, but still possible to be explicitly set to None if needed. Is there any way to achieve this? Thanks, Hong Minhee -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To view this discussion on the web visit https://groups.google.com/d/msg/sqlalchemy/-/m93YnzBU_tUJ. To post to this group, send email to sqlalchemy@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
Re: [sqlalchemy] Re: How to set the column which has default value to explicitly None
It works very well. Thanks! On Friday, December 14, 2012 at 5:52 AM, Michael Bayer wrote: tricky, perhaps try setting the column to the expression sqlalchemy.sql.null() for now.A None does indicate fire the default. On Thursday, December 13, 2012 12:41:38 PM UTC-5, Hong Minhee wrote: Hi, I have a model class which contains a nullable DateTime column, and its default value is now(). Its value is None immediately after it’s instantiated with Model(col=None), but it becomes filled to the current time after the session gets flushed. (Note: I’m using sqlalchemy.ext.declarative with its default constructor.) Does default value mean just alternative value to None? I want to make the column to be set to the current time by default, but still possible to be explicitly set to None if needed. Is there any way to achieve this? Thanks, Hong Minhee -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To view this discussion on the web visit https://groups.google.com/d/msg/sqlalchemy/-/LO99H_UrY1wJ. To post to this group, send email to sqlalchemy@googlegroups.com (mailto:sqlalchemy@googlegroups.com). To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com (mailto:sqlalchemy+unsubscr...@googlegroups.com). For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en. -- 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 sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
[sqlalchemy] Best practice for faves/likes counting?
Hi, I am making a typical web application using SQLAlchemy, and it contains “users”, “works” and “likes”: - users ( id, login, … ) - works ( id, title, … ) - likes ( user_id, work_id ) I want to print how many users liked each work, so the most simple (but naive) is querying count of them e.g.: len(work.like_set) work.like_query.count() However it’s inefficient, so I want to maintain like_count field or such thing for works. The problem is that I have to manually update the field every time new like is inserted or existing like is deleted. I thought it could be automatically updated without inconsistency if I catch SQLAlchemy events, but I’m not sure whether it’s correct way to do it or not. How do you guys solve such situation with SQLAlchemy? Thanks, Hong Minhee -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To view this discussion on the web visit https://groups.google.com/d/msg/sqlalchemy/-/EnzHBbacWU8J. To post to this group, send email to sqlalchemy@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
[sqlalchemy] Re: Best practice for faves/likes counting?
But for work in works: work.like_query.count() causes inefficient 1+N queries even if we have the right indices for it. Of course I could query like session.query(Work, count()).join(Work.like_set).group_by(Work) but it’s somewhat complicated to read and write for me (is it only me?). I want to reject such uses in ORM… Anyway I use PostgreSQL. On Thursday, December 6, 2012 9:17:14 AM UTC+9, Eric Ongerth wrote: But work.like_query.count() will be efficient if you have the right indexes in the database, no? I think if you want to denormalize that count all the way and also stay very efficient, maybe it would be good to do it right on the db server with a trigger and a stored procedure and avoid extra python function calls. What database do you use? On Wednesday, December 5, 2012 3:06:03 PM UTC-8, Hong Minhee wrote: Hi, I am making a typical web application using SQLAlchemy, and it contains “users”, “works” and “likes”: - users ( id, login, … ) - works ( id, title, … ) - likes ( user_id, work_id ) I want to print how many users liked each work, so the most simple (but naive) is querying count of them e.g.: len(work.like_set) work.like_query.count() However it’s inefficient, so I want to maintain like_count field or such thing for works. The problem is that I have to manually update the field every time new like is inserted or existing like is deleted. I thought it could be automatically updated without inconsistency if I catch SQLAlchemy events, but I’m not sure whether it’s correct way to do it or not. How do you guys solve such situation with SQLAlchemy? Thanks, Hong Minhee -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To view this discussion on the web visit https://groups.google.com/d/msg/sqlalchemy/-/WoMqe657sPEJ. To post to this group, send email to sqlalchemy@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
[sqlalchemy] Re: SQLAlchemy column_property
You could use hybrid attributes to do that. http://docs.sqlalchemy.org/en/rel_0_7/orm/extensions/hybrid.html On Wednesday, August 29, 2012 5:22:02 PM UTC+9, Denis Rykov wrote: I have two models: class Report(Base): __tablename__ = 'report' id = Column(Integer, primary_key=True) class ReportPhoto(Base): __tablename__ = 'report_photo' id = Column(Integer, primary_key=True) report_id = Column(Integer, ForeignKey(Report.id), nullable=False) report = relationship(Report, uselist=False, backref=backref('report_photo', uselist=True)) And I would like to add column to Report model which indicates is there any records within ReportPhoto. I try to use [column_property][1] this way: class Report(Base): __tablename__ = 'report' id = Column(Integer, primary_key=True) has_photo = column_property( select(ReportPhoto.any()) ) but get an error `NameError: name 'ReportPhoto' is not defined`. How I can fix this issue? -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To view this discussion on the web visit https://groups.google.com/d/msg/sqlalchemy/-/mq1-pGbqYDwJ. To post to this group, send email to sqlalchemy@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
Re: [sqlalchemy] SQLAlchemy-Future
Could you tell me how it is going on? -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalch...@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
Re: [sqlalchemy] SQLAlchemy-Future
I don’t know why setuptools provides pkg_resources, implements another incompatible way to declare namespace packages, additionally in spite of existence of pkgutil.extend_path, the standard way to do it. IMO sqlalchemy.contrib namespace have to be declared by using pkgutil.extend_path, because it is a part of Python standard library so it don’t force users to install setuptools. -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalch...@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
Re: [sqlalchemy] SQLAlchemy-Future
In the case of Flask and Sphinx, they use the namespace package called flaskext and sphinxcontrib. - http://flask.pocoo.org/docs/extensiondev/ - https://bitbucket.org/birkenfeld/sphinx-contrib See the case of repoze.bfg also. It made repoze and repoze.bfg both namespace packages: - http://repoze.org/viewcvs/repoze.bfg/trunk/setup.py?rev=10644view=markup - http://repoze.org/viewcvs/repoze.bfg/trunk/repoze/__init__.py?rev=1228view=markup - http://repoze.org/viewcvs/repoze.bfg/trunk/repoze/bfg/__init__.py?rev=4409view=markup -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalch...@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
Re: [sqlalchemy] SQLAlchemy-Future
Thanks for your fine answer. Is there any plan of defining sqlalchemy.contrib namespace package into current 0.7 branch or 0.6.x release? I hope for it to be clear. -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalch...@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
[sqlalchemy] SQLAlchemy-Future
Hi everyone, I’ve been written a small extension that introduces promise/future[1] model to SQLAlchemy query objects. The documentation can be found http://lunant.github.com/SQLAlchemy-Future/ but it’s written in my awkward English, so any indications about my writing are welcome. Anyway, there is a trivial problem. I wanted to make its module name `sqlalchemy.ext.future` or `sqlalchemy.contrib.future`, but it requires the declaration that `sqlalchemy.ext` or `sqlalchemy.contrib` are namespace packages. So I named the module as just `future` unwillingly currently. In short, it is my question: What module name is good for this package? Or, could a slightly standardized namespace like `sqlalchemy.ext`/`sqlalchemy.contrib` defined by Michael Bayer? [1] http://en.wikipedia.org/wiki/Futures_and_promises -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalch...@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.