zrnik/mksql

MkSQL is a tool for keeping your tables up to date with PHP code. You can use it in your project or as a database preparation in your integration tests.

v0.7 2021-04-16 08:32 UTC

This package is auto-updated.

Last update: 2021-04-16 08:54:58 UTC


README

GitHub Packagist Downloads Packagist Version

MkSQL is a tool for keeping your tables up to date with PHP code. You can use it in your project or as a database preparation in your integration tests.

It's a good tool for prototyping, so you can just change your code instead of fiddling with Adminer (or PHPMyAdmin). I would not use it in production to save precious resources on runtime. Better way is creating a standalone script to run table update once when you upgrade and/or install your application.

Documentation index is in docs/index.md

Requirements

{
    "PHP": ">= 7.4",
    "ext-pdo": "*",

    "nette/utils": "^3.0",
    "ext-iconv": "*",
    "ext-intl": "*",

    "zrnik/enum": "^1"
}

Installation

composer require zrny/mksql

Supported Drivers:

Supported Features:

This library only supports basic features for creating the tables.

Column:
  • Name
  • Type
  • NULL / NOT NULL
  • DEFAULT
  • COMMENT (Not in SQLite)
  • UNIQUE INDEX
  • FOREIGN KEY
Table:

Usage:

Example:

use \Zrnik\MkSQL\Updater;

$pdo = new PDO("sqlite::memory:");
$updater = new Updater($pdo);

// Articles:
$articles = $updater->tableCreate("articles");

$articles->columnCreate("title","varchar(255)");

$articles->columnCreate("url_slug","varchar(255)")
    ->setNotNull()->setUnique();

$articles->columnCreate("content","longtext");

$articles->columnCreate("display_count","longtext")
    ->setNotNull()->setDefault(0);

// Comments:
$comments = $updater->tableCreate("comments");

$comments->columnCreate("author_name");

$comments->columnCreate("author_email");

$comments->columnCreate("article")
    ->addForeignKey("articles.id");

$comments->columnCreate("comment_text");

//Then we install it:
$updater->install();

For all the possible examples see docs/usage.md.

Tracy Panel

Add this to your bootstrap file:

use \Zrnik\MkSQL\Tracy\Panel;
Tracy\Debugger::getBar()->addPanel(new Panel());

Or, if you are using Nette Framework, register it in your configuration file:

tracy: 
    bar: 
        - Zrnik\MkSQL\Tracy\Panel