Commit 621c41cc authored by guozhiyuan's avatar guozhiyuan

update:add skip locked func

parent 8770af2e
......@@ -1459,6 +1459,55 @@ class Medoo
return $result;
}
public function selectForUpdateSkipLocked($table, $columns = null, $where = null, $options = null)
{
$map = [];
$result = [];
$column_map = [];
$index = 0;
$column = $columns;
$is_single = (is_string($column) && $column !== '*');
$query = $this->exec($this->selectContext($table, $map, $columns, $where, null, $options) . ' FOR UPDATE SKIP LOCKED ', $map);
$this->columnMap($columns, $column_map, true);
if (!$this->statement)
{
return false;
}
if ($columns === '*')
{
return $query->fetchAll(PDO::FETCH_ASSOC);
}
while ($data = $query->fetch(PDO::FETCH_ASSOC))
{
$current_stack = [];
$this->dataMap($data, $columns, $column_map, $current_stack, true, $result);
}
if ($is_single)
{
$single_result = [];
$result_key = $column_map[ $column ][ 0 ];
foreach ($result as $item)
{
$single_result[] = $item[ $result_key ];
}
return $single_result;
}
return $result;
}
public function insert($table, $datas)
{
$stack = [];
......
......@@ -37,6 +37,7 @@ use Api\PhpUtils\Log\FileLog;
* @method static MysqlBase select($columns, $where, $options)
* @method static MysqlBase selectMaster($columns, $where, $options)
* @method static MysqlBase selectForUpdate($columns, $where, $options)
* * @method static MysqlBase selectForUpdateSkipLocked($columns, $where, $options)
* @method static MysqlBase getMaster($columns, $where, $options)
* @method static MysqlBase get($columns, $where, $options)
* @method static MysqlBase count($columns, $where)
......@@ -105,6 +106,7 @@ abstract class MysqlBase
"selectMaster", // 或使用/*master*/强制路由,对主从实时性要求较高的场景使用,分布式系统尽量用消息代替查主库等其他方案
"getMaster",
"selectForUpdate",
"selectForUpdateSkipLocked",
"insertDuplicate",
];
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment