command handler for GRAPH.CONSTRAINT command GRAPH.CONSTRAINT CREATE UNIQUE/MANDATORY [NODE label / RELATIONSHIP type] PROPERTIES prop_count prop0, prop1... GRAPH.CONSTRAINT DROP UNIQUE/MANDATORY [NODE label / RELATIONSHIP type] PROPERTIES prop_count prop0, prop1...
| 378 | // GRAPH.CONSTRAINT CREATE <key> UNIQUE/MANDATORY [NODE label / RELATIONSHIP type] PROPERTIES prop_count prop0, prop1... |
| 379 | // GRAPH.CONSTRAINT DROP <key> UNIQUE/MANDATORY [NODE label / RELATIONSHIP type] PROPERTIES prop_count prop0, prop1... |
| 380 | int Graph_Constraint |
| 381 | ( |
| 382 | RedisModuleCtx *ctx, |
| 383 | RedisModuleString **argv, |
| 384 | int argc |
| 385 | ) { |
| 386 | if(argc < 8) { |
| 387 | return RedisModule_WrongArity(ctx); |
| 388 | } |
| 389 | |
| 390 | ConstraintOp op; |
| 391 | ConstraintType ct; |
| 392 | const char *label; |
| 393 | uint8_t prop_count; |
| 394 | RedisModuleString **props; |
| 395 | GraphEntityType entity_type; |
| 396 | RedisModuleString *key_name; |
| 397 | |
| 398 | //-------------------------------------------------------------------------- |
| 399 | // parse command arguments |
| 400 | //-------------------------------------------------------------------------- |
| 401 | |
| 402 | int res = Constraint_Parse(ctx, argv+1, argc-1, &key_name, &op, &ct, |
| 403 | &entity_type, &label, &prop_count, &props); |
| 404 | |
| 405 | // command parsing error, abort |
| 406 | if(res != REDISMODULE_OK) { |
| 407 | return REDISMODULE_ERR; |
| 408 | } |
| 409 | |
| 410 | // extract constraint properties and validate property name |
| 411 | const char *props_cstr[prop_count]; |
| 412 | for(uint8_t i = 0; i < prop_count; i++) { |
| 413 | props_cstr[i] = RedisModule_StringPtrLen(props[i], NULL); |
| 414 | if(str_MatchRegex(PROPERTY_NAME_PATTERN, props_cstr[i]) == false) { |
| 415 | RedisModule_ReplyWithErrorFormat(ctx, "Property name %s is invalid", props_cstr[i]); |
| 416 | return REDISMODULE_ERR; |
| 417 | } |
| 418 | } |
| 419 | |
| 420 | bool success = false; |
| 421 | |
| 422 | if(op == CT_CREATE) { |
| 423 | // try to create constraint |
| 424 | success = _Constraint_Create(ctx, key_name, ct, entity_type, label, |
| 425 | prop_count, props_cstr); |
| 426 | } else { |
| 427 | // CT_DROP |
| 428 | success = _Constraint_Drop(ctx, key_name, ct, entity_type, label, |
| 429 | prop_count, props_cstr); |
| 430 | } |
| 431 | |
| 432 | if(success == true) { |
| 433 | RedisModule_ReplyWithSimpleString(ctx, op == CT_CREATE ? "PENDING" : "OK"); |
| 434 | RedisModule_ReplicateVerbatim(ctx); |
| 435 | return REDISMODULE_OK; |
| 436 | } |
| 437 |
nothing calls this directly
no test coverage detected