You are here

protected function Database::sqlType in Search API 8

Returns the schema definition for a database column for a search data type.

Parameters

string $type: An indexed field's search type. One of the default data types.

Return value

array Column configurations to use for the field's database column.

Throws

\Drupal\search_api\SearchApiException Thrown if $type is unknown.

2 calls to Database::sqlType()
Database::createFieldTable in modules/search_api_db/src/Plugin/search_api/backend/Database.php
Creates or modifies a table to add an indexed field.
Database::fieldsUpdated in modules/search_api_db/src/Plugin/search_api/backend/Database.php
Updates the storage tables when the field configuration changes.

File

modules/search_api_db/src/Plugin/search_api/backend/Database.php, line 894

Class

Database
Indexes and searches items using the database.

Namespace

Drupal\search_api_db\Plugin\search_api\backend

Code

protected function sqlType($type) {
  switch ($type) {
    case 'text':
      return [
        'type' => 'varchar',
        'length' => 30,
      ];
    case 'string':
    case 'uri':
      return [
        'type' => 'varchar',
        'length' => 255,
      ];
    case 'integer':
    case 'duration':
    case 'date':

      // 'datetime' sucks. Therefore, we just store the timestamp.
      return [
        'type' => 'int',
        'size' => 'big',
      ];
    case 'decimal':
      return [
        'type' => 'float',
      ];
    case 'boolean':
      return [
        'type' => 'int',
        'size' => 'tiny',
      ];
    default:
      throw new SearchApiException("Unknown field type '{$type}'.");
  }
}