Remove expired records from database

@see \Spork\Mvc\Listener\Limit\Storage\StorageInterface::clean()
180814
public function clean()
    {
        $this->assertReady();
        
        $sql = sprintf("DELETE FROM %s WHERE %s < NOW() - INTERVAL %d SECOND",
            $this->dbAdapter->platform->quoteIdentifier($this->table),
            $this->dbAdapter->platform->quoteIdentifier($this->timestampColumn),
            $this->getCleanInterval()->toSeconds());
        
        $this->dbAdapter->query($sql, DbAdapter::QUERY_MODE_EXECUTE);
    }
64234
function clean()
    {
        try {
            $this->collection->drop();
        } catch (\Exception $e) {
            throw new exWriteError($e->getMessage(), $e->getCode(), $e);
        }
    }
204723
public function purgeExpired()
    {

        if ($this->sqlInitialized()) {
            if ($this->sql) {
                if ($this->sql->query("
                    DELETE
                        FROM `{$this->table}`
                        WHERE `expire` < NOW()
                ")) {
                    return true;
                }
            }
        }
        return false;
    }
60870
def prune_database():
    
    now = datetime.now()
    expired = TokenBlacklist.query.filter(TokenBlacklist.expires < now).all()
    for token in expired:
        db.session.delete(token)
    db.session.commit()
434717
public function clean($expiration)
    {
        $files = glob($this->path . '*');

        if ($files === false) {
            return;
        }

        foreach ($files as $file) {
            if (filetype($file) == 'file' && filemtime($file) < $expiration) {
                unlink($file);
            }
        }
    }
78500
static function cleanAll()
    {
        $db = eZDB::instance();
        $definition = eZISBNRegistrantRange::definition();
        $table = $definition['name'];
        $sql = "TRUNCATE TABLE " . $table;
        $db->query( $sql );
    }
172828
public function forceDelete()
    {
        // get records
        $affectedRecords = $this->getAffectedRecords()->toArray();
        $ids = array_map(function($record) {
            return $record->{$this->model->getKeyName()};
        }, $affectedRecords);

        // delete main table records
        if (! $this->query->delete()) {
            return false;
        }

        // delete version table records
        $db = $this->model->getConnection();
        return $db->table($this->model->getVersionTable())
            ->whereIn($this->model->getVersionKeyName(), $ids)
            ->delete();
    }
1332668
public function deleteAllExpired()
    {
        $expiredBlacklistedTokens = $this->findAllExpired();

        foreach ($expiredBlacklistedTokens as $expiredBlacklistedToken)
        {
            $this->delete($expiredBlacklistedToken['id']);
        }
    }
223682
public function clear()
    {
        $lastQuery = $this->query;
        $this->query = new Query($this->error, $lastQuery->getInitializer());
        $this->query->forceLimit($lastQuery->getLimit());
        $this->query->forceOffset($lastQuery->getOffset());

        if (!is_array($lastQuery->getResultDataType())) {
            $this->query->setResultDataType($lastQuery->getResultDataType());
        }

        return $this;
    }
438910
public function cleanupTrash()
    {
        $query = $this->handler->createDeleteQuery();
        $query->deleteFrom('ezcontentobject_trash');
        $query->prepare()->execute();
    }
531492
function expunge()
    {
        if ($this->type == 'db' && $this->db && $this->ttl) {
            $this->db->query(
                "DELETE FROM {$this->table}"
                . " WHERE `cache_key` LIKE ?"
                . " AND `expires` < " . $this->db->now(),
                $this->prefix . '.%');
        }
    }
1326407
public function deleteExpired()
    {
        if ($this->isExpirationEnabled()) {
            $expiredAt = Carbon::now()->subSeconds($this->expires);

            $this->getTable()->where('created_at', '<', $expiredAt)->delete();
        }
    }
1354277
public function cleanup_stale_data()
    {

        logger()->info('Performing stale data maintenance');

        // First cleanup characters.
        CharacterInfo::whereNotIn('character_id', function ($query) {

            $query->select('id')
                ->from((new User)->getTable());

        })->each(function ($character) {

            logger()->info('Cleaning up character: ' . $character->name);
            $character->delete();

        });

        // Next, cleanup corporations
        CorporationInfo::whereNotIn('corporation_id', function ($query) {

            // Filter out corporations that we have characters for.
            $query->select('corporation_id')
                ->from((new CharacterInfo)->getTable())
                ->whereIn('character_id', function ($sub_query) {

                    // Ensure that its characters with roles. Otherwise
                    // the corporation info is meaningless anyways.
                    $sub_query->select('character_id')
                        ->from((new CharacterRole)->getTable());

                });

        })->each(function ($corporation) {

            dump('Cleaning up corporation: ' . $corporation->name);
            logger()->info('Cleaning up corporation: ' . $corporation->name);
            $corporation->delete();

        });
    }
1073943
public function removeExpired() {
		$count = $this->UserTable->removeExpiredRegistrations();
		$this->out(__dn(
			'burzum/user_tools',
			'Removed {0,number,integer} expired registration.',
			'Removed {0,number,integer} expired registrations.',
			$count,
			$count
		));
	}
1311765
public function clearAllData()
    {
        if (!$this->isUsed()) {
            return;
        }

        $this->getConn()->clearAllData();

        // Some DataExtensions keep a static cache of information that needs to
        // be reset whenever the database is cleaned out
        $classes = array_merge(
            ClassInfo::subclassesFor(DataExtension::class),
            ClassInfo::subclassesFor(DataObject::class)
        );
        foreach ($classes as $class) {
            $toCall = array($class, 'on_db_reset');
            if (is_callable($toCall)) {
                call_user_func($toCall);
            }
        }
    }
807968
protected function cleanupTempTables()
    {
        $dbHandle = $this->getDatabase()->getDatabaseConnection();

        $query = 'TRUNCATE ' . Database::TABLE_TMP_DEPENDS_NEEDED;
        $dbHandle->query($query);
    }
1338383
public function deleteExpired()
    {
        $cache = $this->loadCache();
        if (is_array($cache)) {
            $i = 0;
            $cache = array_map(function ($value) use (& $i) {
                if (!$this->isExpired($value['time'], $value['expire'])) {
                    ++$i;
                    return $value;
                }
            }, $cache);
            if ($i > 0) {
                $this->saveCache($cache);
            }
        }
        return $this;
    }