This repository has been archived by the owner on Jul 10, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
query.php
87 lines (70 loc) · 1.83 KB
/
query.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<?php
require_once('sqlbuilder.php');
require_once('table.php');
class Query {
private $table;
private $sql;
function __construct($table) {
$this->table = $table;
$this->sql = new SqlBuilder();
}
public function all(...$parameters) {
return $this->table->query($this->sql->__toString(), ...$parameters);
}
public function one(...$parameters) {
$this->limit(1);
$models = $this->all(...$parameters);
if (!isset($models) || empty($models)) {
return null;
} else {
return $models[0];
}
}
public function select(...$fields) {
$this->sql->select(...$fields);
return $this;
}
public function from($table) {
$this->sql->from($table);
return $this;
}
public function join($table) {
$this->sql->join($table);
return $this;
}
public function leftJoin($table) {
$this->sql->leftJoin($table);
return $this;
}
public function rightJoin($table) {
$this->sql->rightJoin($table);
return $this;
}
public function where($condition) {
$this->sql->addCondition($condition);
return $this;
}
public function groupBy(...$groups) {
$this->sql->groupBy(...$groups);
return $this;
}
public function having(...$havings) {
$this->sql->having(...$havings);
return $this;
}
public function orderBy(...$orders) {
$this->sql->orderBy(...$orders);
return $this;
}
public function limit($limit) {
$this->sql->limit($limit);
return $this;
}
public function offset($offset) {
$this->sql->offset($offset);
return $this;
}
public function __toString() {
return $this->sql->__toString();
}
}