SQLiteProcessor.php
TLDR
The SQLiteProcessor.php
file is a part of the Illuminate\Database\Query\Processors namespace. It contains a class called SQLiteProcessor
that extends the Processor
class. This file contains methods to process the results of various database queries related to SQLite.
Methods
processColumnListing
This method processes the results of a column listing query. It takes an array of results and returns an array with the names of the columns.
processColumns
This method processes the results of a columns query. It takes an array of results and returns an array with information about each column, such as name, type, nullable, default value, etc.
processIndexes
This method processes the results of an indexes query. It takes an array of results and returns an array with information about each index, such as name, columns, type, uniqueness, etc.
processForeignKeys
This method processes the results of a foreign keys query. It takes an array of results and returns an array with information about each foreign key, such as columns, foreign table, foreign columns, on update, on delete actions, etc.
<?php
namespace Illuminate\Database\Query\Processors;
class SQLiteProcessor extends Processor
{
/**
* Process the results of a column listing query.
*
* @deprecated Will be removed in a future Laravel version.
*
* @param array $results
* @return array
*/
public function processColumnListing($results)
{
return array_map(function ($result) {
return ((object) $result)->name;
}, $results);
}
/**
* Process the results of a columns query.
*
* @param array $results
* @return array
*/
public function processColumns($results)
{
$hasPrimaryKey = array_sum(array_column($results, 'primary')) === 1;
return array_map(function ($result) use ($hasPrimaryKey) {
$result = (object) $result;
$type = strtolower($result->type);
return [
'name' => $result->name,
'type_name' => strtok($type, '(') ?: '',
'type' => $type,
'collation' => null,
'nullable' => (bool) $result->nullable,
'default' => $result->default,
'auto_increment' => $hasPrimaryKey && $result->primary && $type === 'integer',
'comment' => null,
];
}, $results);
}
/**
* Process the results of an indexes query.
*
* @param array $results
* @return array
*/
public function processIndexes($results)
{
$primaryCount = 0;
$indexes = array_map(function ($result) use (&$primaryCount) {
$result = (object) $result;
if ($isPrimary = (bool) $result->primary) {
$primaryCount += 1;
}
return [
'name' => strtolower($result->name),
'columns' => explode(',', $result->columns),
'type' => null,
'unique' => (bool) $result->unique,
'primary' => $isPrimary,
];
}, $results);
if ($primaryCount > 1) {
$indexes = array_filter($indexes, fn ($index) => $index['name'] !== 'primary');
}
return $indexes;
}
/**
* Process the results of a foreign keys query.
*
* @param array $results
* @return array
*/
public function processForeignKeys($results)
{
return array_map(function ($result) {
$result = (object) $result;
return [
'name' => null,
'columns' => explode(',', $result->columns),
'foreign_schema' => null,
'foreign_table' => $result->foreign_table,
'foreign_columns' => explode(',', $result->foreign_columns),
'on_update' => strtolower($result->on_update),
'on_delete' => strtolower($result->on_delete),
];
}, $results);
}
}