Fix type issues

This commit is contained in:
Timothy Warren 2023-01-20 10:33:43 -05:00
parent d80f26859e
commit 973e92e99f
11 changed files with 81 additions and 33 deletions

View File

@ -339,6 +339,8 @@ abstract class AbstractDriver
/** /**
* Return list of functions for the current database * Return list of functions for the current database
*
* @deprecated Will be removed in next version
*/ */
public function getFunctions(): ?array public function getFunctions(): ?array
{ {
@ -347,6 +349,8 @@ abstract class AbstractDriver
/** /**
* Return list of stored procedures for the current database * Return list of stored procedures for the current database
*
* @deprecated Will be removed in next version
*/ */
public function getProcedures(): ?array public function getProcedures(): ?array
{ {
@ -355,6 +359,8 @@ abstract class AbstractDriver
/** /**
* Return list of triggers for the current database * Return list of triggers for the current database
*
* @deprecated Will be removed in next version
*/ */
public function getTriggers(): ?array public function getTriggers(): ?array
{ {

View File

@ -102,16 +102,22 @@ interface DriverInterface /* extends the interface of PDO */ {
/** /**
* Return list of functions for the current database * Return list of functions for the current database
*
* @deprecated Will be removed in next version
*/ */
public function getFunctions(): ?array; public function getFunctions(): ?array;
/** /**
* Return list of stored procedures for the current database * Return list of stored procedures for the current database
*
* @deprecated Will be removed in next version
*/ */
public function getProcedures(): ?array; public function getProcedures(): ?array;
/** /**
* Return list of triggers for the current database * Return list of triggers for the current database
*
* @deprecated Will be removed in next version
*/ */
public function getTriggers(): ?array; public function getTriggers(): ?array;

View File

@ -98,6 +98,8 @@ SQL;
/** /**
* Returns sql to list triggers * Returns sql to list triggers
*
* @codeCoverageIgnore
*/ */
public function triggerList(): string public function triggerList(): string
{ {
@ -106,6 +108,8 @@ SQL;
/** /**
* Return sql to list functions * Return sql to list functions
*
* @codeCoverageIgnore
*/ */
public function functionList(): string public function functionList(): string
{ {
@ -114,6 +118,8 @@ SQL;
/** /**
* Return sql to list stored procedures * Return sql to list stored procedures
*
* @codeCoverageIgnore
*/ */
public function procedureList(): string public function procedureList(): string
{ {

View File

@ -64,8 +64,6 @@ class Driver extends AbstractDriver {
/** /**
* Retrieve foreign keys for the table * Retrieve foreign keys for the table
*
* @return array<int, array{child_column: mixed, parent_table: mixed, parent_column: mixed, update: mixed, delete: mixed}>
*/ */
public function getFks(string $table): array public function getFks(string $table): array
{ {

View File

@ -24,4 +24,14 @@ enum JoinType: string {
case OUTER = 'outer'; case OUTER = 'outer';
case LEFT = 'left'; case LEFT = 'left';
case RIGHT = 'right'; case RIGHT = 'right';
public static function parse(string|self $val): self {
if ($val instanceof self)
{
return $val;
}
return self::from($val);
}
} }

View File

@ -22,4 +22,13 @@ enum LikeType: string {
case BEFORE = 'before'; case BEFORE = 'before';
case AFTER = 'after'; case AFTER = 'after';
case BOTH = 'both'; case BOTH = 'both';
public static function parse(string|self $val): self {
if ($val instanceof self)
{
return $val;
}
return self::from($val);
}
} }

View File

@ -188,33 +188,33 @@ class QueryBuilder extends QueryBuilderBase implements QueryBuilderInterface {
/** /**
* Creates a Like clause in the sql statement * Creates a Like clause in the sql statement
*/ */
public function like(string $field, mixed $val, LikeType $pos=LikeType::BOTH): self public function like(string $field, mixed $values, LikeType|string $pos=LikeType::BOTH): self
{ {
return $this->_like($field, $val, $pos); return $this->_like($field, $values, LikeType::parse($pos));
} }
/** /**
* Generates an OR Like clause * Generates an OR Like clause
*/ */
public function orLike(string $field, mixed $val, LikeType $pos=LikeType::BOTH): self public function orLike(string $field, mixed $values, LikeType|string $pos=LikeType::BOTH): self
{ {
return $this->_like($field, $val, $pos, 'LIKE', 'OR'); return $this->_like($field, $values, LikeType::parse($pos), 'LIKE', 'OR');
} }
/** /**
* Generates a NOT LIKE clause * Generates a NOT LIKE clause
*/ */
public function notLike(string $field, mixed $val, LikeType $pos=LikeType::BOTH): self public function notLike(string $field, mixed $values, LikeType|string $pos=LikeType::BOTH): self
{ {
return $this->_like($field, $val, $pos, 'NOT LIKE'); return $this->_like($field, $values, LikeType::parse($pos), 'NOT LIKE');
} }
/** /**
* Generates a OR NOT LIKE clause * Generates a OR NOT LIKE clause
*/ */
public function orNotLike(string $field, mixed $val, LikeType $pos=LikeType::BOTH): self public function orNotLike(string $field, mixed $values, LikeType|string $pos=LikeType::BOTH): self
{ {
return $this->_like($field, $val, $pos, 'NOT LIKE', 'OR'); return $this->_like($field, $values, LikeType::parse($pos), 'NOT LIKE', 'OR');
} }
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
@ -223,17 +223,17 @@ class QueryBuilder extends QueryBuilderBase implements QueryBuilderInterface {
/** /**
* Generates a 'Having' clause * Generates a 'Having' clause
*/ */
public function having(mixed $key, mixed $val=[]): self public function having(mixed $key, mixed $values=[]): self
{ {
return $this->_having($key, $val); return $this->_having($key, $values);
} }
/** /**
* Generates a 'Having' clause prefixed with 'OR' * Generates a 'Having' clause prefixed with 'OR'
*/ */
public function orHaving(mixed $key, mixed $val=[]): self public function orHaving(mixed $key, mixed $values=[]): self
{ {
return $this->_having($key, $val, 'OR'); return $this->_having($key, $values, 'OR');
} }
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
@ -244,17 +244,17 @@ class QueryBuilder extends QueryBuilderBase implements QueryBuilderInterface {
* Note: this function works with key / value, or a * Note: this function works with key / value, or a
* passed array with key / value pairs * passed array with key / value pairs
*/ */
public function where(mixed $key, mixed $val=[]): self public function where(mixed $key, mixed $values=[]): self
{ {
return $this->_whereString($key, $val); return $this->_whereString($key, $values);
} }
/** /**
* Where clause prefixed with "OR" * Where clause prefixed with "OR"
*/ */
public function orWhere(mixed $key, mixed $val=[]): self public function orWhere(mixed $key, mixed $values=[]): self
{ {
return $this->_whereString($key, $val, 'OR'); return $this->_whereString($key, $values, 'OR');
} }
/** /**
@ -323,7 +323,7 @@ class QueryBuilder extends QueryBuilderBase implements QueryBuilderInterface {
/** /**
* Creates a join phrase in a compiled query * Creates a join phrase in a compiled query
*/ */
public function join(string $table, string $condition, JoinType $type=JoinType::INNER): self public function join(string $table, string $condition, JoinType|string $type=JoinType::INNER): self
{ {
// Prefix and quote table name // Prefix and quote table name
$tableArr = explode(' ', mb_trim($table)); $tableArr = explode(' ', mb_trim($table));
@ -335,7 +335,7 @@ class QueryBuilder extends QueryBuilderBase implements QueryBuilderInterface {
$parsedCondition = $this->parser->compileJoin($condition); $parsedCondition = $this->parser->compileJoin($condition);
$condition = $table . ' ON ' . $parsedCondition; $condition = $table . ' ON ' . $parsedCondition;
$this->state->appendMap("\n" . strtoupper($type->value) . ' JOIN ', $condition, MapType::JOIN); $this->state->appendMap("\n" . strtoupper(JoinType::parse($type)->value) . ' JOIN ', $condition, MapType::JOIN);
return $this; return $this;
} }
@ -490,7 +490,7 @@ class QueryBuilder extends QueryBuilderBase implements QueryBuilderInterface {
$this->limit($limit, $offset); $this->limit($limit, $offset);
} }
return $this->_run('get', $table); return $this->_run(QueryType::SELECT, $table);
} }
/** /**

View File

@ -33,15 +33,12 @@ use Query\Drivers\DriverInterface;
* @method getColumns(string $table): array | null * @method getColumns(string $table): array | null
* @method getDbs(): array | null * @method getDbs(): array | null
* @method getFks(string $table): array | null * @method getFks(string $table): array | null
* @method getFunctions(): array | null
* @method getIndexes(string $table): array | null * @method getIndexes(string $table): array | null
* @method getLastQuery(): string * @method getLastQuery(): string
* @method getProcedures(): array | null
* @method getSchemas(): array | null * @method getSchemas(): array | null
* @method getSequences(): array | null * @method getSequences(): array | null
* @method getSystemTables(): array | null * @method getSystemTables(): array | null
* @method getTables(): array * @method getTables(): array
* @method getTriggers(): array | null
* @method getTypes(): array | null * @method getTypes(): array | null
* @method getUtil(): \Query\Drivers\AbstractUtil * @method getUtil(): \Query\Drivers\AbstractUtil
* @method getVersion(): string * @method getVersion(): string
@ -284,10 +281,12 @@ class QueryBuilderBase {
if (empty($queryMap) || ( ! regexInArray($conjunctionList, "/^ ?\n?WHERE/i"))) if (empty($queryMap) || ( ! regexInArray($conjunctionList, "/^ ?\n?WHERE/i")))
{ {
$conj = "\nWHERE "; $conj = "\nWHERE ";
} elseif ($lastItem['type'] === 'group_start') }
elseif ($lastItem['type'] === MapType::GROUP_START)
{ {
$conj = ''; $conj = '';
} else }
else
{ {
$conj = " {$defaultConj} "; $conj = " {$defaultConj} ";
} }

View File

@ -127,28 +127,28 @@ interface QueryBuilderInterface {
* *
* @param mixed $values * @param mixed $values
*/ */
public function like(string $field, mixed $values, LikeType $pos=LikeType::BOTH): self; public function like(string $field, mixed $values, LikeType|string $pos=LikeType::BOTH): self;
/** /**
* Generates an OR Like clause * Generates an OR Like clause
* *
* @param mixed $values * @param mixed $values
*/ */
public function orLike(string $field, mixed $values, LikeType $pos=LikeType::BOTH): self; public function orLike(string $field, mixed $values, LikeType|string $pos=LikeType::BOTH): self;
/** /**
* Generates a NOT LIKE clause * Generates a NOT LIKE clause
* *
* @param mixed $values * @param mixed $values
*/ */
public function notLike(string $field, mixed $values, LikeType $pos=LikeType::BOTH): self; public function notLike(string $field, mixed $values, LikeType|string $pos=LikeType::BOTH): self;
/** /**
* Generates a OR NOT LIKE clause * Generates a OR NOT LIKE clause
* *
* @param mixed $values * @param mixed $values
*/ */
public function orNotLike(string $field, mixed $values, LikeType $pos=LikeType::BOTH): self; public function orNotLike(string $field, mixed $values, LikeType|string $pos=LikeType::BOTH): self;
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
// ! Having methods // ! Having methods
@ -236,7 +236,7 @@ interface QueryBuilderInterface {
/** /**
* Creates a join phrase in a compiled query * Creates a join phrase in a compiled query
*/ */
public function join(string $table, string $condition, JoinType $type=JoinType::INNER): self; public function join(string $table, string $condition, JoinType|string $type=JoinType::INNER): self;
/** /**
* Group the results by the selected field(s) * Group the results by the selected field(s)

View File

@ -101,7 +101,7 @@ abstract class BaseDriverTest extends TestCase {
public function testGetTriggers(): void public function testGetTriggers(): void
{ {
// @TODO standardize trigger output for different databases $this->markTestSkipped('Deprecated');
$triggers = self::$db->getTriggers(); $triggers = self::$db->getTriggers();
$this->assertTrue(\is_array($triggers)); $this->assertTrue(\is_array($triggers));
@ -122,12 +122,16 @@ abstract class BaseDriverTest extends TestCase {
public function testGetProcedures(): void public function testGetProcedures(): void
{ {
$this->markTestSkipped('Deprecated');
$procedures = self::$db->getProcedures(); $procedures = self::$db->getProcedures();
$this->assertTrue(\is_array($procedures)); $this->assertTrue(\is_array($procedures));
} }
public function testGetFunctions(): void public function testGetFunctions(): void
{ {
$this->markTestSkipped('Deprecated');
$funcs = self::$db->getFunctions(); $funcs = self::$db->getFunctions();
$this->assertTrue(\is_array($funcs)); $this->assertTrue(\is_array($funcs));
} }

View File

@ -201,6 +201,16 @@ abstract class BaseQueryBuilderTest extends TestCase {
$this->assertIsA($query, 'PDOStatement'); $this->assertIsA($query, 'PDOStatement');
} }
public function testSelectTableGet(): void
{
$query = self::$db->select('id, key as k, val')
->table('test ct')
->where('id >', 1)
->get();
$this->assertIsA($query, 'PDOStatement');
}
public function testSelectFromLimitGet(): void public function testSelectFromLimitGet(): void
{ {
$query = self::$db->select('id, key as k, val') $query = self::$db->select('id, key as k, val')