-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdbtng_example.install
94 lines (89 loc) · 1.98 KB
/
dbtng_example.install
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
<?php
/**
* @file
* Install, update and uninstall functions for the dbtng_example module.
*/
/**
* Implements hook_install().
*
* Creates some default entries on this module custom table.
*
* @see hook_install()
*
* @ingroup dbtng_example
*/
function dbtng_example_install() {
// Insert some example data into our schema.
$entries = [
[
'name' => 'John',
'surname' => 'Doe',
'age' => 0,
],
[
'name' => 'John',
'surname' => 'Roe',
'age' => 100,
'uid' => 1,
],
];
$connection = \Drupal::database();
foreach ($entries as $entry) {
$connection->insert('dbtng_example')->fields($entry)->execute();
}
}
/**
* Implements hook_schema().
*
* Defines the database tables used by this module.
*
* @see hook_schema()
*
* @ingroup dbtng_example
*/
function dbtng_example_schema() {
$schema['dbtng_example'] = [
'description' => 'Stores example person entries for demonstration purposes.',
'fields' => [
'pid' => [
'type' => 'serial',
'not null' => TRUE,
'description' => 'Primary Key: Unique person ID.',
],
'uid' => [
'type' => 'int',
'not null' => TRUE,
'default' => 0,
'description' => "Creator user's {users}.uid",
],
'name' => [
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
'description' => 'Name of the person.',
],
'surname' => [
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
'description' => 'Surname of the person.',
],
'age' => [
'type' => 'int',
'not null' => TRUE,
'default' => 0,
'size' => 'tiny',
'description' => 'The age of the person in years.',
],
],
'primary key' => ['pid'],
'indexes' => [
'name' => ['name'],
'surname' => ['surname'],
'age' => ['age'],
],
];
return $schema;
}