Skip to content

Commit db7d84d

Browse files
authored
Merge pull request #5505 from kenjis/fix-docs-dbmgmt/forge.rst
docs: improve dbmgmt/forge.rst
2 parents 7807496 + 5876539 commit db7d84d

1 file changed

Lines changed: 30 additions & 32 deletions

File tree

user_guide_src/source/dbmgmt/forge.rst

Lines changed: 30 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Initializing the Forge Class
1313
****************************
1414

1515
.. important:: In order to initialize the Forge class, your database
16-
driver must already be running, since the forge class relies on it.
16+
driver must already be running, since the Forge class relies on it.
1717

1818
Load the Forge Class as follows::
1919

@@ -40,7 +40,7 @@ Returns true/false based on success or failure::
4040
echo 'Database created!';
4141
}
4242

43-
An optional second parameter set to true will add IF EXISTS statement
43+
An optional second parameter set to true will add ``IF EXISTS`` statement
4444
or will check if a database exists before create it (depending on DBMS).
4545

4646
::
@@ -91,13 +91,13 @@ There are several things you may wish to do when creating tables. Add
9191
fields, add keys to the table, alter columns. CodeIgniter provides a
9292
mechanism for this.
9393

94-
Adding fields
94+
Adding Fields
9595
=============
9696

9797
Fields are normally created via an associative array. Within the array, you must
98-
include a 'type' key that relates to the datatype of the field. For
98+
include a ``type`` key that relates to the datatype of the field. For
9999
example, INT, VARCHAR, TEXT, etc. Many datatypes (for example VARCHAR)
100-
also require a 'constraint' key.
100+
also require a ``constraint`` key.
101101

102102
::
103103

@@ -111,14 +111,14 @@ also require a 'constraint' key.
111111

112112
Additionally, the following key/values can be used:
113113

114-
- unsigned/true : to generate "UNSIGNED" in the field definition.
115-
- default/value : to generate a default value in the field definition.
116-
- null/true : to generate "null" in the field definition. Without this,
114+
- ``unsigned``/true : to generate "UNSIGNED" in the field definition.
115+
- ``default``/value : to generate a default value in the field definition.
116+
- ``null``/true : to generate "null" in the field definition. Without this,
117117
the field will default to "NOT null".
118-
- auto_increment/true : generates an auto_increment flag on the
118+
- ``auto_increment``/true : generates an auto_increment flag on the
119119
field. Note that the field type must be a type that supports this,
120120
such as integer.
121-
- unique/true : to generate a unique key for the field definition.
121+
- ``unique``/true : to generate a unique key for the field definition.
122122

123123
::
124124

@@ -151,7 +151,7 @@ Additionally, the following key/values can be used:
151151
];
152152

153153
After the fields have been defined, they can be added using
154-
``$forge->addField($fields);`` followed by a call to the
154+
``$forge->addField($fields)`` followed by a call to the
155155
``createTable()`` method.
156156

157157
**$forge->addField()**
@@ -162,15 +162,13 @@ Passing strings as fields
162162
-------------------------
163163

164164
If you know exactly how you want a field to be created, you can pass the
165-
string into the field definitions with addField()
166-
167-
::
165+
string into the field definitions with ``addField()``::
168166

169167
$forge->addField("label varchar(100) NOT NULL DEFAULT 'default label'");
170168

171169
.. note:: Passing raw strings as fields cannot be followed by ``addKey()`` calls on those fields.
172170

173-
.. note:: Multiple calls to addField() are cumulative.
171+
.. note:: Multiple calls to ``addField()`` are cumulative.
174172

175173
Creating an id field
176174
--------------------
@@ -188,10 +186,10 @@ Adding Keys
188186
===========
189187

190188
Generally speaking, you'll want your table to have Keys. This is
191-
accomplished with $forge->addKey('field'). The optional second
189+
accomplished with ``$forge->addKey('field')``. The optional second
192190
parameter set to true will make it a primary key and the third
193-
parameter set to true will make it a unique key. Note that addKey()
194-
must be followed by a call to createTable().
191+
parameter set to true will make it a unique key. Note that ``addKey()``
192+
must be followed by a call to ``createTable()``.
195193

196194
Multiple column non-primary keys must be sent as an array. Sample output
197195
below is for MySQL.
@@ -245,7 +243,7 @@ You can specify the desired action for the "on delete" and "on update" propertie
245243
$forge->addForeignKey(['users_id', 'users_name'], 'users', ['id', 'name'], 'CASCADE', 'CASCADE');
246244
// gives CONSTRAINT `TABLENAME_users_foreign` FOREIGN KEY(`users_id`, `users_name`) REFERENCES `users`(`id`, `name`) ON DELETE CASCADE ON UPDATE CASCADE
247245

248-
Creating a table
246+
Creating a Table
249247
================
250248

