예제 #1
0
    def save(self, commit=True):
        """
        Calling the save methode will store the object in the databse.

        :param commit: If `True` (default), each change will direct affect the
            database. If `commit` is `False`
        :type commit: Boolean
        """
        if self.pk and self.__meta__['fields'][self.pk].value:
            __query__ = Query(Query.QTYPE_UPDATE, self.__meta__['fields'],
                            table=self.__meta__['name'],
                            pk=self.pk)
            ret = __query__.run()
            if ret:
                statement, values = ret
                db.execute(statement, values)
                if commit:
                    connection.commit()

        else:
            __query__ = Query(Query.QTYPE_INSERT, self.__meta__['fields'],
                            table=self.__meta__['name'],
                            pk=self.pk)
            ret = __query__.run()
            if ret:
                statement, values = ret
                db.execute(statement, values)
                if commit:
                    connection.commit()
                if self.pk:
                    self.__meta__['fields'][self.pk].value = db.lastrowid
예제 #2
0
 def truncate(cls):
     """
     This method removes all records in this table from the database.
     """
     # TODO: dry_run
     __query__ = Query(Query.QTYPE_TRUNCATE, {}, table=cls.__name__.lower())
     ret = __query__.run()
     if ret:
         statement, values = ret
         db.execute(statement, values)
         connection.commit()
예제 #3
0
 def drop(cls):
     """
     This method drops this table from the database.
     """
     # TODO: dry_run
     __query__ = Query(Query.QTYPE_DROP, {}, table=cls.__name__.lower())
     ret = __query__.run()
     if ret:
         statement, values = ret
         db.execute(statement, values)
         connection.commit()
예제 #4
0
    def delete(self, commit=True):
        """
        Calling this method will remove the object from the database. However,
        any variable that is referring an instance still access it.

        :param commit: If true, each change will direct affect the database
        :type commit: Boolean
        """
        if self.pk and self.__meta__['fields'][self.pk].value:
            __query__ = Query(Query.QTYPE_DELETE, self.__meta__['fields'],
                            table=self.__meta__['name'],
                            pk=self.pk)
            ret = __query__.run()
            if ret:
                statement, values = ret
                db.execute(statement, values)
                if commit:
                    connection.commit()
예제 #5
0
 def commit(self):
     """
     This function forces a commit of all data within the current
     connection
     """
     connection.commit()