MCPcopy Create free account
hub / github.com/RedisGraph/RedisGraph / _Constraint_Drop

Function _Constraint_Drop

src/commands/cmd_constraint.c:138–228  ·  view source on GitHub ↗

GRAPH.CONSTRAIN DROP UNIQUE/MANDATORY [NODE label / RELATIONSHIP type] PROPERTIES prop_count prop0, prop1...

Source from the content-addressed store, hash-verified

136
137// GRAPH.CONSTRAIN <key> DROP UNIQUE/MANDATORY [NODE label / RELATIONSHIP type] PROPERTIES prop_count prop0, prop1...
138static bool _Constraint_Drop
139(
140 RedisModuleCtx *ctx, // redis module context
141 RedisModuleString *key, // graph key to operate on
142 ConstraintType ct, // constraint type
143 GraphEntityType et, // entity type
144 const char *lbl, // label / rel-type
145 uint8_t n, // properties count
146 const char **props // properties
147) {
148 bool res = true; // optimistic
149 Attribute_ID attrs[n];
150
151 //--------------------------------------------------------------------------
152 // try to get graph
153 //--------------------------------------------------------------------------
154
155 GraphContext *gc = GraphContext_Retrieve(ctx, key, false, false);
156 if(!gc) {
157 // graph doesn't exists
158 return false;
159 }
160
161 //--------------------------------------------------------------------------
162 // try to get schema
163 //--------------------------------------------------------------------------
164
165 // determine schema type
166 SchemaType st = (et == GETYPE_NODE) ? SCHEMA_NODE : SCHEMA_EDGE;
167
168 Schema *s = GraphContext_GetSchema(gc, lbl, st);
169 if(s == NULL) {
170 res = false;
171 goto cleanup;
172 }
173
174 //--------------------------------------------------------------------------
175 // try to get attribute IDs
176 //--------------------------------------------------------------------------
177
178 for(uint8_t i = 0; i < n; i++) {
179 const char *prop = props[i];
180
181 // try to get property ID
182 Attribute_ID id = GraphContext_GetAttributeID(gc, prop);
183
184 if(id == ATTRIBUTE_ID_NONE) {
185 // attribute missing
186 res = false;
187 goto cleanup;
188 }
189
190 attrs[i] = id;
191 }
192
193 //--------------------------------------------------------------------------
194 // try to get constraint
195 //--------------------------------------------------------------------------

Callers 1

Graph_ConstraintFunction · 0.85

Calls 9

GraphContext_RetrieveFunction · 0.85
GraphContext_GetSchemaFunction · 0.85
Schema_GetConstraintFunction · 0.85
Graph_AcquireWriteLockFunction · 0.85
Schema_RemoveConstraintFunction · 0.85
Graph_ReleaseLockFunction · 0.85
Indexer_DropConstraintFunction · 0.85

Tested by

no test coverage detected