8000 Update ssql.php · ratajs/SuperSQL@d3937a0 · GitHub
[go: up one dir, main page]

Skip to content

Commit d3937a0

Browse files
authored
Update ssql.php
Added `->put()` method as a shorthand for `->insert()`, `->update()` and `->delete()`
1 parent 9ecc7a4 commit d3937a0

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

ssql.php

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ public function truncate(string $table, int $flags = 0) {
396396
return $this->query($query, $flags, "truncate");
397397
}
398398

399-
public function insert(string $table, array $values, int $flags = 0) {
399+
public function insert(string $table, array $values, int $flags = 0, string $name = "insert") {
400400
$cols = [""];
401401
$useCols = true;
402402
foreach($values as $k => $v) {
@@ -430,19 +430,19 @@ public function insert(string $table, array $values, int $flags = 0) {
430430
};
431431
$r = $this->query("
432432
INSERT INTO {$table}{$colString} VALUES ({$valueString})
433-
", $flags, "insert");
433+
", $flags, $name);
434434
return (boolval($flags & self::INSERT_RETURN_ID) ? $this->connect->lastInsertId() : $r);
435435
}
436436

437-
public function delete(string $table, $cond, int $flags = 128) {
437+
public function delete(string $table, $cond, int $flags = 128, string $name = "delete") {
438438
$all = !boolval($flags & self::COND_OR);
439439
$condString = $this->getCondString($cond, $all);
440440
return $this->query("
441441
DELETE FROM `{$table}` WHERE {$condString}
442-
", $flags, "delete");
442+
", $flags, $name);
443443
}
444444

445-
public function update(string $table, $cond, ar 10046 ray $values, int $flags = 128) {
445+
public function update(string $table, $cond, array $values, int $flags = 128, string $name = "update") {
446446
$all = !boolval($flags & self::COND_OR);
447447
$condString = $this->getCondString($cond, $all);
448448
$string = "";
@@ -461,7 +461,7 @@ public function update(string $table, $cond, array $values, int $flags = 128) {
461461
};
462462
return $this->query("
463463
UPDATE `{$table}` SET {$string} WHERE {$condString}
464-
", $flags, "update");
464+
", $flags, $name);
465465
}
466466

467467
public function add(string $table, string $name, string $type, int $length, bool $null, string $where, string$key, string $data = "", int $flags = 0) {
@@ -639,6 +639,18 @@ public function get(string $table, $options = [], int $flags = 4096) {
639639
$result = $this->selectJoinWhere($table, $join, $on, $cond, $order, $cols, $limit, $flags | $jointype | $condtype | $ordertype, "get");
640640
return $this->fetch($flags | $fetch);
641641
}
642+
643+
public function put(string $table, $data, $cond = NULL, int $flags = 0) {
644+
if(is_int($cond) && $flags==0) {
645+
$flags = $cond;
646+
$cond = NULL;
647+
};
648+
if(empty($cond))
649+
return $this->insert($table, $data, $flags, "put");
650+
if($data===NULL)
651+
return $this->delete($table, $cond, $flags, "put");
652+
return $this->update($table, $cond, $data, $flags, "put");
653+
}
642654

643655
public function cond($cond = "") {
644656
return new SSQLCond($this, $cond);

0 commit comments

Comments
 (0)
0