You are here

function data_build_schema in Data 8

Same name and namespace in other branches
  1. 6 data.module \data_build_schema()
  2. 7 data.module \data_build_schema()

Helper function to generate a schema.

Example: $table->create(data_build_schema($keys));

@todo: check for table name collisions @todo: add type detection @todo: add meta info handling @todo: add primary key handling @todo: may be add option to add a full fledged schema here?

File

./data.module, line 253
Hooks and API functions for data module.

Code

function data_build_schema($keys) {

  // Build the table definition.
  // Fall back to varchar if no valid type is given.
  $fields = $schema = array();
  foreach ($keys as $k => $key) {
    if ($definition = data_get_field_definition($key)) {
      $fields[data_safe_name($k)] = $definition;
    }
    else {
      $fields[data_safe_name($k)] = data_get_field_definition('varchar');
    }
  }
  $schema['fields'] = $fields;
  $schema['indexes'] = array();
  return $schema;
}