This project is not covered by Drupal’s security advisory policy.

Data module helps you model, manage and query related sets of tables. It offers an administration interface and a low level API for manipulating tables and accessing their contents. Data module provides Views integration for displaying table data and Drupal search integration for searching table content.

You can use Feeds to import RSS, Atom, CSV or OPML files into data tables.

The Data module provides

  • an API for dynamically allocating tables for single-row records.
  • an API for insert/update/delete operations and describing how tables join to each other.
  • automatic views integration.
  • a way to export table definitions to code.

The included Data UI module provides

  • UI to add new database tables.
  • UI to add or alter columns to existing tables managed by Data module.
  • UI to define joins between tables.
  • UI to solve conflicts between table in database and schema information.
  • default views for tables managed by Data module.
  • UI to add existing tables that are unclaimed by other modules to Data's table management.

Further, you can:

  • Search specific table fields with the included Data Search module (6.x only; see #1744510: Port Data Search to D7 for 7.x)
  • Relate table records to nodes with the included Data Node module (6.x only)
  • Declare a table to be an entity type, and its records to be entities. This allows FieldAPI fields to be added to the table, and entity references to be made (7.x only)

You may want to

API

(to give an example, not complete)

7.x

// Get a table.
$table = data_get_table('my_table');

// If this table is not available create a table.
if (!$table) {
  $table = data_create_table('my_table', $schema).
}

// Save some data to it.
$table->handler()->save($data);

// Add a field to it.
$table->addField('newfield', $spec);

// Add an index to it.
$table->addIndex('newfield');

// Remove all data from the table.
$table->handler()->truncate();

// Destroy the table.
$table->drop();

8.x

(Most of examples from 7.x. will work in 8.x as well)

// Table configuration is now a configuration entity, use
// Drupal EntityTypeManager to create/drop tables.
$storage = \Drupal::entityTypeManager()->getStorage('data_table_config');

$table = $storage->load('my_table');

if (!$table) {
  $table = $storage->create(array(
    'id' => 'my_table',
    'description' => 'Short table description',
    'table_schema' => array(
      array(
        'name' => 'fld1',
        'type' => 'serial',
        'primary' => TRUE,
      ),
      array(
        'name' => 'label',
        'type' => 'varchar',
        'length' => 100,
      )
    ),
  ));

  $table->save();
}

// Destroy the table.
$storage->delete('my_table')

// Data rows are managed using data.row_manager service
$manager = \Drupal::getContainer()->get('data.row_manager');

$manager->save($row_data);

// Remove all data from the table.
$manager->truncate();

Project information

Releases