tags:

views:

222

answers:

1

The question is based on the thread, since I observed that Storm allows me reuse my SQL-schemas.

How can you solve the following error message in Storm?

The code is based on Jason's answer and on Storm's manual.

import os, pg, sys, re, psycopg2, storm
from storm.locals import *
from storm import *

class Courses():
    subject = Unicode()

database = create_database("postgres://naa:123@localhost:5432/tk")
store = Store(database)

course = Courses()
course.subject = 'abcd'
store.add(course)

It gives you

Traceback (most recent call last):                                            
  File "<stdin>", line 13, in <module>
  File "/usr/lib/python2.6/dist-packages/storm/store.py", line 245, in add
    obj_info = get_obj_info(obj)
  File "/usr/lib/python2.6/dist-packages/storm/info.py", line 40, in get_obj_info 
    obj_info = ObjectInfo(obj)
  File "/usr/lib/python2.6/dist-packages/storm/info.py", line 162, in __init__
    self.cls_info = get_cls_info(type(obj))
  File "/usr/lib/python2.6/dist-packages/storm/info.py", line 51, in get_cls_info
    cls.__storm_class_info__ = ClassInfo(cls)
  File "/usr/lib/python2.6/dist-packages/storm/info.py", line 69, in __init__
    raise ClassInfoError("%s.__storm_table__ missing" % repr(cls))
storm.exceptions.ClassInfoError: <type 'instance'>.__storm_table__ missing

This suggests to me that some module is missing. There is no module instance in Storm.

+3  A: 

I'll leave out the connection details because I'm not terribly familiar with Postgres.

from storm.locals import *

class Courses(object):
    __storm_table__ = 'courses'
    pkey = Int(primary=True)
    course_nro = Unicode()

course = Courses()
course.course_nro = 'abcd'
store.add(course)
store.commit()

Of course, if you want to do the constructor and initialization on one line, you can use pysistence's expandos:

from storm.locals import *
from pysistence import Expando

class Courses(Expando):
    __storm_table__ = 'courses'
    pkey = Int(primary=True)
    course_nro = Unicode()

course = Courses(course_nro='abcd')
store.add(course)
store.commit()
Jason Baker