Skip to content

Commit

Permalink
Merge pull request #3 from kristuff/dev
Browse files Browse the repository at this point in the history
v0.2
  • Loading branch information
kristuff authored Apr 15, 2020
2 parents 5a0aeec + 39fc171 commit ae2c6b8
Show file tree
Hide file tree
Showing 47 changed files with 490 additions and 272 deletions.
15 changes: 11 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,24 @@
language: php

php:
- '5.6'
- '7.0'
# - '5.6'
# - '7.0'
- '7.1'
- '7.2'
- '7.3'
- '7.4'

services:
- mysql
- postgresql

before_install:
- composer install
- cd tests

before_script:
# - psql -c "DROP DATABASE IF EXISTS patabaseTest;" -U postgres
# - mysql -e "DROP DATABASE IF EXISTS patabaseTest;" -uroot
# - psql -c "DROP DATABASE IF EXISTS patabaseTest;" -U postgres
# - mysql -e "DROP DATABASE IF EXISTS patabaseTest;" -u root

script:
- ../vendor/bin/phpunit --debug --configuration phpunit.xml --coverage-text --coverage-clover=coverage.xml
Expand Down
21 changes: 21 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Changelog
All notable changes to this project will be documented in this file.


## [v0.2] - 2020-04-15

### Added
- Best support for sub queries filters : when using the WHERE or HAVING clause, the prefix _PATABASE_COLUMN_LITERALL_ in the filter value allows to match with the result of the main query (insead of a non dynamic value).

### Changed
- **Possible break change** Drop support for php < 7.1
- **Possible break change** Columns, other than primary key, are now nullable by default when creating a table (constraint 'NULL'). In previous releases, columns other than primary key created without explicit 'NULL' or 'NOT NULL' argument was created with 'NOT NULL' constraint.
- **Possible break change** Removed DatabaseDriver::getVersion() and Datasource::getVersion().


## [v0.1] - 2017-06-30

### Initial release
- Support for Sqlite, Mysql, Postgresql


4 changes: 2 additions & 2 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)
The MIT License (MIT)

Copyright (c) 2017 Kristuff
Copyright (c) 2017-2020 Kristuff

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ Server queries (*):
Requirements
------------

- PHP >= 5.6
- PHP >= 7.1
- PDO extension: Sqlite, Mysql or Postgresql


Expand All @@ -79,7 +79,7 @@ License

The MIT License (MIT)

Copyright (c) 2017 Kristuff
Copyright (c) 2017-2020 Kristuff

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
}
],
"require": {
"php": ">=5.6.0"
"php": ">=7.1"
},
"autoload": {
"psr-4": {"Kristuff\\Patabase\\": "lib/"}
},
"require-dev": {
"phpunit/phpunit": "5.7.*"
"phpunit/phpunit": "^6 || ^8"
}
}
35 changes: 35 additions & 0 deletions lib/Constants.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

/*
* ____ _ _
* | _ \ __ _ | |_ __ _ | |__ __ _ ___ ___
* | |_) |/ _` || __|/ _` || '_ \ / _` |/ __| / _ \
* | __/| (_| || |_| (_| || |_) || (_| |\__ \| __/
* |_| \__,_| \__|\__,_||_.__/ \__,_||___/ \___|
*
* This file is part of Kristuff\Patabase.
*
* (c) Kristuff <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @version 0.2.0
* @copyright 2017-2020 Kristuff
*/

namespace Kristuff\Patabase;

/**
* Class Constants
*
* Define api constants
*/
class Constants
{
/**
* Define the constant _PATABASE_COLUMN_LITERALL_ to indicate to the clause WHERE or HAVING in sub queries to refer
* to the result of a main query, instead of a non dynamic value
*/
const COLUMN_LITERALL = '_PATABASE_COLUMN_LITERALL_';
}
10 changes: 8 additions & 2 deletions lib/Database.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
<?php

/*
* ____ _ _
* | _ \ __ _ | |_ __ _ | |__ __ _ ___ ___
* | |_) |/ _` || __|/ _` || '_ \ / _` |/ __| / _ \
* | __/| (_| || |_| (_| || |_) || (_| |\__ \| __/
* |_| \__,_| \__|\__,_||_.__/ \__,_||___/ \___|
*
* This file is part of Kristuff\Patabase.
*
* (c) Kristuff <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @version 0.1.0
* @copyright 2017 Kristuff
* @version 0.2.0
* @copyright 2017-2020 Kristuff
*/

namespace Kristuff\Patabase;
Expand Down
24 changes: 9 additions & 15 deletions lib/Datasource.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
<?php

/*
* ____ _ _
* | _ \ __ _ | |_ __ _ | |__ __ _ ___ ___
* | |_) |/ _` || __|/ _` || '_ \ / _` |/ __| / _ \
* | __/| (_| || |_| (_| || |_) || (_| |\__ \| __/
* |_| \__,_| \__|\__,_||_.__/ \__,_||___/ \___|
*
* This file is part of Kristuff\Patabase.
*
* (c) Kristuff <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @version 0.1.0
* @copyright 2017 Kristuff
* @version 0.2.0
*
* @copyright 2017-2020 Kristuff
*/

namespace Kristuff\Patabase;
Expand Down Expand Up @@ -46,18 +53,6 @@ abstract class Datasource
*/
abstract protected function openConnection();

/**
* Get Patabase Version
*
* @access public
* @method static
* @return string format (0.0.0)
*/
public static function getVersion()
{
return DatabaseDriver::getVersion();
}

