Download the PHP package pinkcrab/table_builder without Composer
On this page you can find all versions of the php package pinkcrab/table_builder. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download pinkcrab/table_builder
More information about pinkcrab/table_builder
Files in pinkcrab/table_builder
Package table_builder
Short Description Used to define a tables schema and to create the table in most SQL database.
License MIT
Homepage https://pinkcrab.co.uk
Informations about the package table_builder
Table-Builder
A chainable table schema constructor with (WPDB) DB Delta builder built in.
Related Pages
» Schema
» Column
» Index
» Foreign_Key
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
Defining a Table's Schema
You can define a table's schema in a few different ways.
See Schema Docs
Columns
The schema is defined from various columns, each column is defined as its own object with a collection of helper/shortcuts
Indexes and Foreign Keys
You can setup a variety of indexes and foreign keys for your table(s). These can be set as in the schema example above.
Index
You can create an index for any column of your table and denote the field as either unique, primary, full text, hash, or just a regular index.
The above would generate:
If you wish to use more than 1 column for an index, please add them as single indexes and the builder will combine. You must also set a custom keyname for all grouped indexes.
The above would generate the following for MySQL:
See INDEX docs
Foreign Key
Like regular indexes, foreign keys can be assigned to a table. When the table is built, it will assume the reference table exists, so ensure that you create them in the correct order if you are creating all tables at once.
The above would produce for MySQL (provided the user table exists with an ID column):
See Foreign Key docs
Creating & Dropping Tables
You can populate the builder with any engine. Included in this package is the DB_Delta_Engine
engine, which internally uses the WordPress dbDelta
function to create and drop tables.
Create
Drop
License
MIT License
http://www.opensource.org/licenses/mit-license.html
Change Log
- 1.2.0 - Added in helper method for unsigned_big() (thanks iniznet), updated dev deps and GH pipelines.
- 1.1.0 - Added JSON column support, fixed precision issue with floating point column, improved docs (with help from ZebulanStanphill)
- 1.0.0 - Added 2 new methods to the engine interface and wpdb implementation to return the queries used to create table and drop table.
- 0.3.0 - Changed how much of the API works; some of the externals have changed. It no longer accepts fully fluent creation, and index/foreign keys have been separated.
- 0.2.2 - No change, branches a mess.
- 0.2.1 - Added in more tests, now has 100% test coverage. Added in more valdation around columns, tablename and indexes. Previously threw PHP errors for missing or malformed data. Now throws exceptions if Table has no name, a column is lacking key, null, type or length and all indexes which are foreign keys, must have a valid reference table and column. No changes to public methods.
- 0.2.0 - Moved to Composer, renamed all namespaces to match the Composer format.
Contributions
If you would like to contribute to this project, please feel to create an issue, then submit a PR.