@@ 83-104 (lines=22) @@ | ||
80 | /** |
|
81 | * {@inheritdoc} |
|
82 | */ |
|
83 | public function compileInsert(Builder $query, array $values) |
|
84 | { |
|
85 | // keyspace-ref: |
|
86 | $table = $this->wrapTable($query->from); |
|
87 | // use-keys-clause: |
|
88 | $keyClause = $this->wrapKey($query->key); |
|
89 | // returning-clause |
|
90 | $returning = implode(', ', $query->returning); |
|
91 | ||
92 | if (!is_array(reset($values))) { |
|
93 | $values = [$values]; |
|
94 | } |
|
95 | $parameters = []; |
|
96 | ||
97 | foreach ($values as $record) { |
|
98 | $parameters[] = '('.$this->parameterize($record).')'; |
|
99 | } |
|
100 | $parameters = (!$keyClause) ? implode(', ', $parameters) : "({$keyClause}, \$parameters)"; |
|
101 | $keyValue = (!$keyClause) ? null : '(KEY, VALUE)'; |
|
102 | ||
103 | return "insert into {$table} {$keyValue} values $parameters RETURNING {$returning}"; |
|
104 | } |
|
105 | ||
106 | /** |
|
107 | * {@inheritdoc} |
|
@@ 130-151 (lines=22) @@ | ||
127 | * |
|
128 | * @return string |
|
129 | */ |
|
130 | public function compileUpsert(QueryBuilder $query, array $values) |
|
131 | { |
|
132 | // keyspace-ref: |
|
133 | $table = $this->wrapTable($query->from); |
|
134 | // use-keys-clause: |
|
135 | $keyClause = $this->wrapKey($query->key); |
|
136 | // returning-clause |
|
137 | $returning = implode(', ', $query->returning); |
|
138 | ||
139 | if (!is_array(reset($values))) { |
|
140 | $values = [$values]; |
|
141 | } |
|
142 | $parameters = []; |
|
143 | ||
144 | foreach ($values as $record) { |
|
145 | $parameters[] = '('.$this->parameterize($record).')'; |
|
146 | } |
|
147 | $parameters = (!$keyClause) ? implode(', ', $parameters) : "({$keyClause}, \$parameters)"; |
|
148 | $keyValue = (!$keyClause) ? null : '(KEY, VALUE)'; |
|
149 | ||
150 | return "UPSERT INTO {$table} {$keyValue} VALUES $parameters RETURNING {$returning}"; |
|
151 | } |
|
152 | } |
|
153 |