Skip to content

Commit f6336a5

Browse files
committed
init commit
0 parents  commit f6336a5

24 files changed

Lines changed: 1575 additions & 0 deletions

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/vendor/
2+
composer.lock
3+
*.sublime-project

.travis.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
2+
language: php
3+
php:
4+
- 5.3
5+
- 5.4
6+
- 5.5
7+
- 5.6
8+
- 7.0
9+
- 7.1
10+
11+
script:
12+
- vendor/bin/tester tests -s -p php
13+
- php temp/code-checker/src/code-checker.php
14+
15+
after_failure:
16+
# Print *.actual content
17+
- for i in $(find tests -name \*.actual); do echo "--- $i"; cat $i; echo; echo; done
18+
19+
before_script:
20+
# Install Nette Tester
21+
- travis_retry composer install --no-interaction --prefer-dist
22+
- travis_retry composer create-project nette/code-checker temp/code-checker ~2.5.0
23+
24+
sudo: false
25+
26+
cache:
27+
directories:
28+
- $HOME/.composer/cache

Makefile

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
tester = vendor/bin/tester
2+
tests_dir = tests/
3+
coverage_name = $(tests_dir)coverage.html
4+
php_ini = $(tests_dir)php-unix.ini
5+
php_bin = php
6+
7+
.PHONY: test coverage clean
8+
test:
9+
@$(tester) -p $(php_bin) -c $(php_ini) $(tests_dir)
10+
11+
coverage:
12+
@$(tester) -p $(php_bin) -c $(php_ini) --coverage $(coverage_name) --coverage-src src/ $(tests_dir)
13+
14+
clean:
15+
@rm -f $(coverage_name)

composer.json

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"name": "czproject/sql-schema",
3+
"type": "library",
4+
"description": "Library for describe of the database schema.",
5+
"license": "BSD-3-Clause",
6+
"authors": [
7+
{
8+
"name": "Jan Pecha",
9+
"homepage": "https://www.janpecha.cz/"
10+
}
11+
],
12+
"require": {
13+
"php": ">=5.3.0"
14+
},
15+
"autoload": {
16+
"classmap": ["src/"]
17+
},
18+
"require-dev": {
19+
"nette/tester": "^1.7"
20+
}
21+
}