251249
After fields and keys have been declared, you can create a new table
@@ -256,7 +254,7 @@ with
256254
$forge->createTable('table_name');
257255
// gives CREATE TABLE table_name
258256

259-
An optional second parameter set to true adds an "IF NOT EXISTS" clause
257+
An optional second parameter set to true adds an ``IF NOT EXISTS`` clause
260258
into the definition
261259

262260
::
@@ -274,10 +272,10 @@ You could also pass optional table attributes, such as MySQL's ``ENGINE``::
274272
``createTable()`` will always add them with your configured *charset*
275273
and *DBCollat* values, as long as they are not empty (MySQL only).
276274

277-
Dropping a table
275+
Dropping a Table
278276
================
279277

280-
Execute a DROP TABLE statement and optionally add an IF EXISTS clause.
278+
Execute a ``DROP TABLE`` statement and optionally add an ``IF EXISTS`` clause.
281279

282280
::
283281

@@ -287,7 +285,7 @@ Execute a DROP TABLE statement and optionally add an IF EXISTS clause.
287285
// Produces: DROP TABLE IF EXISTS `table_name`
288286
$forge->dropTable('table_name', true);
289287

290-
A third parameter can be passed to add a "CASCADE" option, which might be required for some
288+
A third parameter can be passed to add a ``CASCADE`` option, which might be required for some
291289
drivers to handle removal of tables with foreign keys.
292290

293291
::
@@ -316,7 +314,7 @@ Execute a DROP KEY.
316314
// Produces: DROP INDEX `users_index` ON `tablename`
317315
$forge->dropKey('tablename', 'users_index');
318316

319-
Renaming a table
317+
Renaming a Table
320318
================
321319

322320
Executes a TABLE rename
@@ -348,7 +346,7 @@ number of additional fields.
348346
// Executes: ALTER TABLE `table_name` ADD `preferences` TEXT
349347

350348
If you are using MySQL or CUBIRD, then you can take advantage of their
351-
AFTER and FIRST clauses to position the new column.
349+
``AFTER`` and ``FIRST`` clauses to position the new column.
352350

353351
Examples::
354352

@@ -421,7 +419,7 @@ Class Reference
421419
:returns: \CodeIgniter\Database\Forge instance (method chaining)
422420
:rtype: \CodeIgniter\Database\Forge
423421

424-
Adds a field to the set that will be used to create a table. Usage: See `Adding fields`_.
422+
Adds a field to the set that will be used to create a table. Usage: See `Adding Fields`_.
425423

426424
.. php:method:: addForeignKey($fieldName, $tableName, $tableField[, $onUpdate = '', $onDelete = ''])
427425
@@ -464,7 +462,7 @@ Class Reference
464462
.. php:method:: createDatabase($dbName[, $ifNotExists = false])
465463
466464
:param string $db_name: Name of the database to create
467-
:param string $ifNotExists: Set to true to add an 'IF NOT EXISTS' clause or check if database exists
465+
:param string $ifNotExists: Set to true to add an ``IF NOT EXISTS`` clause or check if database exists
468466
:returns: true on success, false on failure
469467
:rtype: bool
470468

@@ -473,12 +471,12 @@ Class Reference
473471
.. php:method:: createTable($table[, $if_not_exists = false[, array $attributes = []]])
474472
475473
:param string $table: Name of the table to create
476-
:param string $if_not_exists: Set to true to add an 'IF NOT EXISTS' clause
474+
:param string $if_not_exists: Set to true to add an ``IF NOT EXISTS`` clause
477475
:param string $attributes: An associative array of table attributes
478476
:returns: Query object on success, false on failure
479477
:rtype: mixed
480478

481-
Creates a new table. Usage: See `Creating a table`_.
479+
Creates a new table. Usage: See `Creating a Table`_.
482480

483481
.. php:method:: dropColumn($table, $column_name)
484482
@@ -500,11 +498,11 @@ Class Reference
500498
.. php:method:: dropTable($table_name[, $if_exists = false])
501499
502500
:param string $table: Name of the table to drop
503-
:param string $if_exists: Set to true to add an 'IF EXISTS' clause
501+
:param string $if_exists: Set to true to add an ``IF EXISTS`` clause
504502
:returns: true on success, false on failure
505503
:rtype: bool
506504

507-
Drops a table. Usage: See `Dropping a table`_.
505+
Drops a table. Usage: See `Dropping a Table`_.
508506

509507
.. php:method:: modifyColumn($table, $field)
510508
@@ -522,4 +520,4 @@ Class Reference
522520
:returns: Query object on success, false on failure
523521
:rtype: mixed
524522

525-
Renames a table. Usage: See `Renaming a table`_.
523+
Renames a table. Usage: See `Renaming a Table`_.

0 commit comments

Comments
 (0)