public static function delete($query)
    {
        static::applySchema();

        $key = static::getPrimaryKeyOrMainField();

        if ($key && !is_array($query)) {
            $query = [$key => $query];
        }

        $whereArray = [];
        if (isset($query['where'])) {
            $whereArray[] = $query['where'];
            unset($query['where']);
        }

        $params = [];

        foreach ($query as $field => $value) {
            $token = ':'.$field;
            $whereArray[] = "`{$field}` = {$token}";
            $params[$token] = $value;
        }

        $where = $whereArray
               ? 'WHERE '.implode(' AND ', $whereArray)
               : '';

        $table = static::getTable();
        $sql = "DELETE FROM {$table} {$where}";

        static::getDatabase()->execute($sql, $params);
    }