Skip to content

Commit 52137ef

Browse files
authored
πŸ”€ Merge pull request #3 from mychidarko/next
Improvements
2 parents 4595d80 + 4c06eb0 commit 52137ef

3 files changed

Lines changed: 12 additions & 14 deletions

File tree

β€Žsrc/Db/Builder.phpβ€Ž

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -91,14 +91,13 @@ public static function where(
9191
static::$bindings[] = $value;
9292
}
9393
} else {
94-
$values = array_values($condition);
95-
$conditionQuery = http_build_query($condition, '', " $operation ");
96-
$query .= str_replace($values, '?', $conditionQuery);
97-
98-
if ($comparator !== "=") {
99-
$query = str_replace("=", $comparator, $query);
94+
foreach ($condition as $k => $v) {
95+
$query .= "$k$comparator? $operation ";
10096
}
10197

98+
$values = array_values($condition);
99+
$query = rtrim($query, " $operation ");
100+
102101
static::$bindings = array_merge(static::$bindings, $values);
103102
}
104103

@@ -151,7 +150,7 @@ public static function params(string $query, $params): string
151150
$rebuild[$k] = '?';
152151
}
153152

154-
$query .= str_replace('%3F', '?', http_build_query($rebuild, '', ' AND '));
153+
$query .= str_replace('%3F', '?', http_build_query($rebuild, '', ', '));
155154
static::$bindings = array_values($params);
156155
}
157156

β€Žsrc/Db/Core.phpβ€Ž

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -281,10 +281,10 @@ public function execute()
281281
if (!isset($state['params'][$unique])) {
282282
trigger_error("$unique not found, Add $unique to your insert or update items or check your spelling.");
283283
}
284-
}
285284

286-
if ($this->connection->query("SELECT * FROM {$state['table']} WHERE $unique='{$state['params'][$unique]}'")->fetch(\PDO::FETCH_ASSOC)) {
287-
$this->errors[$unique] = "$unique already exists";
285+
if ($this->connection->query("SELECT * FROM {$state['table']} WHERE $unique='{$state['params'][$unique]}'")->fetch(\PDO::FETCH_ASSOC)) {
286+
$this->errors[$unique] = "$unique already exists";
287+
}
288288
}
289289

290290
if (count($this->errors)) {

β€Žsrc/functions.phpβ€Ž

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,10 @@
88
*/
99
function db()
1010
{
11-
if (!(app()->config('db.instance'))) {
12-
$db = new \Leaf\Db;
13-
app()->config('db.instance', $db);
11+
if (!(\Leaf\Config::get("db.instance"))) {
12+
\Leaf\Config::set("db.instance", new \Leaf\Db());
1413
}
1514

16-
return app()->config('db.instance');
15+
return \Leaf\Config::get("db.instance");
1716
}
1817
}

0 commit comments

Comments
Β (0)