Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using list as a data type in a column (SQLAlchemy)

I want to store a list of rss feed urls in an sqlite db. I'm using SQLAlchemy and was wondering how to store these. I can't seem to find any documentation about lists, and was wondering if this was legal for a column: Column('rss_feed_urls', List)

Or is there an array type that I could use?

like image 471
Chris Avatar asked Sep 04 '11 15:09

Chris


1 Answers

If you really must you could use the PickleType. But what you probably want is another table (which consists of a list of rows, right?). Just create a table to hold your RSS feeds:

class RssFeed(Base):     __tablename__ = 'rssfeeds'     id = Column(Integer, primary_key=True)     url = Column(String) 

Add new urls:

feed = RssFeed(url='http://url/for/feed') session.add(feed) 

Retrieve your list of urls:

session.query(RssFeed).all() 

Find a specific feed by index:

session.query(RssFeed).get(1) 

I'd recommend SQLAlchemy's Object Relational Tutorial.

like image 78
zeekay Avatar answered Sep 25 '22 13:09

zeekay