Skip to content

Commit 4d95131

Browse files
authored
Merge pull request #212 from sagittaracc/develop
Develop
2 parents 4e14ffb + fcdf8ad commit 4d95131

File tree

3 files changed

+39
-10
lines changed

3 files changed

+39
-10
lines changed

README.md

-8
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,6 @@
2626
### What is this?
2727
SuQL is syntactic sugar for SQL.
2828

29-
### How does this work?
30-
Click on the image below to see the whole demo on YouTube.
31-
<p align="center">
32-
<a href="https://www.youtube.com/watch?v=9-WSjChYwn4">
33-
<img src="https://s7.gifyu.com/images/suql-demo-by-sagittaracc.gif" alt="Sugar SQL (SuQL) demo by sagittaracc"/>
34-
</a>
35-
</p>
36-
3729
### Why do you need this?
3830
1. Write queries once, use for every DBMS.
3931
2. Write queries that are easy to read and write.

src/modifier/SQLWhereModifier.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ public static function mod_endsWith($ofield, $params) {
5151
}
5252

5353
public static function mod_where($ofield, $params) {
54-
// TODO: Custom where
54+
if ($ofield->hasAlias())
55+
$ofield->getOSelect()->addHaving(str_replace('$', $ofield->getAlias(), trim($params[0], "'")));
56+
else
57+
$ofield->getOSelect()->addWhere(str_replace('$', $ofield->getField(), trim($params[0], "'")));
5558
}
5659
}

tests/SuQLTest.php

+35-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
final class SuQLTest extends TestCase
66
{
7-
private $suql;
7+
private $suql = null;
88

99
private function init()
1010
{
@@ -81,6 +81,40 @@ public function testSelectWhere(): void
8181
);
8282
}
8383

84+
public function testCustomWhere(): void
85+
{
86+
$this->init();
87+
88+
$this->assertEquals(
89+
$this->suql->query("
90+
select
91+
users {
92+
id.where('$ mod 2 = 0')
93+
}
94+
;
95+
")->getSQL(),
96+
"select users.id from users where users.id mod 2 = 0"
97+
);
98+
}
99+
100+
public function testQueryNestedInWhere(): void
101+
{
102+
$this->init();
103+
104+
$this->assertEquals(
105+
$this->suql->query("
106+
@q1 = select users {};
107+
108+
select
109+
groups {
110+
name.where($ not in @q1)
111+
}
112+
;
113+
")->getSQL(),
114+
"select groups.name from groups where groups.name not in (select * from users)"
115+
);
116+
}
117+
84118
public function testJoin(): void
85119
{
86120
$this->init();

0 commit comments

Comments
 (0)