This commit is contained in:
2023-12-13 15:36:51 +08:00
parent 3179e95a82
commit a73b5c0e2a
2 changed files with 6 additions and 30 deletions
+1 -1
View File
@@ -90,7 +90,7 @@ class Command extends Component
* @return mixed
* @throws
*/
public function rowCount(): mixed
public function rowCount(): int
{
return $this->search('rowCount');
}
+5 -29
View File
@@ -87,10 +87,7 @@ class Db extends QueryTrait implements ISqlBuilder
*/
public static function table(string $table, string $database = 'db'): Db|static
{
$connection = new Db();
$connection->connection = current(\config('databases.connections'));
$connection->from($table);
return $connection;
return self::connect($database)->from($table);
}
@@ -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
*/
public function count(): int
{
$count = $this->connection->createCommand(SqlBuilder::builder($this)->count())->one();
return current($count);
return $this->connection->createCommand(SqlBuilder::builder($this)->count())->rowCount();
}
/**
@@ -140,8 +118,7 @@ class Db extends QueryTrait implements ISqlBuilder
*/
public function exists(): bool
{
$fetchColumn = $this->connection->createCommand(SqlBuilder::builder($this)->one())->fetchColumn();
return !empty($fetchColumn);
return $this->connection->createCommand(SqlBuilder::builder($this)->one())->rowCount() > 0;
}
/**
@@ -150,7 +127,7 @@ class Db extends QueryTrait implements ISqlBuilder
* @return array|bool|int|string|null
* @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();
}
@@ -160,7 +137,7 @@ class Db extends QueryTrait implements ISqlBuilder
* @param array $attributes
* @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();
}
@@ -188,7 +165,6 @@ class Db extends QueryTrait implements ISqlBuilder
$table = [' const TABLE = \'select * from %s where REFERENCED_TABLE_NAME=%s\';'];
return $connection->createCommand((new Query())
->select('*')
->from('INFORMATION_SCHEMA.KEY_COLUMN_USAGE')
->where(['REFERENCED_TABLE_NAME' => $table])
->build())->one();