PHPackages                             pinkcrab/table\_builder - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. pinkcrab/table\_builder

ActiveLibrary[Database &amp; ORM](/categories/database)

pinkcrab/table\_builder
=======================

Used to define a tables schema and to create the table in most SQL database.

1.2.1(1mo ago)213.2k↓68.8%21MITPHPPHP &gt;=8.0.0CI passing

Since Jan 18Pushed 1mo ago1 watchersCompare

[ Source](https://github.com/Pink-Crab/WPDB-Table-Builder)[ Packagist](https://packagist.org/packages/pinkcrab/table_builder)[ Docs](https://pinkcrab.co.uk)[ RSS](/packages/pinkcrab-table-builder/feed)WikiDiscussions master Synced 1w ago

READMEChangelog (9)Dependencies (24)Versions (23)Used By (1)

Table-Builder
=============

[](#table-builder)

A chainable table schema constructor with (WPDB) DB Delta builder built in.

[![Latest Stable Version](https://camo.githubusercontent.com/6ea0582e323cef78fcabb8b37b72b0182e48cc015933222b1b6b6939bef389d3/687474703a2f2f706f7365722e707567782e6f72672f70696e6b637261622f7461626c655f6275696c6465722f76)](https://packagist.org/packages/pinkcrab/table_builder) [![Total Downloads](https://camo.githubusercontent.com/aafa5bdf0c7e4af6be69cdf06059561f271b2d96877e2de25d1e92a68e5bf27f/687474703a2f2f706f7365722e707567782e6f72672f70696e6b637261622f7461626c655f6275696c6465722f646f776e6c6f616473)](https://packagist.org/packages/pinkcrab/table_builder) [![Latest Unstable Version](https://camo.githubusercontent.com/e3727ebb4d9fa5c1d231f8dff450e129fef8dffc7995d7cd77b1b9a2ae15b73b/687474703a2f2f706f7365722e707567782e6f72672f70696e6b637261622f7461626c655f6275696c6465722f762f756e737461626c65)](https://packagist.org/packages/pinkcrab/table_builder) [![License](https://camo.githubusercontent.com/55e23b2beec7ea0a981fd6f5e00aaa078b3f6714ab762bae89e8edc206208490/687474703a2f2f706f7365722e707567782e6f72672f70696e6b637261622f7461626c655f6275696c6465722f6c6963656e7365)](https://packagist.org/packages/pinkcrab/table_builder) [![PHP Version Require](https://camo.githubusercontent.com/69bdae3479ad1ddcf2acfd984cb53c5e0e90a6ba1227c628fb9a5e272aca26d1/687474703a2f2f706f7365722e707567782e6f72672f70696e6b637261622f7461626c655f6275696c6465722f726571756972652f706870)](https://packagist.org/packages/pinkcrab/table_builder)[![GitHub contributors](https://camo.githubusercontent.com/ab4e533ff84393fb719af103c3aba9ccd860f002616bca342895cdf9b0cfbe93/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f636f6e7472696275746f72732f50696e6b2d437261622f575044422d5461626c652d4275696c6465723f6c6162656c3d436f6e7472696275746f7273)](https://camo.githubusercontent.com/ab4e533ff84393fb719af103c3aba9ccd860f002616bca342895cdf9b0cfbe93/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f636f6e7472696275746f72732f50696e6b2d437261622f575044422d5461626c652d4275696c6465723f6c6162656c3d436f6e7472696275746f7273)[![GitHub issues](https://camo.githubusercontent.com/929a22bb97c9f368d3af70b7c501e69f9d38741b588ab20e8e7e421480a2d43b/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6973737565732d7261772f50696e6b2d437261622f575044422d5461626c652d4275696c646572)](https://camo.githubusercontent.com/929a22bb97c9f368d3af70b7c501e69f9d38741b588ab20e8e7e421480a2d43b/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6973737565732d7261772f50696e6b2d437261622f575044422d5461626c652d4275696c646572)

[![WP6.6 [PHP8.0-8.4] Tests](https://github.com/Pink-Crab/WPDB-Table-Builder/actions/workflows/WP_6_6.yaml/badge.svg)](https://github.com/Pink-Crab/WPDB-Table-Builder/actions/workflows/WP_6_6.yaml)[![WP6.7 [PHP8.0-8.4] Tests](https://github.com/Pink-Crab/WPDB-Table-Builder/actions/workflows/WP_6_7.yaml/badge.svg)](https://github.com/Pink-Crab/WPDB-Table-Builder/actions/workflows/WP_6_7.yaml)[![WP6.8 [PHP8.0-8.4] Tests](https://github.com/Pink-Crab/WPDB-Table-Builder/actions/workflows/WP_6_8.yaml/badge.svg)](https://github.com/Pink-Crab/WPDB-Table-Builder/actions/workflows/WP_6_8.yaml)[![WP6.9 [PHP8.0-8.4] Tests](https://github.com/Pink-Crab/WPDB-Table-Builder/actions/workflows/WP_6_9.yaml/badge.svg)](https://github.com/Pink-Crab/WPDB-Table-Builder/actions/workflows/WP_6_9.yaml)

[![codecov](https://camo.githubusercontent.com/b8f6b9c684218cb9621c8d31be80aafb4b33438f40598b39087ac55d063410d6/68747470733a2f2f636f6465636f762e696f2f67682f50696e6b2d437261622f575044422d5461626c652d4275696c6465722f6272616e63682f6d61737465722f67726170682f62616467652e7376673f746f6b656e3d5542574c3853344f384c)](https://codecov.io/gh/Pink-Crab/WPDB-Table-Builder)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/46d05db44fe1e5f700c39553d5681bd8a96cc0cf5740b0799605543e346ea13d/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f50696e6b2d437261622f575044422d5461626c652d4275696c6465722f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/Pink-Crab/WPDB-Table-Builder/?branch=master)[![Maintainability](https://camo.githubusercontent.com/9a07f9172e34071edecbc1fe374b38565cd3885c7fc3dc430084de9b4fb18bc6/68747470733a2f2f6170692e636f6465636c696d6174652e636f6d2f76312f6261646765732f31313663616234323335336232306634333636652f6d61696e7461696e6162696c697479)](https://codeclimate.com/github/Pink-Crab/WPDB-Table-Builder/maintainability)

> **Related Pages**
> » [Schema](docs/Schema.md)
> » [Column](docs/Column.md)
> » [Index](docs/Index.md)
> » [Foreign\_Key](docs/Foreign_Key.md)

Why?
----

[](#why)

For those of you who have used `dbDelta` to create tables in WordPress, to say it's a bit fussy is an understatement.

The `PinkCrab\Table_Builder` module makes creating tables much easier by providing a more expressive fluent API to define the schema, which can be passed to the Builder to create the table.

Out of the box, this package comes with the `DB_Delta` builder engine only, but thanks to the `SQL_Builder` interface, engines for other table formats can be created easily.

Install
-------

[](#install)

```
composer require pinkcrab/table_builder
```

Defining a Table's Schema
-------------------------

[](#defining-a-tables-schema)

You can define a table's schema in a few different ways.

```
