Giter Site home page Giter Site logo

mysqlcreatetableutil's Introduction

MysqlCreateTableUtil

2019-07-23 -> 2021-03-05

A tool to create a basic mysql create table statement.

This is part of the universe framework.

Install

Using the planet installer via light-cli

lt install Ling.MysqlCreateTableUtil

Using the uni command.

uni import Ling/MysqlCreateTableUtil

Or just download it and place it where you want otherwise.

Summary

How to use

The following:

$util = MysqlCreateTableUtil::create("user", "mydb");
$util->setEngine('InnoDB');
$util->setDefaultCharset('utf8');
$util->addColumn(PrimaryKeyAutoIncrementedColumn::create()->name("id"));
//$util->addColumn(Column::create()->name("id")->type('int')->typeSize(11)->notNullable()->autoIncrement()->primaryKey());
$util->addColumn(Column::create()->name("user_id")->type('varchar')->typeSize(128)->notNullable()->uniqueIndex());
$util->addColumn(Column::create()->name("password")->type('varchar')->typeSize(64)->notNullable());
$util->addColumn(Column::create()->name("rights")->type('text')->notNullable());
$util->addColumn(Column::create()->name("avatar_url")->type('varchar')->typeSize(512)->notNullable());
$util->addColumn(Column::create()->name("pseudo")->type('varchar')->typeSize(64)->notNullable());
$util->addColumn(Column::create()->name("extra")->type('varchar')->typeSize(64)->notNullable());
$util->addColumn(Column::create()->name("address_id")->type('int')->typeSize(11)->notNullable()
    ->foreignKey("address", "id")->onUpdate("cascade")->onDelete("cascade")
);

a($util->render());

Will produce an output like this:

string(592) "CREATE TABLE IF NOT EXISTS `mydb`.`user` (
`id` INT(11) NOT NULL AUTO_INCREMENT,
`user_id` VARCHAR(128) NOT NULL,
`password` VARCHAR(64) NOT NULL,
`rights` TEXT NOT NULL,
`avatar_url` VARCHAR(512) NOT NULL,
`pseudo` VARCHAR(64) NOT NULL,
`extra` VARCHAR(64) NOT NULL,
`address_id` INT(11) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE INDEX `user_id_UNIQUE` (`user_id` ASC),
INDEX `fk_user_address_idx` (`address_id` ASC),
CONSTRAINT `fk_user_address_idx`
FOREIGN KEY (`address_id`)
REFERENCES `mydb`.`address` (`id`)
ON DELETE CASCADE
ON UPDATE CASCADE
)
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8;"

Note: the created statement is based on my observations of the MysqlWorkBench utility.

History Log

  • 1.0.6 -- 2021-05-31

    • Removing trailing plus in lpi-deps file (to work with Light_PlanetInstaller:2.0.0 api
  • 1.0.5 -- 2021-03-05

    • update README.md, add install alternative
  • 1.0.4 -- 2020-12-08

    • Fix lpi-deps not using natsort.
  • 1.0.3 -- 2020-12-04

    • Add lpi-deps.byml file
  • 1.0.2 -- 2019-07-23

    • fix typo
  • 1.0.1 -- 2019-07-23

    • update docTools documentation
  • 1.0.0 -- 2019-07-23

    • initial commit

mysqlcreatetableutil's People

Contributors

lingtalfi avatar

Stargazers

 avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.