helper.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | ThinkPHP [ WE CAN DO IT JUST THINK ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2006~2025 http://thinkphp.cn All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
  8. // +----------------------------------------------------------------------
  9. // | Author: liu21st <liu21st@gmail.com>
  10. // +----------------------------------------------------------------------
  11. declare (strict_types = 1);
  12. //------------------------
  13. // ThinkORM 助手函数
  14. //-------------------------
  15. use think\db\BaseQuery as Query;
  16. use think\db\Express;
  17. use think\db\Raw;
  18. use think\facade\Db;
  19. if (!function_exists('db')) {
  20. function db(string $name, string|array|null $connect = null): Query
  21. {
  22. if ($connect) {
  23. return Db::connect($connect)->name($name);
  24. }
  25. return Db::name($name);
  26. }
  27. }
  28. if (!function_exists('raw')) {
  29. function raw(string $value, array $bind = []): Raw
  30. {
  31. return new Raw($value, $bind);
  32. }
  33. }
  34. if (!function_exists('inc')) {
  35. function inc(float|int $step = 1, int $lazyTime = 0): Express
  36. {
  37. return new Express('+', $step, $lazyTime);
  38. }
  39. }
  40. if (!function_exists('dec')) {
  41. function dec(float|int $step = 1, int $lazyTime = 0): Express
  42. {
  43. return new Express('-', $step, $lazyTime);
  44. }
  45. }