In storm, I miss the feature to have an automatic generated schema.

For example: I must write

   1 from storm.locals import *
   2 
   3 store = Store(create_database('sqlite:'))
   4 
   5 class Movie(object):
   6     __storm_table__ = 'movies'
   7     id = Int(primary=True)
   8     title = Char()
   9     language = Char()
  10     length_in_min = Int()
  11     description = Unicode()
  12 
  13 store.execute('CREATE TABLE movies '
  14     '(id INTEGER PRIMARY KEY, title VARCHAR, language VARCHAR, length_in_min INTEGER,'
  15     'description TEXT)')

I think the last part (store.execute(...)) is unnecessary. You can set default values for the SQL part and if you want to change something, you can change it via argument:

   1 class Movie(object):
   2     __storm_table__ = 'movies'
   3     id = Int(primary=True)
   4     title = Char(sql_field='title TEXT')
   5     language = Char()
   6     length_in_min = Int()
   7     description = Unicode()

Also, now is title a Text field and you needn't to write the last part for changing it. I think it's better because mostly, the first part is the same like the second part. And with this solution it's simpler to write your own store and define you own database in an other file than the database model. Example:

   1 # database.py
   2 
   3 store = Store(create_database('sqlite:'))
   4 
   5 class Movie(object):
   6     __storm_table__ = 'movies'
   7     id = Int(primary=True)
   8     title = Char()
   9     language = Char()
  10     length_in_min = Int()
  11     description = Unicode()
  12 
  13 store.execute('CREATE TABLE movies '
  14     '(id INTEGER PRIMARY KEY, title VARCHAR, language VARCHAR, length_in_min INTEGER,'
  15     'description TEXT)')
  16 
  17 # application.py
  18 
  19 from database import store, Movie

With my idea you can make

   1 # database.py
   2 
   3 store = Store(create_database('sqlite:'))
   4 
   5 class Movie(object):
   6     __storm_table__ = 'movies'
   7     id = Int(primary=True)
   8     title = Char()
   9     language = Char()
  10     length_in_min = Int()
  11     description = Unicode()
  12 
  13 # application.py
  14 
  15 from storm.locals import *
  16 
  17 from database import Movie
  18 
  19 store = Store(create_database('sqlite:'))
  20 store.add_table(Movie)
  21 
  22 # do inserts, selects and other stuff...

But maybe this is another idea.

And for people who don't like that, you can put in an own file that you must import it extra.

   1 import storm.schema
   2 
   3 # work like described above

So that you can work with it or without it.

Just an idea...

Cheers,

Rafael Weber


I have implemented a prototype of this at: http://bazaar.launchpad.net/~aafshar/storm/automatic-table-schema-generation

At the moment the mapping of attribute types to schema types is hard-coded. I suspect that eventually you would want to ask the database what to do.

AliAfshar

UPDATE: This branch has been obsoleted, and replaced with: http://bazaar.launchpad.net/~cg-webshox/storm/auto-schema-creation

AutomaticSchemaGeneration (last edited 2008-06-19 17:42:21 by localhost)