license.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
New BSD License
2+
---------------
3+
4+
Copyright © 2017 Jan Pecha (https://www.janpecha.cz/) All rights reserved.
5+
6+
Redistribution and use in source and binary forms, with or without modification,
7+
are permitted provided that the following conditions are met:
8+
* Redistributions of source code must retain the above copyright notice, this
9+
list of conditions and the following disclaimer.
10+
* Redistributions in binary form must reproduce the above copyright notice, this
11+
list of conditions and the following disclaimer in the documentation and/or
12+
other materials provided with the distribution.
13+
* Neither the name of “CzProject“ nor the names of its contributors may be used to
14+
endorse or promote products derived from this software without specific prior
15+
written permission.
16+
17+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND
18+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
21+
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
24+
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

readme.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
2+
# CzProject\SqlSchema
3+
4+
Library for describe of the database schema.
5+
6+
7+
## Installation
8+
9+
[Download a latest package](https://github.com/czproject/sql-schema/releases) or use [Composer](http://getcomposer.org/):
10+
11+
```
12+
composer require czproject/sql-schema
13+
```
14+
15+
CzProject\SqlSchema requires PHP 5.3.0 or later.
16+
17+
18+
## Usage
19+
20+
``` php
21+
use CzProject\SqlSchema\Index;
22+
$schema = new CzProject\SqlSchema\Schema;
23+
24+
$table = $schema->addTable('book');
25+
$table->addColumn('id', 'INT', NULL, array('UNSIGNED'));
26+
$table->addColumn('name', 'VARCHAR', array(200));
27+
$table->addColumn('author_id', 'INT', NULL, array('UNSIGNED'));
28+
$table->addIndex(NULL, Index::TYPE_PRIMARY, 'id');
29+
$table->addIndex('name_author_id', Index::TYPE_UNIQUE, array('name', 'author_id'));
30+
31+
$schema->getTables();
32+
```
33+
34+
------------------------------
35+
36+
License: [New BSD License](license.md)
37+
<br>Author: Jan Pecha, https://www.janpecha.cz/

src/Column.php

Lines changed: 228 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,228 @@
1+
<?php
2+
3+
namespace CzProject\SqlSchema;
4+
5+
6+
class Column
7+
{
8+
const OPTION_UNSIGNED = 'UNSIGNED';
9+
const OPTION_ZEROFILL = 'ZEROFILL';
10+
const OPTION_BINARY = 'BINARY';
11+
12+
/** @var string */
13+
private $name;
14+
15+
/** @var string */
16+
private $type;
17+
18+
/** @var array */
19+
private $parameters = array();
20+
21+
/** @var array */
22+
private $options = array();
23+
24+
/** @var bool */
25+
private $nullable = FALSE;
26+
27+
/** @var bool */
28+
private $autoIncrement = FALSE;
29+
30+
/** @var scalar|NULL */
31+
private $defaultValue;
32+
33+
/** @var string|NULL */
34+
private $comment;
35+
36+
37+
/**
38+
* @param string
39+
* @param string|NULL
40+
* @param array|string|NULL
41+
* @param array [OPTION => VALUE, OPTION2]
42+
*/
43+
public function __construct($name, $type, array $parameters = NULL, array $options = array())
44+
{
45+
$this->name = $name;
46+
$this->setType($type);
47+
$this->setParameters($parameters);
48+
$this->setOptions($options);
49+
}
50+
51+
52+
/**
53+
* @return string
54+
*/
55+
public function getName()
56+
{
57+
return $this->name;
58+
}
59+
60+
61+
/**
62+
* @param string
63+
* @return self
64+
*/
65+
public function setType($type)
66+
{
67+
$this->type = $type;
68+
return $this;
69+
}
70+
71+
72+
/**
73+
* @return string
74+
*/
75+
public function getType()
76+
{
77+
return $this->type;
78+
}
79+
80+
81+
/**
82+
* @param string|array|NULL
83+
* @return self
84+
*/
85+
public function setParameters($parameters)
86+
{
87+
if ($parameters === NULL) {
88+
$parameters = array();
89+
90+
} elseif (!is_array($parameters)) {
91+
$parameters = array($parameters);
92+
}
93+
94+
$this->parameters = $parameters;
95+
return $this;
96+
}
97+
98+
99+
/**
100+
* @return array
101+
*/
102+
public function getParameters()
103+
{
104+
return $this->parameters;
105+
}
106+
107+
108+
/**
109+
* @param string
110+
* @param scalar|NULL
111+
* @return self
112+
*/
113+
public function addOption($option, $value = NULL)
114+
{
115+
$this->options[$option] = $value;
116+
return $this;
117+
}
118+
119+
120+
/**
121+
* @param array
122+
* @return self
123+
*/
124+
public function setOptions(array $options)
125+
{
126+
$this->options = array();
127+
128+
foreach ($options as $k => $v) {
129+
if (is_int($k)) {
130+
$this->options[$v] = NULL;
131+
132+
} else {
133+
$this->options[$k] = $v;
134+
}
135+
}
136+
137+
return $this;
138+
}
139+
140+
141+
/**
142+
* @return array
143+
*/
144+
public function getOptions()
145+
{
146+
return $this->options;
147+
}
148+
149+
150+
/**
151+
* @param bool
152+
* @return self
153+
*/
154+
public function setNullable($nullable = TRUE)
155+
{
156+
$this->nullable = $nullable;
157+
return $this;
158+
}
159+
160+
161+
/**
162+
* @return bool
163+
*/
164+
public function isNullable()
165+
{
166+
return $this->nullable;
167+
}
168+
169+
170+
/**
171+
* @param bool
172+
* @return self
173+
*/
174+
public function setAutoIncrement($autoIncrement = TRUE)
175+
{
176+
$this->autoIncrement = $autoIncrement;
177+
return $this;
178+
}
179+
180+
181+
/**
182+
* @return bool
183+
*/
184+
public function isAutoIncrement()
185+
{
186+
return $this->autoIncrement;
187+
}
188+
189+
190+
/**
191+
* @param scalar|NULL
192+
* @return self
193+
*/
194+
public function setDefaultValue($defaultValue)
195+
{
196+
$this->defaultValue = $defaultValue;
197+
return $this;
198+
}
199+
200+
201+
/**
202+
* @return scalar|NULL
203+
*/
204+
public function getDefaultValue()
205+
{
206+
return $this->defaultValue;
207+
}
208+
209+
210+
/**
211+
* @param string|NULL
212+
* @return self
213+
*/
214+
public function setComment($comment)
215+
{
216+
$this->comment = $comment;
217+
return $this;
218+
}
219+
220+
221+
/**
222+
* @return string|NULL
223+
*/
224+
public function getComment()
225+
{
226+
return $this->comment;
227+
}
228+
}

0 commit comments

Comments
 (0)