/**
* Get the current driver name
*
Expand Down Expand Up @@ -159,5 +154,4 @@ public function closeConnection()
$this->driver = null;
}
}

}
32 changes: 10 additions & 22 deletions lib/Driver/DatabaseDriver.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
<?php

/*
* ____ _ _
* | _ \ __ _ | |_ __ _ | |__ __ _ ___ ___
* | |_) |/ _` || __|/ _` || '_ \ / _` |/ __| / _ \
* | __/| (_| || |_| (_| || |_) || (_| |\__ \| __/
* |_| \__,_| \__|\__,_||_.__/ \__,_||___/ \___|
*
* This file is part of Kristuff\Patabase.
*
* (c) Kristuff <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @version 0.1.0
* @copyright 2017 Kristuff
* @version 0.2.0
*
* @copyright 2017-2020 Kristuff
*/

namespace Kristuff\Patabase\Driver;
Expand All @@ -25,15 +32,7 @@
*/
abstract class DatabaseDriver
{
/**
* Version
*
* @access protected
* @var string
*/
protected static $version = "0.1.0";

/**
/**
* PDO connection
*
* @access protected
Expand Down Expand Up @@ -185,17 +184,6 @@ public function __construct(array $settings)
$this->driverName = $settings['driver'];
}

/**
* Get the current version (format: 0.0.0)
*
* @access public
* @return string
*/
public static function getVersion()
{
return self::$version;
}

/**
* Has error
*
Expand Down
10 changes: 8 additions & 2 deletions lib/Driver/DriverFactory.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
<?php

/*
* ____ _ _
* | _ \ __ _ | |_ __ _ | |__ __ _ ___ ___
* | |_) |/ _` || __|/ _` || '_ \ / _` |/ __| / _ \
* | __/| (_| || |_| (_| || |_) || (_| |\__ \| __/
* |_| \__,_| \__|\__,_||_.__/ \__,_||___/ \___|
*
* This file is part of Kristuff\Patabase.
*
* (c) Kristuff <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @version 0.1.0
* @copyright 2017 Kristuff
* @version 0.2.0
* @copyright 2017-2020 Kristuff
*/

namespace Kristuff\Patabase\Driver;
Expand Down
18 changes: 11 additions & 7 deletions lib/Driver/Mysql/MysqlDriver.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
<?php

/*
* ____ _ _
* | _ \ __ _ | |_ __ _ | |__ __ _ ___ ___
* | |_) |/ _` || __|/ _` || '_ \ / _` |/ __| / _ \
* | __/| (_| || |_| (_| || |_) || (_| |\__ \| __/
* |_| \__,_| \__|\__,_||_.__/ \__,_||___/ \___|
*
* This file is part of Kristuff\Patabase.
*
* (c) Kristuff <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @version 0.1.0
* @copyright 2017 Kristuff
* @version 0.2.0
*
* @copyright 2017-2020 Kristuff
*/

namespace Kristuff\Patabase\Driver\Mysql;
Expand Down Expand Up @@ -81,10 +88,9 @@ public function createConnection(array $settings)
$charset = !empty($settings['charset']) ? ';charset='.$settings['charset'] : ';charset=utf8';
$port = !empty($settings['port']) ? ';port='.$settings['port'] : '';
$dbname = !empty($settings['database']) ? ';dbname='.$settings['database'] : '';
$dsn = 'mysql:host='.$settings['hostname'] .$port .$dbname .$charset ;

$this->pdo = new \PDO(
$dsn,
'mysql:host='.$settings['hostname'] .$port .$dbname .$charset,
$settings['username'],
$settings['password'],
array()
Expand Down Expand Up @@ -123,7 +129,6 @@ public function enableForeignKeys()
*/
public function disableForeignKeys()
{
// TODO return $this->prepareAndExecuteSql('SET FOREIGN_KEY_CHECKS=0');
$this->pdo->exec('SET FOREIGN_KEY_CHECKS=0');
}

Expand Down Expand Up @@ -315,8 +320,7 @@ public function sqlCreateTableOptions()
*/
public function sqlRandom($seed = null)
{
$seed = !empty($seed) ? $seed : '';
return sprintf('rand(%s)', $seed);
return sprintf('rand(%s)', !empty($seed) ? $seed : '');
}

/**
Expand Down
10 changes: 8 additions & 2 deletions lib/Driver/Postgres/PostgresDriver.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
<?php

/*
* ____ _ _
* | _ \ __ _ | |_ __ _ | |__ __ _ ___ ___
* | |_) |/ _` || __|/ _` || '_ \ / _` |/ __| / _ \
* | __/| (_| || |_| (_| || |_) || (_| |\__ \| __/
* |_| \__,_| \__|\__,_||_.__/ \__,_||___/ \___|
*
* This file is part of Kristuff\Patabase.
*
* (c) Kristuff <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @version 0.1.0
* @copyright 2017 Kristuff
* @version 0.2.0
* @copyright 2017-2020 Kristuff
*/

namespace Kristuff\Patabase\Driver\Postgres;
Expand Down
10 changes: 8 additions & 2 deletions lib/Driver/ServerDriver.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
<?php

/*
* ____ _ _
* | _ \ __ _ | |_ __ _ | |__ __ _ ___ ___
* | |_) |/ _` || __|/ _` || '_ \ / _` |/ __| / _ \
* | __/| (_| || |_| (_| || |_) || (_| |\__ \| __/
* |_| \__,_| \__|\__,_||_.__/ \__,_||___/ \___|
*
* This file is part of Kristuff\Patabase.
*
* (c) Kristuff <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @version 0.1.0
* @copyright 2017 Kristuff
* @version 0.2.0
* @copyright 2017-2020 Kristuff
*/

namespace Kristuff\Patabase\Driver;
Expand Down
Loading

0 comments on commit ae2c6b8

Please sign in to comment.