| 1 |
RUN DROP SCHEMA IF EXISTS xtest |
| 2 |
|
| 3 |
0 rows affected |
| 4 |
RUN CREATE SCHEMA xtest |
| 5 |
|
| 6 |
1 rows affected |
| 7 |
RUN CREATE TABLE xtest.xtable (xfield JSON) |
| 8 |
|
| 9 |
0 rows affected |
| 10 |
Inserting object into table |
| 11 |
send Mysqlx.Crud.Insert { |
| 12 |
collection { |
| 13 |
name: "xtable" |
| 14 |
schema: "xtest" |
| 15 |
} |
| 16 |
data_model: TABLE |
| 17 |
projection { |
| 18 |
name: "xfield" |
| 19 |
} |
| 20 |
row { |
| 21 |
field { |
| 22 |
type: OBJECT |
| 23 |
object { |
| 24 |
fld { |
| 25 |
key: "_id" |
| 26 |
value { |
| 27 |
type: LITERAL |
| 28 |
literal { |
| 29 |
type: V_OCTETS |
| 30 |
v_octets { |
| 31 |
value: "1" |
| 32 |
} |
| 33 |
} |
| 34 |
} |
| 35 |
} |
| 36 |
fld { |
| 37 |
key: "first_name" |
| 38 |
value { |
| 39 |
type: LITERAL |
| 40 |
literal { |
| 41 |
type: V_OCTETS |
| 42 |
v_octets { |
| 43 |
value: "John" |
| 44 |
} |
| 45 |
} |
| 46 |
} |
| 47 |
} |
| 48 |
fld { |
| 49 |
key: "last_name" |
| 50 |
value { |
| 51 |
type: LITERAL |
| 52 |
literal { |
| 53 |
type: V_OCTETS |
| 54 |
v_octets { |
| 55 |
value: "Snow" |
| 56 |
} |
| 57 |
} |
| 58 |
} |
| 59 |
} |
| 60 |
} |
| 61 |
} |
| 62 |
} |
| 63 |
} |
| 64 |
|
| 65 |
|
| 66 |
1 rows affected |
| 67 |
RUN SELECT * FROM xtest.xtable |
| 68 |
xfield |
| 69 |
{"_id": "1", "last_name": "Snow", "first_name": "John"} |
| 70 |
0 rows affected |
| 71 |
Selecting object from table with alias |
| 72 |
send Mysqlx.Crud.Find { |
| 73 |
collection { |
| 74 |
name: "xtable" |
| 75 |
schema: "xtest" |
| 76 |
} |
| 77 |
data_model: TABLE |
| 78 |
projection { |
| 79 |
source { |
| 80 |
type: OBJECT |
| 81 |
object { |
| 82 |
fld { |
| 83 |
key: "name" |
| 84 |
value { |
| 85 |
type: FUNC_CALL |
| 86 |
function_call { |
| 87 |
name { |
| 88 |
name: "concat" |
| 89 |
} |
| 90 |
param { |
| 91 |
type: IDENT |
| 92 |
identifier { |
| 93 |
document_path { |
| 94 |
type: MEMBER |
| 95 |
value: "first_name" |
| 96 |
} |
| 97 |
name: "xfield" |
| 98 |
} |
| 99 |
} |
| 100 |
param { |
| 101 |
type: LITERAL |
| 102 |
literal { |
| 103 |
type: V_OCTETS |
| 104 |
v_octets { |
| 105 |
value: " " |
| 106 |
} |
| 107 |
} |
| 108 |
} |
| 109 |
param { |
| 110 |
type: IDENT |
| 111 |
identifier { |
| 112 |
document_path { |
| 113 |
type: MEMBER |
| 114 |
value: "last_name" |
| 115 |
} |
| 116 |
name: "xfield" |
| 117 |
} |
| 118 |
} |
| 119 |
} |
| 120 |
} |
| 121 |
} |
| 122 |
fld { |
| 123 |
key: "number" |
| 124 |
value { |
| 125 |
type: OPERATOR |
| 126 |
operator { |
| 127 |
name: "+" |
| 128 |
param { |
| 129 |
type: LITERAL |
| 130 |
literal { |
| 131 |
type: V_SINT |
| 132 |
v_signed_int: 1 |
| 133 |
} |
| 134 |
} |
| 135 |
param { |
| 136 |
type: LITERAL |
| 137 |
literal { |
| 138 |
type: V_SINT |
| 139 |
v_signed_int: 1 |
| 140 |
} |
| 141 |
} |
| 142 |
} |
| 143 |
} |
| 144 |
} |
| 145 |
} |
| 146 |
} |
| 147 |
alias: "result" |
| 148 |
} |
| 149 |
} |
| 150 |
|
| 151 |
result |
| 152 |
{"name": "John Snow", "number": 2} |
| 153 |
command ok |
| 154 |
Selecting object with sub-object from table |
| 155 |
send Mysqlx.Crud.Find { |
| 156 |
collection { |
| 157 |
name: "xtable" |
| 158 |
schema: "xtest" |
| 159 |
} |
| 160 |
data_model: TABLE |
| 161 |
projection { |
| 162 |
source { |
| 163 |
type: OBJECT |
| 164 |
object { |
| 165 |
fld { |
| 166 |
key: "name" |
| 167 |
value { |
| 168 |
type: FUNC_CALL |
| 169 |
function_call { |
| 170 |
name { |
| 171 |
name: "concat" |
| 172 |
} |
| 173 |
param { |
| 174 |
type: IDENT |
| 175 |
identifier { |
| 176 |
document_path { |
| 177 |
type: MEMBER |
| 178 |
value: "first_name" |
| 179 |
} |
| 180 |
name: "xfield" |
| 181 |
} |
| 182 |
} |
| 183 |
param { |
| 184 |
type: LITERAL |
| 185 |
literal { |
| 186 |
type: V_OCTETS |
| 187 |
v_octets { |
| 188 |
value: " " |
| 189 |
} |
| 190 |
} |
| 191 |
} |
| 192 |
param { |
| 193 |
type: IDENT |
| 194 |
identifier { |
| 195 |
document_path { |
| 196 |
type: MEMBER |
| 197 |
value: "last_name" |
| 198 |
} |
| 199 |
name: "xfield" |
| 200 |
} |
| 201 |
} |
| 202 |
} |
| 203 |
} |
| 204 |
} |
| 205 |
fld { |
| 206 |
key: "detail" |
| 207 |
value { |
| 208 |
type: OBJECT |
| 209 |
object { |
| 210 |
fld { |
| 211 |
key: "first" |
| 212 |
value { |
| 213 |
type: IDENT |
| 214 |
identifier { |
| 215 |
document_path { |
| 216 |
type: MEMBER |
| 217 |
value: "first_name" |
| 218 |
} |
| 219 |
name: "xfield" |
| 220 |
} |
| 221 |
} |
| 222 |
} |
| 223 |
fld { |
| 224 |
key: "last" |
| 225 |
value { |
| 226 |
type: IDENT |
| 227 |
identifier { |
| 228 |
document_path { |
| 229 |
type: MEMBER |
| 230 |
value: "last_name" |
| 231 |
} |
| 232 |
name: "xfield" |
| 233 |
} |
| 234 |
} |
| 235 |
} |
| 236 |
} |
| 237 |
} |
| 238 |
} |
| 239 |
} |
| 240 |
} |
| 241 |
alias: "result" |
| 242 |
} |
| 243 |
} |
| 244 |
|
| 245 |
result |
| 246 |
{"name": "John Snow", "detail": {"last": "Snow", "first": "John"}} |
| 247 |
command ok |
| 248 |
Updating table by object |
| 249 |
send Mysqlx.Crud.Update { |
| 250 |
collection { |
| 251 |
name: "xtable" |
| 252 |
schema: "xtest" |
| 253 |
} |
| 254 |
data_model: TABLE |
| 255 |
operation { |
| 256 |
source { |
| 257 |
document_path { |
| 258 |
type: MEMBER |
| 259 |
value: "occupation" |
| 260 |
} |
| 261 |
name: "xfield" |
| 262 |
} |
| 263 |
operation: ITEM_SET |
| 264 |
value { |
| 265 |
type: OBJECT |
| 266 |
object { |
| 267 |
fld { |
| 268 |
key: "location" |
| 269 |
value { |
| 270 |
type: LITERAL |
| 271 |
literal { |
| 272 |
type: V_OCTETS |
| 273 |
v_octets { |
| 274 |
value: "the wall" |
| 275 |
} |
| 276 |
} |
| 277 |
} |
| 278 |
} |
| 279 |
fld { |
| 280 |
key: "title" |
| 281 |
value { |
| 282 |
type: LITERAL |
| 283 |
literal { |
| 284 |
type: V_OCTETS |
| 285 |
v_octets { |
| 286 |
value: "lord commander" |
| 287 |
} |
| 288 |
} |
| 289 |
} |
| 290 |
} |
| 291 |
} |
| 292 |
} |
| 293 |
} |
| 294 |
} |
| 295 |
|
| 296 |
|
| 297 |
1 rows affected |
| 298 |
Rows matched: 1 Changed: 1 Warnings: 0 |
| 299 |
RUN SELECT * FROM xtest.xtable |
| 300 |
xfield |
| 301 |
{"_id": "1", "last_name": "Snow", "first_name": "John", "occupation": {"title": "lord commander", "location": "the wall"}} |
| 302 |
0 rows affected |
| 303 |
NOT Error: empty object |
| 304 |
send Mysqlx.Crud.Find { |
| 305 |
collection { |
| 306 |
name: "xtable" |
| 307 |
schema: "xtest" |
| 308 |
} |
| 309 |
data_model: TABLE |
| 310 |
projection { |
| 311 |
source { |
| 312 |
type: OBJECT |
| 313 |
object { |
| 314 |
} |
| 315 |
} |
| 316 |
alias: "result" |
| 317 |
} |
| 318 |
} |
| 319 |
|
| 320 |
result |
| 321 |
{} |
| 322 |
command ok |
| 323 |
Error: empty object key |
| 324 |
send Mysqlx.Crud.Find { |
| 325 |
collection { |
| 326 |
name: "xtable" |
| 327 |
schema: "xtest" |
| 328 |
} |
| 329 |
data_model: TABLE |
| 330 |
projection { |
| 331 |
source { |
| 332 |
type: OBJECT |
| 333 |
object { |
| 334 |
fld { |
| 335 |
key: "" |
| 336 |
value { |
| 337 |
type: IDENT |
| 338 |
identifier { |
| 339 |
document_path { |
| 340 |
type: MEMBER |
| 341 |
value: "first_name" |
| 342 |
} |
| 343 |
name: "xfield" |
| 344 |
} |
| 345 |
} |
| 346 |
} |
| 347 |
} |
| 348 |
} |
| 349 |
alias: "result" |
| 350 |
} |
| 351 |
} |
| 352 |
|
| 353 |
Got expected error: |
| 354 |
Mysqlx.Error { |
| 355 |
severity: ERROR |
| 356 |
code: 5154 |
| 357 |
msg: "Invalid key for Mysqlx::Expr::Object" |
| 358 |
sql_state: "HY000" |
| 359 |
} |
| 360 |
|
| 361 |
RUN drop schema if exists xtest |
| 362 |
|
| 363 |
1 rows affected |
| 364 |
Mysqlx.Ok { |
| 365 |
msg: "bye!" |
| 366 |
} |
| 367 |
ok |