eee
This commit is contained in:
+1
-1
@@ -90,7 +90,7 @@ class Command extends Component
|
|||||||
* @return mixed
|
* @return mixed
|
||||||
* @throws
|
* @throws
|
||||||
*/
|
*/
|
||||||
public function rowCount(): mixed
|
public function rowCount(): int
|
||||||
{
|
{
|
||||||
return $this->search('rowCount');
|
return $this->search('rowCount');
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -87,10 +87,7 @@ class Db extends QueryTrait implements ISqlBuilder
|
|||||||
*/
|
*/
|
||||||
public static function table(string $table, string $database = 'db'): Db|static
|
public static function table(string $table, string $database = 'db'): Db|static
|
||||||
{
|
{
|
||||||
$connection = new Db();
|
return self::connect($database)->from($table);
|
||||||
$connection->connection = current(\config('databases.connections'));
|
|
||||||
$connection->from($table);
|
|
||||||
return $connection;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -108,31 +105,12 @@ class Db extends QueryTrait implements ISqlBuilder
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return array|bool
|
|
||||||
* @throws
|
|
||||||
*/
|
|
||||||
public function get(): array|bool
|
|
||||||
{
|
|
||||||
return $this->connection->createCommand(SqlBuilder::builder($this)->all())->all();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return array|bool|null
|
|
||||||
* @throws
|
|
||||||
*/
|
|
||||||
public function first(): array|bool|null
|
|
||||||
{
|
|
||||||
return $this->connection->createCommand(SqlBuilder::builder($this)->all())->one();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return int
|
* @return int
|
||||||
*/
|
*/
|
||||||
public function count(): int
|
public function count(): int
|
||||||
{
|
{
|
||||||
$count = $this->connection->createCommand(SqlBuilder::builder($this)->count())->one();
|
return $this->connection->createCommand(SqlBuilder::builder($this)->count())->rowCount();
|
||||||
return current($count);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -140,8 +118,7 @@ class Db extends QueryTrait implements ISqlBuilder
|
|||||||
*/
|
*/
|
||||||
public function exists(): bool
|
public function exists(): bool
|
||||||
{
|
{
|
||||||
$fetchColumn = $this->connection->createCommand(SqlBuilder::builder($this)->one())->fetchColumn();
|
return $this->connection->createCommand(SqlBuilder::builder($this)->one())->rowCount() > 0;
|
||||||
return !empty($fetchColumn);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -150,7 +127,7 @@ class Db extends QueryTrait implements ISqlBuilder
|
|||||||
* @return array|bool|int|string|null
|
* @return array|bool|int|string|null
|
||||||
* @throws
|
* @throws
|
||||||
*/
|
*/
|
||||||
public function query(string $sql, array $attributes = []): int|bool|array|string|null
|
public function fetchAll(string $sql, array $attributes = []): int|bool|array|string|null
|
||||||
{
|
{
|
||||||
return $this->connection->createCommand($sql, $attributes)->all();
|
return $this->connection->createCommand($sql, $attributes)->all();
|
||||||
}
|
}
|
||||||
@@ -160,7 +137,7 @@ class Db extends QueryTrait implements ISqlBuilder
|
|||||||
* @param array $attributes
|
* @param array $attributes
|
||||||
* @return array|null
|
* @return array|null
|
||||||
*/
|
*/
|
||||||
public function one(string $sql, array $attributes = []): ?array
|
public function fetch(string $sql, array $attributes = []): ?array
|
||||||
{
|
{
|
||||||
return $this->connection->createCommand($sql, $attributes)->one();
|
return $this->connection->createCommand($sql, $attributes)->one();
|
||||||
}
|
}
|
||||||
@@ -188,7 +165,6 @@ class Db extends QueryTrait implements ISqlBuilder
|
|||||||
|
|
||||||
$table = [' const TABLE = \'select * from %s where REFERENCED_TABLE_NAME=%s\';'];
|
$table = [' const TABLE = \'select * from %s where REFERENCED_TABLE_NAME=%s\';'];
|
||||||
return $connection->createCommand((new Query())
|
return $connection->createCommand((new Query())
|
||||||
->select('*')
|
|
||||||
->from('INFORMATION_SCHEMA.KEY_COLUMN_USAGE')
|
->from('INFORMATION_SCHEMA.KEY_COLUMN_USAGE')
|
||||||
->where(['REFERENCED_TABLE_NAME' => $table])
|
->where(['REFERENCED_TABLE_NAME' => $table])
|
||||||
->build())->one();
|
->build())->one();
|
||||||
|
|||||||
Reference in New Issue
Block a user