Skip to content

Commit

Permalink
πŸ”€ Merge pull request #3 from mychidarko/next
Browse files Browse the repository at this point in the history
Improvements
  • Loading branch information
mychidarko committed Jan 24, 2022
2 parents 4595d80 + 4c06eb0 commit 52137ef
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 14 deletions.
13 changes: 6 additions & 7 deletions src/Db/Builder.php
Expand Up @@ -91,14 +91,13 @@ public static function where(
static::$bindings[] = $value;
}
} else {
$values = array_values($condition);
$conditionQuery = http_build_query($condition, '', " $operation ");
$query .= str_replace($values, '?', $conditionQuery);

if ($comparator !== "=") {
$query = str_replace("=", $comparator, $query);
foreach ($condition as $k => $v) {
$query .= "$k$comparator? $operation ";
}

$values = array_values($condition);
$query = rtrim($query, " $operation ");

static::$bindings = array_merge(static::$bindings, $values);
}

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

$query .= str_replace('%3F', '?', http_build_query($rebuild, '', ' AND '));
$query .= str_replace('%3F', '?', http_build_query($rebuild, '', ', '));
static::$bindings = array_values($params);
}

Expand Down
6 changes: 3 additions & 3 deletions src/Db/Core.php
Expand Up @@ -281,10 +281,10 @@ public function execute()
if (!isset($state['params'][$unique])) {
trigger_error("$unique not found, Add $unique to your insert or update items or check your spelling.");
}
}

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

if (count($this->errors)) {
Expand Down
7 changes: 3 additions & 4 deletions src/functions.php
Expand Up @@ -8,11 +8,10 @@
*/
function db()
{
if (!(app()->config('db.instance'))) {
$db = new \Leaf\Db;
app()->config('db.instance', $db);
if (!(\Leaf\Config::get("db.instance"))) {
\Leaf\Config::set("db.instance", new \Leaf\Db());
}

return app()->config('db.instance');
return \Leaf\Config::get("db.instance");
}
}

0 comments on commit 52137ef

Please sign in to comment.