改名
This commit is contained in:
+13
-12
@@ -4,6 +4,7 @@ declare(strict_types=1);
|
||||
namespace Database\Orm;
|
||||
|
||||
|
||||
use JetBrains\PhpStorm\Pure;
|
||||
use Snowflake\Abstracts\BaseObject;
|
||||
use Database\ActiveQuery;
|
||||
use Exception;
|
||||
@@ -26,7 +27,7 @@ class Change extends BaseObject
|
||||
* @return string
|
||||
* @throws Exception
|
||||
*/
|
||||
public function update(string $model, $attributes, $condition, &$params)
|
||||
public function update(string $model, $attributes, $condition, &$params): string
|
||||
{
|
||||
if (empty($params)) {
|
||||
throw new Exception("Not has update values.");
|
||||
@@ -55,7 +56,7 @@ class Change extends BaseObject
|
||||
* @return array|string
|
||||
* @throws
|
||||
*/
|
||||
public function batchUpdate(string $table, array $attributes, $condition)
|
||||
public function batchUpdate(string $table, array $attributes, $condition): array|string
|
||||
{
|
||||
$param = [];
|
||||
$_attributes = [];
|
||||
@@ -83,7 +84,7 @@ class Change extends BaseObject
|
||||
* @return string
|
||||
* @throws Exception
|
||||
*/
|
||||
public function mathematics($table, $params, $condition)
|
||||
public function mathematics($table, $params, $condition): string
|
||||
{
|
||||
$_tmp = $newParam = [];
|
||||
if (isset($params['incr']) && is_array($params['incr'])) {
|
||||
@@ -109,7 +110,7 @@ class Change extends BaseObject
|
||||
* @return array
|
||||
* @throws Exception
|
||||
*/
|
||||
private function assemble($params, $op, array $_tmp)
|
||||
private function assemble($params, $op, array $_tmp): array
|
||||
{
|
||||
$message = 'Incr And Decr action. The value must a numeric.';
|
||||
foreach ($params as $key => $val) {
|
||||
@@ -127,7 +128,7 @@ class Change extends BaseObject
|
||||
* @param array $params
|
||||
* @return string
|
||||
*/
|
||||
public function insertOrUpdateByDUPLICATE($table, array $params)
|
||||
public function insertOrUpdateByDUPLICATE($table, array $params): string
|
||||
{
|
||||
$keys = implode(',', array_keys($params));
|
||||
|
||||
@@ -153,14 +154,14 @@ class Change extends BaseObject
|
||||
* @return string
|
||||
* @throws Exception
|
||||
*/
|
||||
public function insert($table, $attributes, array $params = NULL)
|
||||
public function insert($table, $attributes, array $params = NULL): string
|
||||
{
|
||||
$sql = $this->inserts($table, implode(',', $attributes), '(:' . implode(',:', $attributes) . ')');
|
||||
if (empty($params)) {
|
||||
throw new Exception("save data param not find.");
|
||||
}
|
||||
foreach ($params as $key => $val) {
|
||||
if (strpos($sql, ':' . $key) === FALSE) {
|
||||
if (!str_contains($sql, ':' . $key)) {
|
||||
throw new Exception("save $key data param not find.");
|
||||
}
|
||||
}
|
||||
@@ -175,7 +176,7 @@ class Change extends BaseObject
|
||||
* @return array
|
||||
* @throws Exception
|
||||
*/
|
||||
public function batchInsert($table, $attributes, array $params = NULL)
|
||||
public function batchInsert($table, $attributes, array $params = NULL): array
|
||||
{
|
||||
if (empty($params)) {
|
||||
throw new Exception("save data param not find.");
|
||||
@@ -205,7 +206,7 @@ class Change extends BaseObject
|
||||
* @return string
|
||||
* 构建SQL语句
|
||||
*/
|
||||
private function inserts($table, $fields, $data)
|
||||
#[Pure] private function inserts($table, $fields, $data): string
|
||||
{
|
||||
$query = [
|
||||
'INSERT IGNORE INTO', '%s', '(%s)', 'VALUES %s'
|
||||
@@ -223,7 +224,7 @@ class Change extends BaseObject
|
||||
* @return bool|string
|
||||
* @throws Exception
|
||||
*/
|
||||
public function updateAll($table, $attributes, $condition)
|
||||
public function updateAll($table, $attributes, $condition): bool|string
|
||||
{
|
||||
$param = [];
|
||||
foreach ($attributes as $key => $val) {
|
||||
@@ -247,7 +248,7 @@ class Change extends BaseObject
|
||||
* @return string
|
||||
* @throws Exception
|
||||
*/
|
||||
public function delete(ActiveQuery $query)
|
||||
public function delete(ActiveQuery $query): string
|
||||
{
|
||||
if (empty($query->from)) {
|
||||
$query->from = $query->getTable();
|
||||
@@ -266,7 +267,7 @@ class Change extends BaseObject
|
||||
* @param string $tableName
|
||||
* @return string
|
||||
*/
|
||||
public function truncate(string $tableName)
|
||||
public function truncate(string $tableName): string
|
||||
{
|
||||
return 'TRUNCATE ' . $tableName;
|
||||
}
|
||||
|
||||
+20
-15
@@ -3,8 +3,11 @@ declare(strict_types=1);
|
||||
|
||||
namespace Database\Orm;
|
||||
|
||||
use JetBrains\PhpStorm\Pure;
|
||||
use ReflectionException;
|
||||
use Snowflake\Core\JSON;
|
||||
use Snowflake\Core\Str;
|
||||
use Snowflake\Exception\NotFindClassException;
|
||||
use Snowflake\Snowflake;
|
||||
use Database\ActiveQuery;
|
||||
use Database\Base\ConditionClassMap;
|
||||
@@ -26,7 +29,7 @@ trait Condition
|
||||
* @return string
|
||||
* @throws Exception
|
||||
*/
|
||||
public function getWhere($query)
|
||||
public function getWhere($query): string
|
||||
{
|
||||
return $this->builderWhere($query);
|
||||
}
|
||||
@@ -36,7 +39,7 @@ trait Condition
|
||||
* @param $alias
|
||||
* @return string
|
||||
*/
|
||||
private function builderAlias($alias)
|
||||
private function builderAlias($alias): string
|
||||
{
|
||||
return " AS " . $alias;
|
||||
}
|
||||
@@ -46,7 +49,7 @@ trait Condition
|
||||
* @return string
|
||||
* @throws Exception
|
||||
*/
|
||||
private function builderFrom($table)
|
||||
private function builderFrom($table): string
|
||||
{
|
||||
if ($table instanceof ActiveQuery) {
|
||||
$table = '(' . $table->getBuild()->getQuery($table) . ')';
|
||||
@@ -58,7 +61,7 @@ trait Condition
|
||||
* @param $join
|
||||
* @return string
|
||||
*/
|
||||
private function builderJoin($join)
|
||||
#[Pure] private function builderJoin($join): string
|
||||
{
|
||||
if (!empty($join)) {
|
||||
return ' ' . implode(' ', $join);
|
||||
@@ -71,7 +74,7 @@ trait Condition
|
||||
* @return string
|
||||
* @throws Exception
|
||||
*/
|
||||
private function builderWhere($where)
|
||||
private function builderWhere($where): string
|
||||
{
|
||||
if (empty($where)) {
|
||||
return '';
|
||||
@@ -101,10 +104,11 @@ trait Condition
|
||||
|
||||
/**
|
||||
* @param $value
|
||||
* @return mixed|object|string|null
|
||||
* @throws Exception
|
||||
* @return mixed
|
||||
* @throws ReflectionException
|
||||
* @throws NotFindClassException
|
||||
*/
|
||||
private function arrayMap($value)
|
||||
private function arrayMap($value): mixed
|
||||
{
|
||||
$classMap = ConditionClassMap::$conditionMap;
|
||||
if (isset($value[0])) {
|
||||
@@ -125,10 +129,11 @@ trait Condition
|
||||
|
||||
/**
|
||||
* @param $value
|
||||
* @return mixed|object
|
||||
* @throws Exception
|
||||
* @return mixed
|
||||
* @throws NotFindClassException
|
||||
* @throws ReflectionException
|
||||
*/
|
||||
private function classMap($value)
|
||||
private function classMap($value): mixed
|
||||
{
|
||||
[$option['opera'], $option['column'], $option['value']] = $value;
|
||||
|
||||
@@ -146,7 +151,7 @@ trait Condition
|
||||
* @param $group
|
||||
* @return string
|
||||
*/
|
||||
private function builderGroup($group)
|
||||
private function builderGroup($group): string
|
||||
{
|
||||
if (empty($group)) {
|
||||
return '';
|
||||
@@ -158,7 +163,7 @@ trait Condition
|
||||
* @param $order
|
||||
* @return string
|
||||
*/
|
||||
private function builderOrder($order)
|
||||
private function builderOrder($order): string
|
||||
{
|
||||
if (!empty($order)) {
|
||||
return ' ORDER BY ' . implode(',', $order);
|
||||
@@ -171,7 +176,7 @@ trait Condition
|
||||
* @param ActiveQuery $query
|
||||
* @return string
|
||||
*/
|
||||
private function builderLimit(ActiveQuery $query)
|
||||
private function builderLimit(ActiveQuery $query): string
|
||||
{
|
||||
$limit = $query->limit;
|
||||
if (!is_numeric($limit) || $limit < 1) {
|
||||
@@ -192,7 +197,7 @@ trait Condition
|
||||
* @param bool $isSearch
|
||||
* @return int|string
|
||||
*/
|
||||
public function valueEncode($value, $isSearch = false)
|
||||
public function valueEncode($value, $isSearch = false): int|string
|
||||
{
|
||||
if ($isSearch) {
|
||||
return $value;
|
||||
|
||||
@@ -4,6 +4,7 @@ declare(strict_types=1);
|
||||
namespace Database\Orm;
|
||||
|
||||
|
||||
use JetBrains\PhpStorm\Pure;
|
||||
use Snowflake\Abstracts\BaseObject;
|
||||
use Database\ActiveQuery;
|
||||
use Database\Sql;
|
||||
@@ -24,17 +25,17 @@ class Select extends BaseObject
|
||||
* @return string
|
||||
* @throws Exception
|
||||
*/
|
||||
public function getQuery($query)
|
||||
public function getQuery(ActiveQuery|Sql|Db $query): string
|
||||
{
|
||||
return $this->generate($query, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ActiveQuery|Db|mixed $query
|
||||
* @param ActiveQuery|Db|Sql $query
|
||||
* @return string
|
||||
* @throws Exception
|
||||
*/
|
||||
public function count($query)
|
||||
public function count(ActiveQuery|Db|Sql $query): string
|
||||
{
|
||||
return $this->generate($query, true);
|
||||
}
|
||||
@@ -45,7 +46,7 @@ class Select extends BaseObject
|
||||
* @return string
|
||||
* @throws Exception
|
||||
*/
|
||||
private function generate($query, $isCount = false)
|
||||
private function generate(ActiveQuery|Db|Sql $query, $isCount = false): string
|
||||
{
|
||||
if (empty($query->from)) {
|
||||
$query->from = $query->getTable();
|
||||
@@ -78,7 +79,7 @@ class Select extends BaseObject
|
||||
* @param bool $isCount
|
||||
* @return string
|
||||
*/
|
||||
private function builderSelect($select = NULL, $isCount = false)
|
||||
#[Pure] private function builderSelect($select = NULL, $isCount = false): string
|
||||
{
|
||||
if ($isCount === true) {
|
||||
return 'SELECT COUNT(*)';
|
||||
@@ -97,7 +98,7 @@ class Select extends BaseObject
|
||||
* @param $table
|
||||
* @return string
|
||||
*/
|
||||
public function getColumn($table)
|
||||
public function getColumn($table): string
|
||||
{
|
||||
return 'SHOW FULL FIELDS FROM ' . $table;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user