ModelIDE.php 61 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * This file is part of Hyperf.
  5. *
  6. * @link https://www.hyperf.io
  7. * @document https://hyperf.wiki
  8. * @contact group@hyperf.io
  9. * @license https://github.com/hyperf/hyperf/blob/master/LICENSE
  10. */
  11. namespace Hyperf\Database\Model;
  12. class ModelIDE
  13. {
  14. /**
  15. * @var Builder
  16. */
  17. protected static $instance;
  18. /**
  19. * Create and return an un-saved model instance.
  20. *
  21. * @param array $attributes
  22. * @return Model|static
  23. */
  24. public static function make($attributes = [])
  25. {
  26. return static::$instance->make($attributes);
  27. }
  28. /**
  29. * Register a new global scope.
  30. *
  31. * @param string $identifier
  32. * @param \Closure|Scope $scope
  33. *
  34. * @return Builder
  35. */
  36. public static function withGlobalScope($identifier, $scope)
  37. {
  38. return static::$instance->withGlobalScope($identifier, $scope);
  39. }
  40. /**
  41. * Remove a registered global scope.
  42. *
  43. * @param Scope|string $scope
  44. * @return Builder
  45. */
  46. public static function withoutGlobalScope($scope)
  47. {
  48. return static::$instance->withoutGlobalScope($scope);
  49. }
  50. /**
  51. * Remove all or passed registered global scopes.
  52. *
  53. * @param null|array $scopes
  54. * @return Builder
  55. */
  56. public static function withoutGlobalScopes($scopes = null)
  57. {
  58. return static::$instance->withoutGlobalScopes($scopes);
  59. }
  60. /**
  61. * Get an array of global scopes that were removed from the query.
  62. *
  63. * @return array
  64. */
  65. public static function removedScopes()
  66. {
  67. return static::$instance->removedScopes();
  68. }
  69. /**
  70. * Add a where clause on the primary key to the query.
  71. *
  72. * @param mixed $id
  73. * @return Builder
  74. */
  75. public static function whereKey($id)
  76. {
  77. return static::$instance->whereKey($id);
  78. }
  79. /**
  80. * Add a where clause on the primary key to the query.
  81. *
  82. * @param mixed $id
  83. * @return Builder
  84. */
  85. public static function whereKeyNot($id)
  86. {
  87. return static::$instance->whereKeyNot($id);
  88. }
  89. /**
  90. * Add a basic where clause to the query.
  91. *
  92. * @param array|\Closure|string $column
  93. * @param mixed $operator
  94. * @param mixed $value
  95. * @param string $boolean
  96. * @return Builder
  97. */
  98. public static function where($column, $operator = null, $value = null, $boolean = 'and')
  99. {
  100. return static::$instance->where($column, $operator, $value, $boolean);
  101. }
  102. /**
  103. * Add an "or where" clause to the query.
  104. *
  105. * @param array|\Closure|string $column
  106. * @param mixed $operator
  107. * @param mixed $value
  108. * @return Builder
  109. */
  110. public static function orWhere($column, $operator = null, $value = null)
  111. {
  112. return static::$instance->orWhere($column, $operator, $value);
  113. }
  114. /**
  115. * Add an "order by" clause for a timestamp to the query.
  116. *
  117. * @param string $column
  118. * @return Builder
  119. */
  120. public static function latest($column = null)
  121. {
  122. return static::$instance->latest($column);
  123. }
  124. /**
  125. * Add an "order by" clause for a timestamp to the query.
  126. *
  127. * @param string $column
  128. * @return Builder
  129. */
  130. public static function oldest($column = null)
  131. {
  132. return static::$instance->oldest($column);
  133. }
  134. /**
  135. * Create a collection of models from plain arrays.
  136. *
  137. * @param array $items
  138. * @return Collection
  139. */
  140. public static function hydrate($items)
  141. {
  142. return static::$instance->hydrate($items);
  143. }
  144. /**
  145. * Create a collection of models from a raw query.
  146. *
  147. * @param string $query
  148. * @param array $bindings
  149. * @return Collection
  150. */
  151. public static function fromQuery($query, $bindings = [])
  152. {
  153. return static::$instance->fromQuery($query, $bindings);
  154. }
  155. /**
  156. * Find a model by its primary key.
  157. *
  158. * @param mixed $id
  159. * @param array $columns
  160. * @return null|Collection|Model|static|static[]
  161. */
  162. public static function find($id, $columns = [])
  163. {
  164. return static::$instance->find($id, $columns);
  165. }
  166. /**
  167. * Find multiple models by their primary keys.
  168. *
  169. * @param array|\Hyperf\Utils\Contracts\Arrayable $ids
  170. * @param array $columns
  171. * @return Collection
  172. */
  173. public static function findMany($ids, $columns = [])
  174. {
  175. return static::$instance->findMany($ids, $columns);
  176. }
  177. /**
  178. * Find a model by its primary key or throw an exception.
  179. *
  180. * @param mixed $id
  181. * @param array $columns
  182. * @throws ModelNotFoundException
  183. * @return Collection|Model|static|static[]
  184. */
  185. public static function findOrFail($id, $columns = [])
  186. {
  187. return static::$instance->findOrFail($id, $columns);
  188. }
  189. /**
  190. * Find a model by its primary key or return fresh model instance.
  191. *
  192. * @param mixed $id
  193. * @param array $columns
  194. * @return Model|static
  195. */
  196. public static function findOrNew($id, $columns = [])
  197. {
  198. return static::$instance->findOrNew($id, $columns);
  199. }
  200. /**
  201. * Get the first record matching the attributes or instantiate it.
  202. *
  203. * @param array $attributes
  204. * @param array $values
  205. * @return Model|static
  206. */
  207. public static function firstOrNew($attributes = [], $values = [])
  208. {
  209. return static::$instance->firstOrNew($attributes, $values);
  210. }
  211. /**
  212. * Get the first record matching the attributes or create it.
  213. *
  214. * @param array $attributes
  215. * @param array $values
  216. * @return Model|static
  217. */
  218. public static function firstOrCreate($attributes, $values = [])
  219. {
  220. return static::$instance->firstOrCreate($attributes, $values);
  221. }
  222. /**
  223. * Create or update a record matching the attributes, and fill it with values.
  224. *
  225. * @param array $attributes
  226. * @param array $values
  227. * @return Model|static
  228. */
  229. public static function updateOrCreate($attributes, $values = [])
  230. {
  231. return static::$instance->updateOrCreate($attributes, $values);
  232. }
  233. /**
  234. * Execute the query and get the first result or throw an exception.
  235. *
  236. * @param array $columns
  237. * @throws ModelNotFoundException
  238. * @return Model|static
  239. */
  240. public static function firstOrFail($columns = [])
  241. {
  242. return static::$instance->firstOrFail($columns);
  243. }
  244. /**
  245. * Execute the query and get the first result or call a callback.
  246. *
  247. * @param array|\Closure $columns
  248. * @param null|\Closure $callback
  249. * @return mixed|Model|static
  250. */
  251. public static function firstOr($columns = [], $callback = null)
  252. {
  253. return static::$instance->firstOr($columns, $callback);
  254. }
  255. /**
  256. * Get a single column's value from the first result of a query.
  257. *
  258. * @param string $column
  259. * @return mixed
  260. */
  261. public static function value($column)
  262. {
  263. return static::$instance->value($column);
  264. }
  265. /**
  266. * Execute the query as a "select" statement.
  267. *
  268. * @param array|string $columns
  269. * @return Collection|static[]
  270. */
  271. public static function get($columns = [])
  272. {
  273. return static::$instance->get($columns);
  274. }
  275. /**
  276. * Get the hydrated models without eager loading.
  277. *
  278. * @param array|string $columns
  279. * @return Model[]|static[]
  280. */
  281. public static function getModels($columns = [])
  282. {
  283. return static::$instance->getModels($columns);
  284. }
  285. /**
  286. * Eager load the relationships for the models.
  287. *
  288. * @param array $models
  289. * @return array
  290. */
  291. public static function eagerLoadRelations($models)
  292. {
  293. return static::$instance->eagerLoadRelations($models);
  294. }
  295. /**
  296. * Get a lazy collection for the given query.
  297. *
  298. * @return \Generator
  299. */
  300. public static function cursor()
  301. {
  302. return static::$instance->cursor();
  303. }
  304. /**
  305. * Get an array with the values of a given column.
  306. *
  307. * @param string $column
  308. * @param null|string $key
  309. * @return \Hyperf\Utils\Collection
  310. */
  311. public static function pluck($column, $key = null)
  312. {
  313. return static::$instance->pluck($column, $key);
  314. }
  315. /**
  316. * Paginate the given query.
  317. *
  318. * @param null|int $perPage
  319. * @param array $columns
  320. * @param string $pageName
  321. * @param null|int $page
  322. * @throws \InvalidArgumentException
  323. * @return \Hyperf\Contract\LengthAwarePaginatorInterface
  324. */
  325. public static function paginate($perPage = null, $columns = [], $pageName = 'page', $page = null)
  326. {
  327. return static::$instance->paginate($perPage, $columns, $pageName, $page);
  328. }
  329. /**
  330. * Paginate the given query into a simple paginator.
  331. *
  332. * @param null|int $perPage
  333. * @param array $columns
  334. * @param string $pageName
  335. * @param null|int $page
  336. * @return \Hyperf\Contract\PaginatorInterface
  337. */
  338. public static function simplePaginate($perPage = null, $columns = [], $pageName = 'page', $page = null)
  339. {
  340. return static::$instance->simplePaginate($perPage, $columns, $pageName, $page);
  341. }
  342. /**
  343. * Save a new model and return the instance.
  344. *
  345. * @param array $attributes
  346. * @return $this|Model
  347. */
  348. public static function create($attributes = [])
  349. {
  350. return static::$instance->create($attributes);
  351. }
  352. /**
  353. * Save a new model and return the instance. Allow mass-assignment.
  354. *
  355. * @param array $attributes
  356. * @return $this|Model
  357. */
  358. public static function forceCreate($attributes)
  359. {
  360. return static::$instance->forceCreate($attributes);
  361. }
  362. /**
  363. * Register a replacement for the default delete function.
  364. *
  365. * @param \Closure $callback
  366. */
  367. public static function onDelete($callback)
  368. {
  369. static::$instance->onDelete($callback);
  370. }
  371. /**
  372. * Call the given local model scopes.
  373. *
  374. * @param array|string $scopes
  375. * @return mixed|static
  376. */
  377. public static function scopes($scopes)
  378. {
  379. return static::$instance->scopes($scopes);
  380. }
  381. /**
  382. * Apply the scopes to the Eloquent builder instance and return it.
  383. *
  384. * @return Builder
  385. */
  386. public static function applyScopes()
  387. {
  388. return static::$instance->applyScopes();
  389. }
  390. /**
  391. * Prevent the specified relations from being eager loaded.
  392. *
  393. * @param mixed $relations
  394. * @return Builder
  395. */
  396. public static function without($relations)
  397. {
  398. return static::$instance->without($relations);
  399. }
  400. /**
  401. * Create a new instance of the model being queried.
  402. *
  403. * @param array $attributes
  404. * @return Model|static
  405. */
  406. public static function newModelInstance($attributes = [])
  407. {
  408. return static::$instance->newModelInstance($attributes);
  409. }
  410. /**
  411. * Apply query-time casts to the model instance.
  412. *
  413. * @param array $casts
  414. * @return Builder
  415. */
  416. public static function withCasts($casts)
  417. {
  418. return static::$instance->withCasts($casts);
  419. }
  420. /**
  421. * Get the underlying query builder instance.
  422. *
  423. * @return \Hyperf\Database\Query\Builder
  424. */
  425. public static function getQuery()
  426. {
  427. return static::$instance->getQuery();
  428. }
  429. /**
  430. * Set the underlying query builder instance.
  431. *
  432. * @param \Hyperf\Database\Query\Builder $query
  433. * @return Builder
  434. */
  435. public static function setQuery($query)
  436. {
  437. return static::$instance->setQuery($query);
  438. }
  439. /**
  440. * Get a base query builder instance.
  441. *
  442. * @return \Hyperf\Database\Query\Builder
  443. */
  444. public static function toBase()
  445. {
  446. return static::$instance->toBase();
  447. }
  448. /**
  449. * Get the relationships being eagerly loaded.
  450. *
  451. * @return array
  452. */
  453. public static function getEagerLoads()
  454. {
  455. return static::$instance->getEagerLoads();
  456. }
  457. /**
  458. * Set the relationships being eagerly loaded.
  459. *
  460. * @param array $eagerLoad
  461. * @return Builder
  462. */
  463. public static function setEagerLoads($eagerLoad)
  464. {
  465. return static::$instance->setEagerLoads($eagerLoad);
  466. }
  467. /**
  468. * Get the model instance being queried.
  469. *
  470. * @return Model|static
  471. */
  472. public static function getModel()
  473. {
  474. return static::$instance->getModel();
  475. }
  476. /**
  477. * Set a model instance for the model being queried.
  478. *
  479. * @param Model $model
  480. * @return Builder
  481. */
  482. public static function setModel($model)
  483. {
  484. return static::$instance->setModel($model);
  485. }
  486. /**
  487. * Get the given macro by name.
  488. *
  489. * @param string $name
  490. * @return \Closure
  491. */
  492. public static function getMacro($name)
  493. {
  494. return static::$instance->getMacro($name);
  495. }
  496. /**
  497. * Checks if a macro is registered.
  498. *
  499. * @param string $name
  500. * @return bool
  501. */
  502. public static function hasMacro($name)
  503. {
  504. return static::$instance::hasMacro($name);
  505. }
  506. /**
  507. * Chunk the results of the query.
  508. *
  509. * @param int $count
  510. * @param callable $callback
  511. * @return bool
  512. */
  513. public static function chunk($count, $callback)
  514. {
  515. return static::$instance->chunk($count, $callback);
  516. }
  517. /**
  518. * Execute a callback over each item while chunking.
  519. *
  520. * @param callable $callback
  521. * @param int $count
  522. * @return bool
  523. */
  524. public static function each($callback, $count = 1000)
  525. {
  526. return static::$instance->each($callback, $count);
  527. }
  528. /**
  529. * Chunk the results of a query by comparing IDs.
  530. *
  531. * @param int $count
  532. * @param callable $callback
  533. * @param null|string $column
  534. * @param null|string $alias
  535. * @return bool
  536. */
  537. public static function chunkById($count, $callback, $column = null, $alias = null)
  538. {
  539. return static::$instance->chunkById($count, $callback, $column, $alias);
  540. }
  541. /**
  542. * Execute the query and get the first result.
  543. *
  544. * @param array|string $columns
  545. * @return null|Model|object|static
  546. */
  547. public static function first($columns = [])
  548. {
  549. return static::$instance->first($columns);
  550. }
  551. /**
  552. * Apply the callback's query changes if the given "value" is true.
  553. *
  554. * @param mixed $value
  555. * @param callable $callback
  556. * @param null|callable $default
  557. * @return $this|mixed
  558. */
  559. public static function when($value, $callback, $default = null)
  560. {
  561. return static::$instance->when($value, $callback, $default);
  562. }
  563. /**
  564. * Pass the query to a given callback.
  565. *
  566. * @param callable $callback
  567. * @return \Hyperf\Database\Query\Builder
  568. */
  569. public static function tap($callback)
  570. {
  571. return static::$instance->tap($callback);
  572. }
  573. /**
  574. * Apply the callback's query changes if the given "value" is false.
  575. *
  576. * @param mixed $value
  577. * @param callable $callback
  578. * @param null|callable $default
  579. * @return $this|mixed
  580. */
  581. public static function unless($value, $callback, $default = null)
  582. {
  583. return static::$instance->unless($value, $callback, $default);
  584. }
  585. /**
  586. * Add a relationship count / exists condition to the query.
  587. *
  588. * @param \Hyperf\Database\Model\Relations\Relation|string $relation
  589. * @param string $operator
  590. * @param int $count
  591. * @param string $boolean
  592. * @param null|\Closure $callback
  593. * @throws \RuntimeException
  594. * @return Builder|static
  595. */
  596. public static function has($relation, $operator = '>=', $count = 1, $boolean = 'and', $callback = null)
  597. {
  598. return static::$instance->has($relation, $operator, $count, $boolean, $callback);
  599. }
  600. /**
  601. * Add a relationship count / exists condition to the query with an "or".
  602. *
  603. * @param string $relation
  604. * @param string $operator
  605. * @param int $count
  606. * @return Builder|static
  607. */
  608. public static function orHas($relation, $operator = '>=', $count = 1)
  609. {
  610. return static::$instance->orHas($relation, $operator, $count);
  611. }
  612. /**
  613. * Add a relationship count / exists condition to the query.
  614. *
  615. * @param string $relation
  616. * @param string $boolean
  617. * @param null|\Closure $callback
  618. * @return Builder|static
  619. */
  620. public static function doesntHave($relation, $boolean = 'and', $callback = null)
  621. {
  622. return static::$instance->doesntHave($relation, $boolean, $callback);
  623. }
  624. /**
  625. * Add a relationship count / exists condition to the query with an "or".
  626. *
  627. * @param string $relation
  628. * @return Builder|static
  629. */
  630. public static function orDoesntHave($relation)
  631. {
  632. return static::$instance->orDoesntHave($relation);
  633. }
  634. /**
  635. * Add a relationship count / exists condition to the query with where clauses.
  636. *
  637. * @param string $relation
  638. * @param null|\Closure $callback
  639. * @param string $operator
  640. * @param int $count
  641. * @return Builder|static
  642. */
  643. public static function whereHas($relation, $callback = null, $operator = '>=', $count = 1)
  644. {
  645. return static::$instance->whereHas($relation, $callback, $operator, $count);
  646. }
  647. /**
  648. * Add a relationship count / exists condition to the query with where clauses and an "or".
  649. *
  650. * @param string $relation
  651. * @param null|\Closure $callback
  652. * @param string $operator
  653. * @param int $count
  654. * @return Builder|static
  655. */
  656. public static function orWhereHas($relation, $callback = null, $operator = '>=', $count = 1)
  657. {
  658. return static::$instance->orWhereHas($relation, $callback, $operator, $count);
  659. }
  660. /**
  661. * Add a relationship count / exists condition to the query with where clauses.
  662. *
  663. * @param string $relation
  664. * @param null|\Closure $callback
  665. * @return Builder|static
  666. */
  667. public static function whereDoesntHave($relation, $callback = null)
  668. {
  669. return static::$instance->whereDoesntHave($relation, $callback);
  670. }
  671. /**
  672. * Add a relationship count / exists condition to the query with where clauses and an "or".
  673. *
  674. * @param string $relation
  675. * @param null|\Closure $callback
  676. * @return Builder|static
  677. */
  678. public static function orWhereDoesntHave($relation, $callback = null)
  679. {
  680. return static::$instance->orWhereDoesntHave($relation, $callback);
  681. }
  682. /**
  683. * Add a polymorphic relationship count / exists condition to the query.
  684. *
  685. * @param string $relation
  686. * @param array|string $types
  687. * @param string $operator
  688. * @param int $count
  689. * @param string $boolean
  690. * @param null|\Closure $callback
  691. * @return Builder|static
  692. */
  693. public static function hasMorph($relation, $types, $operator = '>=', $count = 1, $boolean = 'and', $callback = null)
  694. {
  695. return static::$instance->hasMorph($relation, $types, $operator, $count, $boolean, $callback);
  696. }
  697. /**
  698. * Add a polymorphic relationship count / exists condition to the query.
  699. *
  700. * @param string $relation
  701. * @param array|string $types
  702. * @param string $boolean
  703. * @param null|\Closure $callback
  704. * @return Builder|static
  705. */
  706. public static function doesntHaveMorph($relation, $types, $boolean = 'and', $callback = null)
  707. {
  708. return static::$instance->doesntHaveMorph($relation, $types, $boolean, $callback);
  709. }
  710. /**
  711. * Add a polymorphic relationship count / exists condition to the query with where clauses.
  712. *
  713. * @param string $relation
  714. * @param array|string $types
  715. * @param null|\Closure $callback
  716. * @param string $operator
  717. * @param int $count
  718. * @return Builder|static
  719. */
  720. public static function whereHasMorph($relation, $types, $callback = null, $operator = '>=', $count = 1)
  721. {
  722. return static::$instance->whereHasMorph($relation, $types, $callback, $operator, $count);
  723. }
  724. /**
  725. * Add a polymorphic relationship count / exists condition to the query with where clauses and an "or".
  726. *
  727. * @param string $relation
  728. * @param array|string $types
  729. * @param null|\Closure $callback
  730. * @param string $operator
  731. * @param int $count
  732. * @return Builder|static
  733. */
  734. public static function orWhereHasMorph($relation, $types, $callback = null, $operator = '>=', $count = 1)
  735. {
  736. return static::$instance->orWhereHasMorph($relation, $types, $callback, $operator, $count);
  737. }
  738. /**
  739. * Add a polymorphic relationship count / exists condition to the query with where clauses.
  740. *
  741. * @param string $relation
  742. * @param array|string $types
  743. * @param null|\Closure $callback
  744. * @return Builder|static
  745. */
  746. public static function whereDoesntHaveMorph($relation, $types, $callback = null)
  747. {
  748. return static::$instance->whereDoesntHaveMorph($relation, $types, $callback);
  749. }
  750. /**
  751. * Add a polymorphic relationship count / exists condition to the query with where clauses and an "or".
  752. *
  753. * @param string $relation
  754. * @param array|string $types
  755. * @param null|\Closure $callback
  756. * @return Builder|static
  757. */
  758. public static function orWhereDoesntHaveMorph($relation, $types, $callback = null)
  759. {
  760. return static::$instance->orWhereDoesntHaveMorph($relation, $types, $callback);
  761. }
  762. /**
  763. * Add subselect queries to count the relations.
  764. *
  765. * @param mixed $relations
  766. * @return Builder
  767. */
  768. public static function withCount($relations)
  769. {
  770. return static::$instance->withCount($relations);
  771. }
  772. /**
  773. * Merge the where constraints from another query to the current query.
  774. *
  775. * @param Builder $from
  776. * @return Builder|static
  777. */
  778. public static function mergeConstraintsFrom($from)
  779. {
  780. return static::$instance->mergeConstraintsFrom($from);
  781. }
  782. /**
  783. * Set the columns to be selected.
  784. *
  785. * @param array|mixed $columns
  786. * @return \Hyperf\Database\Query\Builder
  787. */
  788. public static function select($columns = [])
  789. {
  790. return static::$instance->select($columns);
  791. }
  792. /**
  793. * Add a subselect expression to the query.
  794. *
  795. * @param \Closure|\Hyperf\Database\Query\Builder|string $query
  796. * @param string $as
  797. * @throws \InvalidArgumentException
  798. * @return \Hyperf\Database\Query\Builder
  799. */
  800. public static function selectSub($query, $as)
  801. {
  802. return static::$instance->selectSub($query, $as);
  803. }
  804. /**
  805. * Add a new "raw" select expression to the query.
  806. *
  807. * @param string $expression
  808. * @param array $bindings
  809. * @return \Hyperf\Database\Query\Builder
  810. */
  811. public static function selectRaw($expression, $bindings = [])
  812. {
  813. return static::$instance->selectRaw($expression, $bindings);
  814. }
  815. /**
  816. * Makes "from" fetch from a subquery.
  817. *
  818. * @param \Closure|\Hyperf\Database\Query\Builder|string $query
  819. * @param string $as
  820. * @throws \InvalidArgumentException
  821. * @return \Hyperf\Database\Query\Builder
  822. */
  823. public static function fromSub($query, $as)
  824. {
  825. return static::$instance->fromSub($query, $as);
  826. }
  827. /**
  828. * Add a raw from clause to the query.
  829. *
  830. * @param string $expression
  831. * @param mixed $bindings
  832. * @return \Hyperf\Database\Query\Builder
  833. */
  834. public static function fromRaw($expression, $bindings = [])
  835. {
  836. return static::$instance->fromRaw($expression, $bindings);
  837. }
  838. /**
  839. * Add a new select column to the query.
  840. *
  841. * @param array|mixed $column
  842. * @return \Hyperf\Database\Query\Builder
  843. */
  844. public static function addSelect($column)
  845. {
  846. return static::$instance->addSelect($column);
  847. }
  848. /**
  849. * Force the query to only return distinct results.
  850. *
  851. * @return \Hyperf\Database\Query\Builder
  852. */
  853. public static function distinct()
  854. {
  855. return static::$instance->distinct();
  856. }
  857. /**
  858. * Set the table which the query is targeting.
  859. *
  860. * @param \Closure|\Hyperf\Database\Query\Builder|string $table
  861. * @return \Hyperf\Database\Query\Builder
  862. */
  863. public static function from($table)
  864. {
  865. return static::$instance->from($table);
  866. }
  867. /**
  868. * Add a join clause to the query.
  869. *
  870. * @param string $table
  871. * @param \Closure|string $first
  872. * @param null|string $operator
  873. * @param null|string $second
  874. * @param string $type
  875. * @param bool $where
  876. * @return \Hyperf\Database\Query\Builder
  877. */
  878. public static function join($table, $first, $operator = null, $second = null, $type = 'inner', $where = false)
  879. {
  880. return static::$instance->join($table, $first, $operator, $second, $type, $where);
  881. }
  882. /**
  883. * Add a "join where" clause to the query.
  884. *
  885. * @param string $table
  886. * @param \Closure|string $first
  887. * @param string $operator
  888. * @param string $second
  889. * @param string $type
  890. * @return \Hyperf\Database\Query\Builder
  891. */
  892. public static function joinWhere($table, $first, $operator, $second, $type = 'inner')
  893. {
  894. return static::$instance->joinWhere($table, $first, $operator, $second, $type);
  895. }
  896. /**
  897. * Add a subquery join clause to the query.
  898. *
  899. * @param \Closure|\Hyperf\Database\Query\Builder|string $query
  900. * @param string $as
  901. * @param \Closure|string $first
  902. * @param null|string $operator
  903. * @param null|string $second
  904. * @param string $type
  905. * @param bool $where
  906. * @throws \InvalidArgumentException
  907. * @return \Hyperf\Database\Query\Builder
  908. */
  909. public static function joinSub($query, $as, $first, $operator = null, $second = null, $type = 'inner', $where = false)
  910. {
  911. return static::$instance->joinSub($query, $as, $first, $operator, $second, $type, $where);
  912. }
  913. /**
  914. * Add a left join to the query.
  915. *
  916. * @param string $table
  917. * @param \Closure|string $first
  918. * @param null|string $operator
  919. * @param null|string $second
  920. * @return \Hyperf\Database\Query\Builder
  921. */
  922. public static function leftJoin($table, $first, $operator = null, $second = null)
  923. {
  924. return static::$instance->leftJoin($table, $first, $operator, $second);
  925. }
  926. /**
  927. * Add a "join where" clause to the query.
  928. *
  929. * @param string $table
  930. * @param \Closure|string $first
  931. * @param string $operator
  932. * @param string $second
  933. * @return \Hyperf\Database\Query\Builder
  934. */
  935. public static function leftJoinWhere($table, $first, $operator, $second)
  936. {
  937. return static::$instance->leftJoinWhere($table, $first, $operator, $second);
  938. }
  939. /**
  940. * Add a subquery left join to the query.
  941. *
  942. * @param \Closure|\Hyperf\Database\Query\Builder|string $query
  943. * @param string $as
  944. * @param \Closure|string $first
  945. * @param null|string $operator
  946. * @param null|string $second
  947. * @return \Hyperf\Database\Query\Builder
  948. */
  949. public static function leftJoinSub($query, $as, $first, $operator = null, $second = null)
  950. {
  951. return static::$instance->leftJoinSub($query, $as, $first, $operator, $second);
  952. }
  953. /**
  954. * Add a right join to the query.
  955. *
  956. * @param string $table
  957. * @param \Closure|string $first
  958. * @param null|string $operator
  959. * @param null|string $second
  960. * @return \Hyperf\Database\Query\Builder
  961. */
  962. public static function rightJoin($table, $first, $operator = null, $second = null)
  963. {
  964. return static::$instance->rightJoin($table, $first, $operator, $second);
  965. }
  966. /**
  967. * Add a "right join where" clause to the query.
  968. *
  969. * @param string $table
  970. * @param \Closure|string $first
  971. * @param string $operator
  972. * @param string $second
  973. * @return \Hyperf\Database\Query\Builder
  974. */
  975. public static function rightJoinWhere($table, $first, $operator, $second)
  976. {
  977. return static::$instance->rightJoinWhere($table, $first, $operator, $second);
  978. }
  979. /**
  980. * Add a subquery right join to the query.
  981. *
  982. * @param \Closure|\Hyperf\Database\Query\Builder|string $query
  983. * @param string $as
  984. * @param \Closure|string $first
  985. * @param null|string $operator
  986. * @param null|string $second
  987. * @return \Hyperf\Database\Query\Builder
  988. */
  989. public static function rightJoinSub($query, $as, $first, $operator = null, $second = null)
  990. {
  991. return static::$instance->rightJoinSub($query, $as, $first, $operator, $second);
  992. }
  993. /**
  994. * Add a "cross join" clause to the query.
  995. *
  996. * @param string $table
  997. * @param null|\Closure|string $first
  998. * @param null|string $operator
  999. * @param null|string $second
  1000. * @return \Hyperf\Database\Query\Builder
  1001. */
  1002. public static function crossJoin($table, $first = null, $operator = null, $second = null)
  1003. {
  1004. return static::$instance->crossJoin($table, $first, $operator, $second);
  1005. }
  1006. /**
  1007. * Merge an array of where clauses and bindings.
  1008. *
  1009. * @param array $wheres
  1010. * @param array $bindings
  1011. */
  1012. public static function mergeWheres($wheres, $bindings)
  1013. {
  1014. static::$instance->mergeWheres($wheres, $bindings);
  1015. }
  1016. /**
  1017. * Prepare the value and operator for a where clause.
  1018. *
  1019. * @param string $value
  1020. * @param string $operator
  1021. * @param bool $useDefault
  1022. * @throws \InvalidArgumentException
  1023. * @return array
  1024. */
  1025. public static function prepareValueAndOperator($value, $operator, $useDefault = false)
  1026. {
  1027. return static::$instance->prepareValueAndOperator($value, $operator, $useDefault);
  1028. }
  1029. /**
  1030. * Add a "where" clause comparing two columns to the query.
  1031. *
  1032. * @param array|string $first
  1033. * @param null|string $operator
  1034. * @param null|string $second
  1035. * @param null|string $boolean
  1036. * @return \Hyperf\Database\Query\Builder
  1037. */
  1038. public static function whereColumn($first, $operator = null, $second = null, $boolean = 'and')
  1039. {
  1040. return static::$instance->whereColumn($first, $operator, $second, $boolean);
  1041. }
  1042. /**
  1043. * Add an "or where" clause comparing two columns to the query.
  1044. *
  1045. * @param array|string $first
  1046. * @param null|string $operator
  1047. * @param null|string $second
  1048. * @return \Hyperf\Database\Query\Builder
  1049. */
  1050. public static function orWhereColumn($first, $operator = null, $second = null)
  1051. {
  1052. return static::$instance->orWhereColumn($first, $operator, $second);
  1053. }
  1054. /**
  1055. * Add a raw where clause to the query.
  1056. *
  1057. * @param string $sql
  1058. * @param mixed $bindings
  1059. * @param string $boolean
  1060. * @return \Hyperf\Database\Query\Builder
  1061. */
  1062. public static function whereRaw($sql, $bindings = [], $boolean = 'and')
  1063. {
  1064. return static::$instance->whereRaw($sql, $bindings, $boolean);
  1065. }
  1066. /**
  1067. * Add a raw or where clause to the query.
  1068. *
  1069. * @param string $sql
  1070. * @param mixed $bindings
  1071. * @return \Hyperf\Database\Query\Builder
  1072. */
  1073. public static function orWhereRaw($sql, $bindings = [])
  1074. {
  1075. return static::$instance->orWhereRaw($sql, $bindings);
  1076. }
  1077. /**
  1078. * Add a "where in" clause to the query.
  1079. *
  1080. * @param string $column
  1081. * @param mixed $values
  1082. * @param string $boolean
  1083. * @param bool $not
  1084. * @return \Hyperf\Database\Query\Builder
  1085. */
  1086. public static function whereIn($column, $values, $boolean = 'and', $not = false)
  1087. {
  1088. return static::$instance->whereIn($column, $values, $boolean, $not);
  1089. }
  1090. /**
  1091. * Add an "or where in" clause to the query.
  1092. *
  1093. * @param string $column
  1094. * @param mixed $values
  1095. * @return \Hyperf\Database\Query\Builder
  1096. */
  1097. public static function orWhereIn($column, $values)
  1098. {
  1099. return static::$instance->orWhereIn($column, $values);
  1100. }
  1101. /**
  1102. * Add a "where not in" clause to the query.
  1103. *
  1104. * @param string $column
  1105. * @param mixed $values
  1106. * @param string $boolean
  1107. * @return \Hyperf\Database\Query\Builder
  1108. */
  1109. public static function whereNotIn($column, $values, $boolean = 'and')
  1110. {
  1111. return static::$instance->whereNotIn($column, $values, $boolean);
  1112. }
  1113. /**
  1114. * Add an "or where not in" clause to the query.
  1115. *
  1116. * @param string $column
  1117. * @param mixed $values
  1118. * @return \Hyperf\Database\Query\Builder
  1119. */
  1120. public static function orWhereNotIn($column, $values)
  1121. {
  1122. return static::$instance->orWhereNotIn($column, $values);
  1123. }
  1124. /**
  1125. * Add a "where in raw" clause for integer values to the query.
  1126. *
  1127. * @param string $column
  1128. * @param array|\Hyperf\Utils\Contracts\Arrayable $values
  1129. * @param string $boolean
  1130. * @param bool $not
  1131. * @return \Hyperf\Database\Query\Builder
  1132. */
  1133. public static function whereIntegerInRaw($column, $values, $boolean = 'and', $not = false)
  1134. {
  1135. return static::$instance->whereIntegerInRaw($column, $values, $boolean, $not);
  1136. }
  1137. /**
  1138. * Add a "where not in raw" clause for integer values to the query.
  1139. *
  1140. * @param string $column
  1141. * @param array|\Hyperf\Utils\Contracts\Arrayable $values
  1142. * @param string $boolean
  1143. * @return \Hyperf\Database\Query\Builder
  1144. */
  1145. public static function whereIntegerNotInRaw($column, $values, $boolean = 'and')
  1146. {
  1147. return static::$instance->whereIntegerNotInRaw($column, $values, $boolean);
  1148. }
  1149. /**
  1150. * Add a "where null" clause to the query.
  1151. *
  1152. * @param array|string $columns
  1153. * @param string $boolean
  1154. * @param bool $not
  1155. * @return \Hyperf\Database\Query\Builder
  1156. */
  1157. public static function whereNull($columns, $boolean = 'and', $not = false)
  1158. {
  1159. return static::$instance->whereNull($columns, $boolean, $not);
  1160. }
  1161. /**
  1162. * Add an "or where null" clause to the query.
  1163. *
  1164. * @param string $column
  1165. * @return \Hyperf\Database\Query\Builder
  1166. */
  1167. public static function orWhereNull($column)
  1168. {
  1169. return static::$instance->orWhereNull($column);
  1170. }
  1171. /**
  1172. * Add a "where not null" clause to the query.
  1173. *
  1174. * @param array|string $columns
  1175. * @param string $boolean
  1176. * @return \Hyperf\Database\Query\Builder
  1177. */
  1178. public static function whereNotNull($columns, $boolean = 'and')
  1179. {
  1180. return static::$instance->whereNotNull($columns, $boolean);
  1181. }
  1182. /**
  1183. * Add a where between statement to the query.
  1184. *
  1185. * @param string $column
  1186. * @param array $values
  1187. * @param string $boolean
  1188. * @param bool $not
  1189. * @return \Hyperf\Database\Query\Builder
  1190. */
  1191. public static function whereBetween($column, $values, $boolean = 'and', $not = false)
  1192. {
  1193. return static::$instance->whereBetween($column, $values, $boolean, $not);
  1194. }
  1195. /**
  1196. * Add an or where between statement to the query.
  1197. *
  1198. * @param string $column
  1199. * @param array $values
  1200. * @return \Hyperf\Database\Query\Builder
  1201. */
  1202. public static function orWhereBetween($column, $values)
  1203. {
  1204. return static::$instance->orWhereBetween($column, $values);
  1205. }
  1206. /**
  1207. * Add a where not between statement to the query.
  1208. *
  1209. * @param string $column
  1210. * @param array $values
  1211. * @param string $boolean
  1212. * @return \Hyperf\Database\Query\Builder
  1213. */
  1214. public static function whereNotBetween($column, $values, $boolean = 'and')
  1215. {
  1216. return static::$instance->whereNotBetween($column, $values, $boolean);
  1217. }
  1218. /**
  1219. * Add an or where not between statement to the query.
  1220. *
  1221. * @param string $column
  1222. * @param array $values
  1223. * @return \Hyperf\Database\Query\Builder
  1224. */
  1225. public static function orWhereNotBetween($column, $values)
  1226. {
  1227. return static::$instance->orWhereNotBetween($column, $values);
  1228. }
  1229. /**
  1230. * Add an "or where not null" clause to the query.
  1231. *
  1232. * @param string $column
  1233. * @return \Hyperf\Database\Query\Builder
  1234. */
  1235. public static function orWhereNotNull($column)
  1236. {
  1237. return static::$instance->orWhereNotNull($column);
  1238. }
  1239. /**
  1240. * Add a "where date" statement to the query.
  1241. *
  1242. * @param string $column
  1243. * @param string $operator
  1244. * @param null|\DateTimeInterface|string $value
  1245. * @param string $boolean
  1246. * @return \Hyperf\Database\Query\Builder
  1247. */
  1248. public static function whereDate($column, $operator, $value = null, $boolean = 'and')
  1249. {
  1250. return static::$instance->whereDate($column, $operator, $value, $boolean);
  1251. }
  1252. /**
  1253. * Add an "or where date" statement to the query.
  1254. *
  1255. * @param string $column
  1256. * @param string $operator
  1257. * @param null|\DateTimeInterface|string $value
  1258. * @return \Hyperf\Database\Query\Builder
  1259. */
  1260. public static function orWhereDate($column, $operator, $value = null)
  1261. {
  1262. return static::$instance->orWhereDate($column, $operator, $value);
  1263. }
  1264. /**
  1265. * Add a "where time" statement to the query.
  1266. *
  1267. * @param string $column
  1268. * @param string $operator
  1269. * @param null|\DateTimeInterface|string $value
  1270. * @param string $boolean
  1271. * @return \Hyperf\Database\Query\Builder
  1272. */
  1273. public static function whereTime($column, $operator, $value = null, $boolean = 'and')
  1274. {
  1275. return static::$instance->whereTime($column, $operator, $value, $boolean);
  1276. }
  1277. /**
  1278. * Add an "or where time" statement to the query.
  1279. *
  1280. * @param string $column
  1281. * @param string $operator
  1282. * @param null|\DateTimeInterface|string $value
  1283. * @return \Hyperf\Database\Query\Builder
  1284. */
  1285. public static function orWhereTime($column, $operator, $value = null)
  1286. {
  1287. return static::$instance->orWhereTime($column, $operator, $value);
  1288. }
  1289. /**
  1290. * Add a "where day" statement to the query.
  1291. *
  1292. * @param string $column
  1293. * @param string $operator
  1294. * @param null|\DateTimeInterface|string $value
  1295. * @param string $boolean
  1296. * @return \Hyperf\Database\Query\Builder
  1297. */
  1298. public static function whereDay($column, $operator, $value = null, $boolean = 'and')
  1299. {
  1300. return static::$instance->whereDay($column, $operator, $value, $boolean);
  1301. }
  1302. /**
  1303. * Add an "or where day" statement to the query.
  1304. *
  1305. * @param string $column
  1306. * @param string $operator
  1307. * @param null|\DateTimeInterface|string $value
  1308. * @return \Hyperf\Database\Query\Builder
  1309. */
  1310. public static function orWhereDay($column, $operator, $value = null)
  1311. {
  1312. return static::$instance->orWhereDay($column, $operator, $value);
  1313. }
  1314. /**
  1315. * Add a "where month" statement to the query.
  1316. *
  1317. * @param string $column
  1318. * @param string $operator
  1319. * @param null|\DateTimeInterface|string $value
  1320. * @param string $boolean
  1321. * @return \Hyperf\Database\Query\Builder
  1322. */
  1323. public static function whereMonth($column, $operator, $value = null, $boolean = 'and')
  1324. {
  1325. return static::$instance->whereMonth($column, $operator, $value, $boolean);
  1326. }
  1327. /**
  1328. * Add an "or where month" statement to the query.
  1329. *
  1330. * @param string $column
  1331. * @param string $operator
  1332. * @param null|\DateTimeInterface|string $value
  1333. * @return \Hyperf\Database\Query\Builder
  1334. */
  1335. public static function orWhereMonth($column, $operator, $value = null)
  1336. {
  1337. return static::$instance->orWhereMonth($column, $operator, $value);
  1338. }
  1339. /**
  1340. * Add a "where year" statement to the query.
  1341. *
  1342. * @param string $column
  1343. * @param string $operator
  1344. * @param null|\DateTimeInterface|int|string $value
  1345. * @param string $boolean
  1346. * @return \Hyperf\Database\Query\Builder
  1347. */
  1348. public static function whereYear($column, $operator, $value = null, $boolean = 'and')
  1349. {
  1350. return static::$instance->whereYear($column, $operator, $value, $boolean);
  1351. }
  1352. /**
  1353. * Add an "or where year" statement to the query.
  1354. *
  1355. * @param string $column
  1356. * @param string $operator
  1357. * @param null|\DateTimeInterface|int|string $value
  1358. * @return \Hyperf\Database\Query\Builder
  1359. */
  1360. public static function orWhereYear($column, $operator, $value = null)
  1361. {
  1362. return static::$instance->orWhereYear($column, $operator, $value);
  1363. }
  1364. /**
  1365. * Add a nested where statement to the query.
  1366. *
  1367. * @param \Closure $callback
  1368. * @param string $boolean
  1369. * @return \Hyperf\Database\Query\Builder
  1370. */
  1371. public static function whereNested($callback, $boolean = 'and')
  1372. {
  1373. return static::$instance->whereNested($callback, $boolean);
  1374. }
  1375. /**
  1376. * Create a new query instance for nested where condition.
  1377. *
  1378. * @return \Hyperf\Database\Query\Builder
  1379. */
  1380. public static function forNestedWhere()
  1381. {
  1382. return static::$instance->forNestedWhere();
  1383. }
  1384. /**
  1385. * Add another query builder as a nested where to the query builder.
  1386. *
  1387. * @param $this $query
  1388. * @param string $boolean
  1389. * @param mixed $query
  1390. * @return \Hyperf\Database\Query\Builder
  1391. */
  1392. public static function addNestedWhereQuery($query, $boolean = 'and')
  1393. {
  1394. return static::$instance->addNestedWhereQuery($query, $boolean);
  1395. }
  1396. /**
  1397. * Add an exists clause to the query.
  1398. *
  1399. * @param \Closure $callback
  1400. * @param string $boolean
  1401. * @param bool $not
  1402. * @return \Hyperf\Database\Query\Builder
  1403. */
  1404. public static function whereExists($callback, $boolean = 'and', $not = false)
  1405. {
  1406. return static::$instance->whereExists($callback, $boolean, $not);
  1407. }
  1408. /**
  1409. * Add an or exists clause to the query.
  1410. *
  1411. * @param \Closure $callback
  1412. * @param bool $not
  1413. * @return \Hyperf\Database\Query\Builder
  1414. */
  1415. public static function orWhereExists($callback, $not = false)
  1416. {
  1417. return static::$instance->orWhereExists($callback, $not);
  1418. }
  1419. /**
  1420. * Add a where not exists clause to the query.
  1421. *
  1422. * @param \Closure $callback
  1423. * @param string $boolean
  1424. * @return \Hyperf\Database\Query\Builder
  1425. */
  1426. public static function whereNotExists($callback, $boolean = 'and')
  1427. {
  1428. return static::$instance->whereNotExists($callback, $boolean);
  1429. }
  1430. /**
  1431. * Add a where not exists clause to the query.
  1432. *
  1433. * @param \Closure $callback
  1434. * @return \Hyperf\Database\Query\Builder
  1435. */
  1436. public static function orWhereNotExists($callback)
  1437. {
  1438. return static::$instance->orWhereNotExists($callback);
  1439. }
  1440. /**
  1441. * Add an exists clause to the query.
  1442. *
  1443. * @param \Hyperf\Database\Query\Builder $query
  1444. * @param string $boolean
  1445. * @param bool $not
  1446. * @return \Hyperf\Database\Query\Builder
  1447. */
  1448. public static function addWhereExistsQuery($query, $boolean = 'and', $not = false)
  1449. {
  1450. return static::$instance->addWhereExistsQuery($query, $boolean, $not);
  1451. }
  1452. /**
  1453. * Adds a where condition using row values.
  1454. *
  1455. * @param array $columns
  1456. * @param string $operator
  1457. * @param array $values
  1458. * @param string $boolean
  1459. * @throws \InvalidArgumentException
  1460. * @return \Hyperf\Database\Query\Builder
  1461. */
  1462. public static function whereRowValues($columns, $operator, $values, $boolean = 'and')
  1463. {
  1464. return static::$instance->whereRowValues($columns, $operator, $values, $boolean);
  1465. }
  1466. /**
  1467. * Adds a or where condition using row values.
  1468. *
  1469. * @param array $columns
  1470. * @param string $operator
  1471. * @param array $values
  1472. * @return \Hyperf\Database\Query\Builder
  1473. */
  1474. public static function orWhereRowValues($columns, $operator, $values)
  1475. {
  1476. return static::$instance->orWhereRowValues($columns, $operator, $values);
  1477. }
  1478. /**
  1479. * Add a "where JSON contains" clause to the query.
  1480. *
  1481. * @param string $column
  1482. * @param mixed $value
  1483. * @param string $boolean
  1484. * @param bool $not
  1485. * @return \Hyperf\Database\Query\Builder
  1486. */
  1487. public static function whereJsonContains($column, $value, $boolean = 'and', $not = false)
  1488. {
  1489. return static::$instance->whereJsonContains($column, $value, $boolean, $not);
  1490. }
  1491. /**
  1492. * Add a "or where JSON contains" clause to the query.
  1493. *
  1494. * @param string $column
  1495. * @param mixed $value
  1496. * @return \Hyperf\Database\Query\Builder
  1497. */
  1498. public static function orWhereJsonContains($column, $value)
  1499. {
  1500. return static::$instance->orWhereJsonContains($column, $value);
  1501. }
  1502. /**
  1503. * Add a "where JSON not contains" clause to the query.
  1504. *
  1505. * @param string $column
  1506. * @param mixed $value
  1507. * @param string $boolean
  1508. * @return \Hyperf\Database\Query\Builder
  1509. */
  1510. public static function whereJsonDoesntContain($column, $value, $boolean = 'and')
  1511. {
  1512. return static::$instance->whereJsonDoesntContain($column, $value, $boolean);
  1513. }
  1514. /**
  1515. * Add a "or where JSON not contains" clause to the query.
  1516. *
  1517. * @param string $column
  1518. * @param mixed $value
  1519. * @return \Hyperf\Database\Query\Builder
  1520. */
  1521. public static function orWhereJsonDoesntContain($column, $value)
  1522. {
  1523. return static::$instance->orWhereJsonDoesntContain($column, $value);
  1524. }
  1525. /**
  1526. * Add a "where JSON length" clause to the query.
  1527. *
  1528. * @param string $column
  1529. * @param mixed $operator
  1530. * @param mixed $value
  1531. * @param string $boolean
  1532. * @return \Hyperf\Database\Query\Builder
  1533. */
  1534. public static function whereJsonLength($column, $operator, $value = null, $boolean = 'and')
  1535. {
  1536. return static::$instance->whereJsonLength($column, $operator, $value, $boolean);
  1537. }
  1538. /**
  1539. * Add a "or where JSON length" clause to the query.
  1540. *
  1541. * @param string $column
  1542. * @param mixed $operator
  1543. * @param mixed $value
  1544. * @return \Hyperf\Database\Query\Builder
  1545. */
  1546. public static function orWhereJsonLength($column, $operator, $value = null)
  1547. {
  1548. return static::$instance->orWhereJsonLength($column, $operator, $value);
  1549. }
  1550. /**
  1551. * Handles dynamic "where" clauses to the query.
  1552. *
  1553. * @param string $method
  1554. * @param array $parameters
  1555. * @return \Hyperf\Database\Query\Builder
  1556. */
  1557. public static function dynamicWhere($method, $parameters)
  1558. {
  1559. return static::$instance->dynamicWhere($method, $parameters);
  1560. }
  1561. /**
  1562. * Add a "group by" clause to the query.
  1563. *
  1564. * @param array|string $groups
  1565. * @return \Hyperf\Database\Query\Builder
  1566. */
  1567. public static function groupBy(...$groups)
  1568. {
  1569. return static::$instance->groupBy(...$groups);
  1570. }
  1571. /**
  1572. * Add a "having" clause to the query.
  1573. *
  1574. * @param string $column
  1575. * @param null|string $operator
  1576. * @param null|string $value
  1577. * @param string $boolean
  1578. * @return \Hyperf\Database\Query\Builder
  1579. */
  1580. public static function having($column, $operator = null, $value = null, $boolean = 'and')
  1581. {
  1582. return static::$instance->having($column, $operator, $value, $boolean);
  1583. }
  1584. /**
  1585. * Add a "or having" clause to the query.
  1586. *
  1587. * @param string $column
  1588. * @param null|string $operator
  1589. * @param null|string $value
  1590. * @return \Hyperf\Database\Query\Builder
  1591. */
  1592. public static function orHaving($column, $operator = null, $value = null)
  1593. {
  1594. return static::$instance->orHaving($column, $operator, $value);
  1595. }
  1596. /**
  1597. * Add a "having between " clause to the query.
  1598. *
  1599. * @param string $column
  1600. * @param array $values
  1601. * @param string $boolean
  1602. * @param bool $not
  1603. * @return \Hyperf\Database\Query\Builder
  1604. */
  1605. public static function havingBetween($column, $values, $boolean = 'and', $not = false)
  1606. {
  1607. return static::$instance->havingBetween($column, $values, $boolean, $not);
  1608. }
  1609. /**
  1610. * Add a raw having clause to the query.
  1611. *
  1612. * @param string $sql
  1613. * @param array $bindings
  1614. * @param string $boolean
  1615. * @return \Hyperf\Database\Query\Builder
  1616. */
  1617. public static function havingRaw($sql, $bindings = [], $boolean = 'and')
  1618. {
  1619. return static::$instance->havingRaw($sql, $bindings, $boolean);
  1620. }
  1621. /**
  1622. * Add a raw or having clause to the query.
  1623. *
  1624. * @param string $sql
  1625. * @param array $bindings
  1626. * @return \Hyperf\Database\Query\Builder
  1627. */
  1628. public static function orHavingRaw($sql, $bindings = [])
  1629. {
  1630. return static::$instance->orHavingRaw($sql, $bindings);
  1631. }
  1632. /**
  1633. * Add an "order by" clause to the query.
  1634. *
  1635. * @param \Closure|\Hyperf\Database\Query\Builder|string $column
  1636. * @param string $direction
  1637. * @throws \InvalidArgumentException
  1638. * @return \Hyperf\Database\Query\Builder
  1639. */
  1640. public static function orderBy($column, $direction = 'asc')
  1641. {
  1642. return static::$instance->orderBy($column, $direction);
  1643. }
  1644. /**
  1645. * Add a descending "order by" clause to the query.
  1646. *
  1647. * @param string $column
  1648. * @return \Hyperf\Database\Query\Builder
  1649. */
  1650. public static function orderByDesc($column)
  1651. {
  1652. return static::$instance->orderByDesc($column);
  1653. }
  1654. /**
  1655. * Put the query's results in random order.
  1656. *
  1657. * @param string $seed
  1658. * @return \Hyperf\Database\Query\Builder
  1659. */
  1660. public static function inRandomOrder($seed = '')
  1661. {
  1662. return static::$instance->inRandomOrder($seed);
  1663. }
  1664. /**
  1665. * Add a raw "order by" clause to the query.
  1666. *
  1667. * @param string $sql
  1668. * @param array $bindings
  1669. * @return \Hyperf\Database\Query\Builder
  1670. */
  1671. public static function orderByRaw($sql, $bindings = [])
  1672. {
  1673. return static::$instance->orderByRaw($sql, $bindings);
  1674. }
  1675. /**
  1676. * Alias to set the "offset" value of the query.
  1677. *
  1678. * @param int $value
  1679. * @return \Hyperf\Database\Query\Builder
  1680. */
  1681. public static function skip($value)
  1682. {
  1683. return static::$instance->skip($value);
  1684. }
  1685. /**
  1686. * Set the "offset" value of the query.
  1687. *
  1688. * @param int $value
  1689. * @return \Hyperf\Database\Query\Builder
  1690. */
  1691. public static function offset($value)
  1692. {
  1693. return static::$instance->offset($value);
  1694. }
  1695. /**
  1696. * Alias to set the "limit" value of the query.
  1697. *
  1698. * @param int $value
  1699. * @return \Hyperf\Database\Query\Builder
  1700. */
  1701. public static function take($value)
  1702. {
  1703. return static::$instance->take($value);
  1704. }
  1705. /**
  1706. * Set the "limit" value of the query.
  1707. *
  1708. * @param int $value
  1709. * @return \Hyperf\Database\Query\Builder
  1710. */
  1711. public static function limit($value)
  1712. {
  1713. return static::$instance->limit($value);
  1714. }
  1715. /**
  1716. * Set the limit and offset for a given page.
  1717. *
  1718. * @param int $page
  1719. * @param int $perPage
  1720. * @return \Hyperf\Database\Query\Builder
  1721. */
  1722. public static function forPage($page, $perPage = 15)
  1723. {
  1724. return static::$instance->forPage($page, $perPage);
  1725. }
  1726. /**
  1727. * Constrain the query to the previous "page" of results before a given ID.
  1728. *
  1729. * @param int $perPage
  1730. * @param null|int $lastId
  1731. * @param string $column
  1732. * @return \Hyperf\Database\Query\Builder
  1733. */
  1734. public static function forPageBeforeId($perPage = 15, $lastId = 0, $column = 'id')
  1735. {
  1736. return static::$instance->forPageBeforeId($perPage, $lastId, $column);
  1737. }
  1738. /**
  1739. * Constrain the query to the next "page" of results after a given ID.
  1740. *
  1741. * @param int $perPage
  1742. * @param null|int $lastId
  1743. * @param string $column
  1744. * @return \Hyperf\Database\Query\Builder
  1745. */
  1746. public static function forPageAfterId($perPage = 15, $lastId = 0, $column = 'id')
  1747. {
  1748. return static::$instance->forPageAfterId($perPage, $lastId, $column);
  1749. }
  1750. /**
  1751. * Add a union statement to the query.
  1752. *
  1753. * @param \Closure|\Hyperf\Database\Query\Builder $query
  1754. * @param bool $all
  1755. *
  1756. * @return \Hyperf\Database\Query\Builder
  1757. */
  1758. public static function union($query, $all = false)
  1759. {
  1760. return static::$instance->union($query, $all);
  1761. }
  1762. /**
  1763. * Add a union all statement to the query.
  1764. *
  1765. * @param \Closure|\Hyperf\Database\Query\Builder $query
  1766. *
  1767. * @return \Hyperf\Database\Query\Builder
  1768. */
  1769. public static function unionAll($query)
  1770. {
  1771. return static::$instance->unionAll($query);
  1772. }
  1773. /**
  1774. * Lock the selected rows in the table.
  1775. *
  1776. * @param bool|string $value
  1777. * @return \Hyperf\Database\Query\Builder
  1778. */
  1779. public static function lock($value = true)
  1780. {
  1781. return static::$instance->lock($value);
  1782. }
  1783. /**
  1784. * Lock the selected rows in the table for updating.
  1785. *
  1786. * @return \Hyperf\Database\Query\Builder
  1787. */
  1788. public static function lockForUpdate()
  1789. {
  1790. return static::$instance->lockForUpdate();
  1791. }
  1792. /**
  1793. * Share lock the selected rows in the table.
  1794. *
  1795. * @return \Hyperf\Database\Query\Builder
  1796. */
  1797. public static function sharedLock()
  1798. {
  1799. return static::$instance->sharedLock();
  1800. }
  1801. /**
  1802. * Get the SQL representation of the query.
  1803. *
  1804. * @return string
  1805. */
  1806. public static function toSql()
  1807. {
  1808. return static::$instance->toSql();
  1809. }
  1810. /**
  1811. * Get the count of the total records for the paginator.
  1812. *
  1813. * @param array $columns
  1814. * @return int
  1815. */
  1816. public static function getCountForPagination($columns = [])
  1817. {
  1818. return static::$instance->getCountForPagination($columns);
  1819. }
  1820. /**
  1821. * Concatenate values of a given column as a string.
  1822. *
  1823. * @param string $column
  1824. * @param string $glue
  1825. * @return string
  1826. */
  1827. public static function implode($column, $glue = '')
  1828. {
  1829. return static::$instance->implode($column, $glue);
  1830. }
  1831. /**
  1832. * Determine if any rows exist for the current query.
  1833. *
  1834. * @return bool
  1835. */
  1836. public static function exists()
  1837. {
  1838. return static::$instance->exists();
  1839. }
  1840. /**
  1841. * Determine if no rows exist for the current query.
  1842. *
  1843. * @return bool
  1844. */
  1845. public static function doesntExist()
  1846. {
  1847. return static::$instance->doesntExist();
  1848. }
  1849. /**
  1850. * Retrieve the "count" result of the query.
  1851. *
  1852. * @param string $columns
  1853. * @return int
  1854. */
  1855. public static function count($columns = '*')
  1856. {
  1857. return static::$instance->count($columns);
  1858. }
  1859. /**
  1860. * Retrieve the minimum value of a given column.
  1861. *
  1862. * @param string $column
  1863. * @return mixed
  1864. */
  1865. public static function min($column)
  1866. {
  1867. return static::$instance->min($column);
  1868. }
  1869. /**
  1870. * Retrieve the maximum value of a given column.
  1871. *
  1872. * @param string $column
  1873. * @return mixed
  1874. */
  1875. public static function max($column)
  1876. {
  1877. return static::$instance->max($column);
  1878. }
  1879. /**
  1880. * Retrieve the sum of the values of a given column.
  1881. *
  1882. * @param string $column
  1883. * @return mixed
  1884. */
  1885. public static function sum($column)
  1886. {
  1887. return static::$instance->sum($column);
  1888. }
  1889. /**
  1890. * Retrieve the average of the values of a given column.
  1891. *
  1892. * @param string $column
  1893. * @return mixed
  1894. */
  1895. public static function avg($column)
  1896. {
  1897. return static::$instance->avg($column);
  1898. }
  1899. /**
  1900. * Alias for the "avg" method.
  1901. *
  1902. * @param string $column
  1903. * @return mixed
  1904. */
  1905. public static function average($column)
  1906. {
  1907. return static::$instance->average($column);
  1908. }
  1909. /**
  1910. * Execute an aggregate function on the database.
  1911. *
  1912. * @param string $function
  1913. * @param array $columns
  1914. * @return mixed
  1915. */
  1916. public static function aggregate($function, $columns = [])
  1917. {
  1918. return static::$instance->aggregate($function, $columns);
  1919. }
  1920. /**
  1921. * Execute a numeric aggregate function on the database.
  1922. *
  1923. * @param string $function
  1924. * @param array $columns
  1925. * @return float|int
  1926. */
  1927. public static function numericAggregate($function, $columns = [])
  1928. {
  1929. return static::$instance->numericAggregate($function, $columns);
  1930. }
  1931. /**
  1932. * Insert a new record into the database.
  1933. *
  1934. * @param array $values
  1935. * @return bool
  1936. */
  1937. public static function insert($values)
  1938. {
  1939. return static::$instance->insert($values);
  1940. }
  1941. /**
  1942. * Insert a new record into the database while ignoring errors.
  1943. *
  1944. * @param array $values
  1945. * @return int
  1946. */
  1947. public static function insertOrIgnore($values)
  1948. {
  1949. return static::$instance->insertOrIgnore($values);
  1950. }
  1951. /**
  1952. * Insert a new record and get the value of the primary key.
  1953. *
  1954. * @param array $values
  1955. * @param null|string $sequence
  1956. * @return int
  1957. */
  1958. public static function insertGetId($values, $sequence = null)
  1959. {
  1960. return static::$instance->insertGetId($values, $sequence);
  1961. }
  1962. /**
  1963. * Insert new records into the table using a subquery.
  1964. *
  1965. * @param array $columns
  1966. * @param \Closure|\Hyperf\Database\Query\Builder|string $query
  1967. * @return int
  1968. */
  1969. public static function insertUsing($columns, $query)
  1970. {
  1971. return static::$instance->insertUsing($columns, $query);
  1972. }
  1973. /**
  1974. * Insert or update a record matching the attributes, and fill it with values.
  1975. *
  1976. * @param array $attributes
  1977. * @param array $values
  1978. * @return bool
  1979. */
  1980. public static function updateOrInsert($attributes, $values = [])
  1981. {
  1982. return static::$instance->updateOrInsert($attributes, $values);
  1983. }
  1984. /**
  1985. * Run a truncate statement on the table.
  1986. */
  1987. public static function truncate()
  1988. {
  1989. static::$instance->truncate();
  1990. }
  1991. /**
  1992. * Create a raw database expression.
  1993. *
  1994. * @param mixed $value
  1995. * @return \Hyperf\Database\Query\Expression
  1996. */
  1997. public static function raw($value)
  1998. {
  1999. return static::$instance->raw($value);
  2000. }
  2001. /**
  2002. * Get the current query value bindings in a flattened array.
  2003. *
  2004. * @return array
  2005. */
  2006. public static function getBindings()
  2007. {
  2008. return static::$instance->getBindings();
  2009. }
  2010. /**
  2011. * Get the raw array of bindings.
  2012. *
  2013. * @return array
  2014. */
  2015. public static function getRawBindings()
  2016. {
  2017. return static::$instance->getRawBindings();
  2018. }
  2019. /**
  2020. * Set the bindings on the query builder.
  2021. *
  2022. * @param array $bindings
  2023. * @param string $type
  2024. * @throws \InvalidArgumentException
  2025. * @return \Hyperf\Database\Query\Builder
  2026. */
  2027. public static function setBindings($bindings, $type = 'where')
  2028. {
  2029. return static::$instance->setBindings($bindings, $type);
  2030. }
  2031. /**
  2032. * Add a binding to the query.
  2033. *
  2034. * @param mixed $value
  2035. * @param string $type
  2036. * @throws \InvalidArgumentException
  2037. * @return \Hyperf\Database\Query\Builder
  2038. */
  2039. public static function addBinding($value, $type = 'where')
  2040. {
  2041. return static::$instance->addBinding($value, $type);
  2042. }
  2043. /**
  2044. * Merge an array of bindings into our bindings.
  2045. *
  2046. * @param \Hyperf\Database\Query\Builder $query
  2047. * @return \Hyperf\Database\Query\Builder
  2048. */
  2049. public static function mergeBindings($query)
  2050. {
  2051. return static::$instance->mergeBindings($query);
  2052. }
  2053. /**
  2054. * Get the database query processor instance.
  2055. *
  2056. * @return \Hyperf\Database\Query\Processors\Processor
  2057. */
  2058. public static function getProcessor()
  2059. {
  2060. return static::$instance->getProcessor();
  2061. }
  2062. /**
  2063. * Get the query grammar instance.
  2064. *
  2065. * @return \Hyperf\Database\Query\Grammars\Grammar
  2066. */
  2067. public static function getGrammar()
  2068. {
  2069. return static::$instance->getGrammar();
  2070. }
  2071. /**
  2072. * Use the write pdo for query.
  2073. *
  2074. * @return \Hyperf\Database\Query\Builder
  2075. */
  2076. public static function useWritePdo()
  2077. {
  2078. return static::$instance->useWritePdo();
  2079. }
  2080. /**
  2081. * Clone the query without the given properties.
  2082. *
  2083. * @param array $properties
  2084. *
  2085. * @return \Hyperf\Database\Query\Builder
  2086. */
  2087. public static function cloneWithout($properties)
  2088. {
  2089. return static::$instance->cloneWithout($properties);
  2090. }
  2091. /**
  2092. * Clone the query without the given bindings.
  2093. *
  2094. * @param array $except
  2095. *
  2096. * @return \Hyperf\Database\Query\Builder
  2097. */
  2098. public static function cloneWithoutBindings($except)
  2099. {
  2100. return static::$instance->cloneWithoutBindings($except);
  2101. }
  2102. /**
  2103. * Register a custom macro.
  2104. *
  2105. * @param string $name
  2106. * @param callable|object $macro
  2107. */
  2108. public static function macro($name, $macro)
  2109. {
  2110. \Hyperf\Database\Query\Builder::macro($name, $macro);
  2111. }
  2112. /**
  2113. * Mix another object into the class.
  2114. *
  2115. * @param object $mixin
  2116. * @throws \ReflectionException
  2117. */
  2118. public static function mixin($mixin)
  2119. {
  2120. \Hyperf\Database\Query\Builder::mixin($mixin);
  2121. }
  2122. /**
  2123. * Dynamically handle calls to the class.
  2124. *
  2125. * @param string $method
  2126. * @param array $parameters
  2127. * @throws \BadMethodCallException
  2128. * @return mixed
  2129. */
  2130. public static function macroCall($method, $parameters)
  2131. {
  2132. return static::$instance->macroCall($method, $parameters);
  2133. }
  2134. }