-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit f6336a5
Showing
24 changed files
with
1,575 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
/vendor/ | ||
composer.lock | ||
*.sublime-project |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
|
||
language: php | ||
php: | ||
- 5.3 | ||
- 5.4 | ||
- 5.5 | ||
- 5.6 | ||
- 7.0 | ||
- 7.1 | ||
|
||
script: | ||
- vendor/bin/tester tests -s -p php | ||
- php temp/code-checker/src/code-checker.php | ||
|
||
after_failure: | ||
# Print *.actual content | ||
- for i in $(find tests -name \*.actual); do echo "--- $i"; cat $i; echo; echo; done | ||
|
||
before_script: | ||
# Install Nette Tester | ||
- travis_retry composer install --no-interaction --prefer-dist | ||
- travis_retry composer create-project nette/code-checker temp/code-checker ~2.5.0 | ||
|
||
sudo: false | ||
|
||
cache: | ||
directories: | ||
- $HOME/.composer/cache |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
tester = vendor/bin/tester | ||
tests_dir = tests/ | ||
coverage_name = $(tests_dir)coverage.html | ||
php_ini = $(tests_dir)php-unix.ini | ||
php_bin = php | ||
|
||
.PHONY: test coverage clean | ||
test: | ||
@$(tester) -p $(php_bin) -c $(php_ini) $(tests_dir) | ||
|
||
coverage: | ||
@$(tester) -p $(php_bin) -c $(php_ini) --coverage $(coverage_name) --coverage-src src/ $(tests_dir) | ||
|
||
clean: | ||
@rm -f $(coverage_name) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{ | ||
"name": "czproject/sql-schema", | ||
"type": "library", | ||
"description": "Library for describe of the database schema.", | ||
"license": "BSD-3-Clause", | ||
"authors": [ | ||
{ | ||
"name": "Jan Pecha", | ||
"homepage": "https://www.janpecha.cz/" | ||
} | ||
], | ||
"require": { | ||
"php": ">=5.3.0" | ||
}, | ||
"autoload": { | ||
"classmap": ["src/"] | ||
}, | ||
"require-dev": { | ||
"nette/tester": "^1.7" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
New BSD License | ||
--------------- | ||
|
||
Copyright © 2017 Jan Pecha (https://www.janpecha.cz/) All rights reserved. | ||
|
||
Redistribution and use in source and binary forms, with or without modification, | ||
are permitted provided that the following conditions are met: | ||
* Redistributions of source code must retain the above copyright notice, this | ||
list of conditions and the following disclaimer. | ||
* Redistributions in binary form must reproduce the above copyright notice, this | ||
list of conditions and the following disclaimer in the documentation and/or | ||
other materials provided with the distribution. | ||
* Neither the name of “CzProject“ nor the names of its contributors may be used to | ||
endorse or promote products derived from this software without specific prior | ||
written permission. | ||
|
||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND | ||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR | ||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON | ||
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
|
||
# CzProject\SqlSchema | ||
|
||
Library for describe of the database schema. | ||
|
||
|
||
## Installation | ||
|
||
[Download a latest package](https://github.com/czproject/sql-schema/releases) or use [Composer](http://getcomposer.org/): | ||
|
||
``` | ||
composer require czproject/sql-schema | ||
``` | ||
|
||
CzProject\SqlSchema requires PHP 5.3.0 or later. | ||
|
||
|
||
## Usage | ||
|
||
``` php | ||
use CzProject\SqlSchema\Index; | ||
$schema = new CzProject\SqlSchema\Schema; | ||
|
||
$table = $schema->addTable('book'); | ||
$table->addColumn('id', 'INT', NULL, array('UNSIGNED')); | ||
$table->addColumn('name', 'VARCHAR', array(200)); | ||
$table->addColumn('author_id', 'INT', NULL, array('UNSIGNED')); | ||
$table->addIndex(NULL, Index::TYPE_PRIMARY, 'id'); | ||
$table->addIndex('name_author_id', Index::TYPE_UNIQUE, array('name', 'author_id')); | ||
|
||
$schema->getTables(); | ||
``` | ||
|
||
------------------------------ | ||
|
||
License: [New BSD License](license.md) | ||
<br>Author: Jan Pecha, https://www.janpecha.cz/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,228 @@ | ||
<?php | ||
|
||
namespace CzProject\SqlSchema; | ||
|
||
|
||
class Column | ||
{ | ||
const OPTION_UNSIGNED = 'UNSIGNED'; | ||
const OPTION_ZEROFILL = 'ZEROFILL'; | ||
const OPTION_BINARY = 'BINARY'; | ||
|
||
/** @var string */ | ||
private $name; | ||
|
||
/** @var string */ | ||
private $type; | ||
|
||
/** @var array */ | ||
private $parameters = array(); | ||
|
||
/** @var array */ | ||
private $options = array(); | ||
|
||
/** @var bool */ | ||
private $nullable = FALSE; | ||
|
||
/** @var bool */ | ||
private $autoIncrement = FALSE; | ||
|
||
/** @var scalar|NULL */ | ||
private $defaultValue; | ||
|
||
/** @var string|NULL */ | ||
private $comment; | ||
|
||
|
||
/** | ||
* @param string | ||
* @param string|NULL | ||
* @param array|string|NULL | ||
* @param array [OPTION => VALUE, OPTION2] | ||
*/ | ||
public function __construct($name, $type, array $parameters = NULL, array $options = array()) | ||
{ | ||
$this->name = $name; | ||
$this->setType($type); | ||
$this->setParameters($parameters); | ||
$this->setOptions($options); | ||
} | ||
|
||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getName() | ||
{ | ||
return $this->name; | ||
} | ||
|
||
|
||
/** | ||
* @param string | ||
* @return self | ||
*/ | ||
public function setType($type) | ||
{ | ||
$this->type = $type; | ||
return $this; | ||
} | ||
|
||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getType() | ||
{ | ||
return $this->type; | ||
} | ||
|
||
|
||
/** | ||
* @param string|array|NULL | ||
* @return self | ||
*/ | ||
public function setParameters($parameters) | ||
{ | ||
if ($parameters === NULL) { | ||
$parameters = array(); | ||
|
||
} elseif (!is_array($parameters)) { | ||
$parameters = array($parameters); | ||
} | ||
|
||
$this->parameters = $parameters; | ||
return $this; | ||
} | ||
|
||
|
||
/** | ||
* @return array | ||
*/ | ||
public function getParameters() | ||
{ | ||
return $this->parameters; | ||
} | ||
|
||
|
||
/** | ||
* @param string | ||
* @param scalar|NULL | ||
* @return self | ||
*/ | ||
public function addOption($option, $value = NULL) | ||
{ | ||
$this->options[$option] = $value; | ||
return $this; | ||
} | ||
|
||
|
||
/** | ||
* @param array | ||
* @return self | ||
*/ | ||
public function setOptions(array $options) | ||
{ | ||
$this->options = array(); | ||
|
||
foreach ($options as $k => $v) { | ||
if (is_int($k)) { | ||
$this->options[$v] = NULL; | ||
|
||
} else { | ||
$this->options[$k] = $v; | ||
} | ||
} | ||
|
||
return $this; | ||
} | ||
|
||
|
||
/** | ||
* @return array | ||
*/ | ||
public function getOptions() | ||
{ | ||
return $this->options; | ||
} | ||
|
||
|
||
/** | ||
* @param bool | ||
* @return self | ||
*/ | ||
public function setNullable($nullable = TRUE) | ||
{ | ||
$this->nullable = $nullable; | ||
return $this; | ||
} | ||
|
||
|
||
/** | ||
* @return bool | ||
*/ | ||
public function isNullable() | ||
{ | ||
return $this->nullable; | ||
} | ||
|
||
|
||
/** | ||
* @param bool | ||
* @return self | ||
*/ | ||
public function setAutoIncrement($autoIncrement = TRUE) | ||
{ | ||
$this->autoIncrement = $autoIncrement; | ||
return $this; | ||
} | ||
|
||
|
||
/** | ||
* @return bool | ||
*/ | ||
public function isAutoIncrement() | ||
{ | ||
return $this->autoIncrement; | ||
} | ||
|
||
|
||
/** | ||
* @param scalar|NULL | ||
* @return self | ||
*/ | ||
public function setDefaultValue($defaultValue) | ||
{ | ||
$this->defaultValue = $defaultValue; | ||
return $this; | ||
} | ||
|
||
|
||
/** | ||
* @return scalar|NULL | ||
*/ | ||
public function getDefaultValue() | ||
{ | ||
return $this->defaultValue; | ||
} | ||
|
||
|
||
/** | ||
* @param string|NULL | ||
* @return self | ||
*/ | ||
public function setComment($comment) | ||
{ | ||
$this->comment = $comment; | ||
return $this; | ||
} | ||
|
||
|
||
/** | ||
* @return string|NULL | ||
*/ | ||
public function getComment() | ||
{ | ||
return $this->comment; | ||
} | ||
} |
Oops, something went wrong.