take a look at the sqlalchemy docs
and look for

session.clear

session.expunge

session.expunge_all

On Sat, 2011-02-26 at 22:05 +0100, Magnus Pettersson wrote:
> Nice i will take a read :)
> 
> 
> This question is kinda off topic but related to Elixir:
> 
> 
> If i have created entities like Item and Library etc but i have not
> called session.commit.. how can i  get rid of those "unsaved" entities
> with a command?
> Example if i do:
> 
> 
> ------------------------------
> movieLib = Library(path=u"V:/Movies/",name=u"MyLibrary",type=u"movie")
> movie = Item(path=u"V:/Movies/MyMovie.(2009)/",
> title=u"MyMovie",year=u"2009",type=u"movie")
> #The code to delete unsaved entities here
> session.commit
> -------------------------------
> 
> 
> So when session.commit is called there is nothing to save (the library
> and Item i created should not be saved to the database).
> 
> 
> Im trying as we speak with all functions that could be relevant when
> using dir(session) but no luck yet
> 
> On 26 February 2011 11:30, Erik Janssens <[email protected]>
> wrote:
>         I've written some docs on how this is handled in Camelot, the
>         same principles apply for Elixir though
>         
>         
> http://downloads.conceptive.be/downloads/camelot/doc/sphinx/build/doc/under_the_hood.html
>         
>         
>         
>         On Fri, 2011-02-25 at 12:30 -0800, Magnus Pettersson wrote:
>         > I have written all classes that handles the sqlite database
>         in one
>         > python file called "mediaDatabase.py" and then i want to
>         import that
>         > module into another file "mediaGui.py" to be able to query
>         and write
>         > to the database. but i always get a
>         sqlalchemy.exc.OperationalError
>         > that table does not exist or databse is locked (think it was
>         the
>         > "table does not exist" if i actually created and filled and
>         some
>         > entrys into the database.sqlite file from within the
>         mediaDatabase.py,
>         > and i get "database is locked" when i created the sqlite
>         file and
>         > entities from within the "mediaGui.py" file
>         >
>         > Here is the locked exception:
>         > sqlalchemy.exc.OperationalError: (OperationalError) database
>         is locked
>         > u'INSERT INTO mediadatabase_item (path, title, type, year,
>         "imdbID",
>         > genres, library_path) VALUES
>         (?, ?, ?, ?, ?, ?, ?)' (u'V:/Movies/',
>         > u'Bedtime Stories', 'movie', u'2008', None, None, None)
>         >
>         > I tried to read around about sqlalchemy and found out that i
>         need to
>         > do something with the metadata or session but i cant figure
>         out what &
>         > how & where to put stuff
>         >
>         > A extract from mediaDatabase.py:
>         >
>         > from elixir import *
>         > dbfile = "mediaDatabase.sqlite"
>         >
>         > class Database:
>         >     def initDb(self):
>         >         metadata.bind = "sqlite:///%s" % dbfile
>         >         setup_all()
>         >         if not os.path.exists(dbfile):
>         >             create_all()
>         >
>         >     def saveData(self):
>         >         session.commit()
>         >
>         >     def parseMediaItem(self,media):
>         >         item =
>         >
>         Item(path=media["path"],title=media["title"],type=media["type"])
>         >         libs = Library.query.all()
>         >         for lib in libs:
>         >             if lib.path == item.path:
>         >                 lib.items.append(item)
>         >                 foundlib = True
>         >                 break
>         >
>         > class File(Entity):
>         >     path = Field(Unicode, required=True)
>         >     filename = Field(Unicode, required=True)
>         >     ext = Field(Unicode,required=True)
>         >     item = ManyToOne("Item")
>         >
>         > class Library(Entity):
>         >     path = Field(Unicode, primary_key=True)
>         >     name = Field(Unicode)
>         >     items = OneToMany("Item")
>         >
>         >
>         > And some lines from mediaGui.py :
>         >
>         > from mediaDatabase import Database,Item,Library,File
>         > MDB = Database()
>         >
>         > class MainForm(QtGui.QMainWindow, Ui_MainWindow):
>         >       #init etc here
>         >
>         >       def update(self):
>         >              #some code here
>         >             MDB.parseMediaItem(m)  # HERE comes the error,
>         right now
>         > when writing its a
>         >
>         >
>         > if __name__ == "__main__":
>         >     MDB.initDb()
>         >
>         
>         
>         --
>         You received this message because you are subscribed to the
>         Google Groups "SQLElixir" group.
>         To post to this group, send email to
>         [email protected].
>         To unsubscribe from this group, send email to sqlelixir
>         [email protected].
>         For more options, visit this group at
>         http://groups.google.com/group/sqlelixir?hl=en.
>         
>         
> 
> 
> 
> -- 
> You received this message because you are subscribed to the Google
> Groups "SQLElixir" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to sqlelixir
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/sqlelixir?hl=en.


-- 
You received this message because you are subscribed to the Google Groups 
"SQLElixir" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sqlelixir?hl=en.

Reply via email to