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
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()
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()
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()
def commit(self): """ This function forces a commit of all data within the current connection """ connection.commit()