-
Notifications
You must be signed in to change notification settings - Fork 1
/
BiscuitInsertQuery.php
45 lines (39 loc) · 1.09 KB
/
BiscuitInsertQuery.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
<?php
/*
* EXAMPLES
* INSERT users { user_id:bcd001, age:45, status:A };
*/
class BiscuitInsertQuery extends BiscuitQuery
{
private $insert_pairs;
public function __construct($query)
{
parent::__construct($query);
$this->setTableName(explode(' ', $query)[1]);
$this->insert_pairs = $this->genInsertPairs($query);
}
public function getInsertPairs()
{
return $this->insert_pairs;
}
private function genInsertPairs($query)
{
// Obtain the arguments
preg_match("/ \{ (.*?) \}/", $query, $results);
$arguments = explode(',', $results[1]);
// Trim variables
for ($i = 0; $i < count($arguments); $i++) {
$arguments[$i] = trim($arguments[$i]);
}
$update_pairs = array();
foreach ($arguments as $arg) {
$args_array = explode(':', $arg);
$pair = array(
'column' => $args_array[0],
'value' => $args_array[1]
);
array_push($update_pairs, $pair);
}
return $update_pairs;
}
}