@loradb/lora-node 0.36.0 → 0.36.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -0
- package/docs/README.md +86 -0
- package/docs/concepts/graph-model.md +270 -0
- package/docs/concepts/nodes.md +285 -0
- package/docs/concepts/properties.md +348 -0
- package/docs/concepts/relationships.md +325 -0
- package/docs/concepts/result-formats.md +183 -0
- package/docs/concepts/schema-free.md +183 -0
- package/docs/cookbook.md +1081 -0
- package/docs/data-types/lists-and-maps.md +406 -0
- package/docs/data-types/overview.md +210 -0
- package/docs/data-types/scalars.md +376 -0
- package/docs/data-types/spatial.md +291 -0
- package/docs/data-types/temporal.md +349 -0
- package/docs/data-types/vectors.md +563 -0
- package/docs/errors.md +183 -0
- package/docs/functions/aggregation.md +372 -0
- package/docs/functions/list.md +522 -0
- package/docs/functions/map.md +207 -0
- package/docs/functions/math.md +421 -0
- package/docs/functions/number.md +197 -0
- package/docs/functions/overview.md +545 -0
- package/docs/functions/spatial.md +384 -0
- package/docs/functions/string.md +502 -0
- package/docs/functions/temporal.md +590 -0
- package/docs/functions/utility.md +137 -0
- package/docs/functions/vectors.md +772 -0
- package/docs/getting-started/installation.md +204 -0
- package/docs/getting-started/node.md +582 -0
- package/docs/getting-started/tutorial.md +334 -0
- package/docs/index.md +203 -0
- package/docs/limitations.md +291 -0
- package/docs/performance.md +219 -0
- package/docs/queries/aggregation.md +520 -0
- package/docs/queries/cheat-sheet.md +302 -0
- package/docs/queries/constraints.md +239 -0
- package/docs/queries/create.md +331 -0
- package/docs/queries/examples.md +453 -0
- package/docs/queries/index.md +169 -0
- package/docs/queries/indexes.md +538 -0
- package/docs/queries/match.md +429 -0
- package/docs/queries/ordering.md +359 -0
- package/docs/queries/parameters.md +328 -0
- package/docs/queries/paths.md +462 -0
- package/docs/queries/return-with.md +500 -0
- package/docs/queries/set-delete.md +369 -0
- package/docs/queries/unwind-merge.md +358 -0
- package/docs/queries/where.md +416 -0
- package/docs/snapshot.md +545 -0
- package/docs/troubleshooting.md +1158 -0
- package/docs/wal.md +570 -0
- package/docs/why.md +273 -0
- package/package.json +13 -14
|
@@ -0,0 +1,302 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Cypher Cheat Sheet"
|
|
3
|
+
description: "A one-page reference for the Cypher features LoraDB supports — read, write, path, aggregation, and expression forms — each with a minimal working example."
|
|
4
|
+
online: "https://loradb.com/docs/queries/cheat-sheet"
|
|
5
|
+
package: "@loradb/lora-node@0.36.1"
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
# Cypher Cheat Sheet
|
|
9
|
+
|
|
10
|
+
A one-page reference for the Cypher features LoraDB supports. For
|
|
11
|
+
scenario-driven recipes, see the [**Cookbook**](../cookbook.md); for
|
|
12
|
+
clause-by-clause detail, follow the links below.
|
|
13
|
+
|
|
14
|
+
## Read
|
|
15
|
+
|
|
16
|
+
```cypher
|
|
17
|
+
MATCH (n) // every node
|
|
18
|
+
MATCH (n:Person) // label filter
|
|
19
|
+
MATCH (n:Person {name: 'Ada'}) // label + property
|
|
20
|
+
MATCH (a)-[:KNOWS]->(b) // outgoing relationship
|
|
21
|
+
MATCH (a)-[:KNOWS]-(b) // either direction (MATCH only)
|
|
22
|
+
MATCH (a)-[r:KNOWS|LIKES]->(b) // any of several types
|
|
23
|
+
MATCH p = (a)-[:R*1..3]->(b) // variable-length; bind path
|
|
24
|
+
OPTIONAL MATCH (u)-[:WROTE]->(p) // left-join shape
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
More: [MATCH](./match.md), [Paths](./paths.md).
|
|
28
|
+
|
|
29
|
+
## Filter
|
|
30
|
+
|
|
31
|
+
```cypher
|
|
32
|
+
WHERE p.born >= 1900 AND p.born < 1950
|
|
33
|
+
WHERE p.email IS NOT NULL
|
|
34
|
+
WHERE p.name STARTS WITH 'A'
|
|
35
|
+
WHERE p.name CONTAINS 'da'
|
|
36
|
+
WHERE p.name =~ '.*son$'
|
|
37
|
+
WHERE EXISTS { (p)-[:FOLLOWS]->() }
|
|
38
|
+
WHERE NOT EXISTS { (p)-[:BANNED]->() }
|
|
39
|
+
WHERE p.tier IN ['gold', 'platinum']
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
More: [WHERE](./where.md).
|
|
43
|
+
|
|
44
|
+
## Indexes
|
|
45
|
+
|
|
46
|
+
```cypher
|
|
47
|
+
CREATE INDEX user_email FOR (u:User) ON (u.email)
|
|
48
|
+
CREATE TEXT INDEX user_name FOR (u:User) ON (u.name)
|
|
49
|
+
CREATE POINT INDEX place_location FOR (p:Place) ON (p.location)
|
|
50
|
+
CREATE VECTOR INDEX doc_embedding FOR (d:Doc) ON (d.embedding)
|
|
51
|
+
OPTIONS {indexConfig: {\`vector.dimensions\`: 1536, \`vector.similarity_function\`: 'cosine'}}
|
|
52
|
+
CREATE FULLTEXT INDEX article_search FOR (a:Article) ON EACH [a.title, a.body]
|
|
53
|
+
CREATE INDEX rel_since FOR ()-[r:FOLLOWS]-() ON (r.since)
|
|
54
|
+
CALL db.index.vector.queryNodes('doc_embedding', 5, $query) YIELD node, score
|
|
55
|
+
CALL db.index.fulltext.queryNodes('article_search', 'graph') YIELD node, score
|
|
56
|
+
SHOW INDEXES
|
|
57
|
+
DROP INDEX user_email IF EXISTS
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
More: [Indexes](./indexes.md).
|
|
61
|
+
|
|
62
|
+
## Constraints
|
|
63
|
+
|
|
64
|
+
```cypher
|
|
65
|
+
CREATE CONSTRAINT user_email FOR (u:User) REQUIRE u.email IS UNIQUE;
|
|
66
|
+
CREATE CONSTRAINT author_name FOR (a:Author) REQUIRE a.name IS NOT NULL;
|
|
67
|
+
CREATE CONSTRAINT actor_name FOR (a:Actor) REQUIRE (a.first, a.last) IS NODE KEY;
|
|
68
|
+
CREATE CONSTRAINT owns_id FOR ()-[o:OWNS]-() REQUIRE o.ownershipId IS RELATIONSHIP KEY;
|
|
69
|
+
CREATE CONSTRAINT doc_embedding FOR (d:Doc) REQUIRE d.embedding IS :: VECTOR<FLOAT32>(1536);
|
|
70
|
+
SHOW CONSTRAINTS;
|
|
71
|
+
DROP CONSTRAINT user_email IF EXISTS
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
More: [Constraints](./constraints.md).
|
|
75
|
+
|
|
76
|
+
## Project
|
|
77
|
+
|
|
78
|
+
```cypher
|
|
79
|
+
RETURN p.name, p.born;
|
|
80
|
+
RETURN p.name AS name, 2026 - p.born AS age;
|
|
81
|
+
RETURN DISTINCT c.country;
|
|
82
|
+
RETURN p { .name, .born }; // map projection
|
|
83
|
+
RETURN p { .*, extra: p.handle } // map projection with override
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
More: [RETURN / WITH](./return-with.md),
|
|
87
|
+
[map projection](../data-types/lists-and-maps.md#map-projection).
|
|
88
|
+
|
|
89
|
+
## Pipe and group
|
|
90
|
+
|
|
91
|
+
```cypher
|
|
92
|
+
WITH u, count(p) AS posts // group + pipe forward
|
|
93
|
+
WITH u WHERE u.active // HAVING-style filter
|
|
94
|
+
WITH *, string.lower(u.handle) AS key // pass-through plus computed
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
More: [WITH](./return-with.md#with).
|
|
98
|
+
|
|
99
|
+
## Sort and paginate
|
|
100
|
+
|
|
101
|
+
```cypher
|
|
102
|
+
ORDER BY n.name ASC
|
|
103
|
+
ORDER BY count(*) DESC
|
|
104
|
+
ORDER BY coalesce(p.rank, 9999) ASC
|
|
105
|
+
SKIP 20 LIMIT 10
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
More: [ORDER BY / SKIP / LIMIT](./ordering.md).
|
|
109
|
+
|
|
110
|
+
## Write
|
|
111
|
+
|
|
112
|
+
```cypher
|
|
113
|
+
CREATE (:Person {name: 'Ada', born: 1815})
|
|
114
|
+
CREATE (a)-[:FOLLOWS {since: 2020}]->(b)
|
|
115
|
+
|
|
116
|
+
MERGE (u:User {email: $email})
|
|
117
|
+
ON CREATE SET u.created = temporal.timestamp()
|
|
118
|
+
ON MATCH SET u.last_seen = temporal.timestamp()
|
|
119
|
+
|
|
120
|
+
SET n.prop = value // one key
|
|
121
|
+
SET n += {a: 1, b: 2} // merge into map
|
|
122
|
+
SET n = {id: 1, tier: 'gold'} // replace all properties
|
|
123
|
+
SET n:Admin // add a label
|
|
124
|
+
|
|
125
|
+
REMOVE n.prop // drop a property
|
|
126
|
+
REMOVE n:Admin // drop a label
|
|
127
|
+
|
|
128
|
+
DELETE r // a relationship
|
|
129
|
+
DETACH DELETE n // node + its edges
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
More: [CREATE](./create.md), [MERGE / UNWIND](./unwind-merge.md),
|
|
133
|
+
[SET / REMOVE / DELETE](./set-delete.md).
|
|
134
|
+
|
|
135
|
+
## Iterate and combine
|
|
136
|
+
|
|
137
|
+
```cypher
|
|
138
|
+
UNWIND $rows AS row
|
|
139
|
+
CREATE (:User {id: row.id, name: row.name});
|
|
140
|
+
|
|
141
|
+
UNWIND [1, 2, 3] AS n RETURN n * n AS square;
|
|
142
|
+
|
|
143
|
+
MATCH (u:User) RETURN u.name
|
|
144
|
+
UNION
|
|
145
|
+
MATCH (a:Admin) RETURN a.name
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
More: [UNWIND + MERGE](./unwind-merge.md),
|
|
149
|
+
[UNION](./return-with.md#union--union-all).
|
|
150
|
+
|
|
151
|
+
## Aggregate
|
|
152
|
+
|
|
153
|
+
```cypher
|
|
154
|
+
count(*) // rows
|
|
155
|
+
count(x) // rows where x is not null
|
|
156
|
+
count(DISTINCT x)
|
|
157
|
+
sum(x), avg(x), min(x), max(x)
|
|
158
|
+
collect(x), collect(DISTINCT x)
|
|
159
|
+
stdev(x), stdevp(x)
|
|
160
|
+
percentileCont(x, 0.95)
|
|
161
|
+
percentileDisc(x, 0.5)
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
More: [Aggregation (queries)](./aggregation.md),
|
|
165
|
+
[Aggregation (functions)](../functions/aggregation.md).
|
|
166
|
+
|
|
167
|
+
## Conditionals
|
|
168
|
+
|
|
169
|
+
```cypher
|
|
170
|
+
CASE WHEN x >= 50 THEN 'ok' ELSE 'low' END
|
|
171
|
+
CASE status WHEN 'paid' THEN 1 ELSE 0 END
|
|
172
|
+
count(CASE WHEN status = 'paid' THEN 1 END) // count-if
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
More: [CASE expressions](./return-with.md#case-expressions).
|
|
176
|
+
|
|
177
|
+
## Paths
|
|
178
|
+
|
|
179
|
+
```cypher
|
|
180
|
+
MATCH p = (a)-[:R*1..3]->(b) // 1 to 3 hops
|
|
181
|
+
MATCH p = shortestPath((a)-[:R*]->(b))
|
|
182
|
+
RETURN path.length(p), path.nodes(p), path.edges(p)
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
More: [Paths](./paths.md).
|
|
186
|
+
|
|
187
|
+
## Strings
|
|
188
|
+
|
|
189
|
+
```cypher
|
|
190
|
+
string.lower(s), string.upper(s)
|
|
191
|
+
string.trim(s), string.trim_left(s), string.trim_right(s)
|
|
192
|
+
string.slice(s, 0, 3), string.prefix(s, 2), string.suffix(s, 2)
|
|
193
|
+
string.replace(s, 'a', 'b'), value.reverse(s)
|
|
194
|
+
string.split(s, ','), value.size(s)
|
|
195
|
+
string.pad_left(s, 10, '0'), string.pad_right(s, 10, ' ')
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
More: [String functions](../functions/string.md).
|
|
199
|
+
|
|
200
|
+
## Math
|
|
201
|
+
|
|
202
|
+
```cypher
|
|
203
|
+
math.abs(x), math.ceil(x), math.floor(x), math.round(x)
|
|
204
|
+
math.sqrt(x), math.sign(x)
|
|
205
|
+
math.log(x), math.log10(x), math.exp(x)
|
|
206
|
+
math.sin(x), math.cos(x), math.tan(x), math.atan2(y, x)
|
|
207
|
+
math.radians(x), math.degrees(x)
|
|
208
|
+
math.pi(), math.e(), math.random()
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
More: [Math functions](../functions/math.md).
|
|
212
|
+
|
|
213
|
+
## Lists
|
|
214
|
+
|
|
215
|
+
```cypher
|
|
216
|
+
value.size(xs), list.first(xs), list.rest(xs), list.last(xs)
|
|
217
|
+
value.reverse(xs), list.range(1, 10), list.range(1, 10, 2)
|
|
218
|
+
xs[0], xs[-1], xs[..3], xs[2..5]
|
|
219
|
+
[x IN xs WHERE x > 0] // filter
|
|
220
|
+
[x IN xs | x * x] // map
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
More: [List functions](../functions/list.md).
|
|
224
|
+
|
|
225
|
+
## Temporal
|
|
226
|
+
|
|
227
|
+
```cypher
|
|
228
|
+
'2026-04-20'::DATE
|
|
229
|
+
'12:00:00'::TIME
|
|
230
|
+
'2026-04-20T12:00:00Z'::DATETIME
|
|
231
|
+
'2026-04-20T12:00:00'::LOCAL_DATETIME
|
|
232
|
+
'P30D'::DURATION, {days: 30}::DURATION
|
|
233
|
+
temporal.truncate('month', d)
|
|
234
|
+
temporal.truncate('hour', dt)
|
|
235
|
+
temporal.between(a, b)
|
|
236
|
+
dt.year, dt.month, dt.day, dt.hour
|
|
237
|
+
dt + 'P1D'::DURATION
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
More: [Temporal types](../data-types/temporal.md),
|
|
241
|
+
[Temporal functions](../functions/temporal.md).
|
|
242
|
+
|
|
243
|
+
## Spatial
|
|
244
|
+
|
|
245
|
+
```cypher
|
|
246
|
+
{x: 1, y: 2}::POINT // Cartesian 2D
|
|
247
|
+
{x: 1, y: 2, z: 3}::POINT // Cartesian 3D
|
|
248
|
+
{latitude: 52.37, longitude: 4.89}::POINT // WGS-84 2D
|
|
249
|
+
{latitude: 52.37, longitude: 4.89, height: 5}::POINT // WGS-84 3D
|
|
250
|
+
geo.distance(a, b) // same SRID only
|
|
251
|
+
p.x, p.y, p.latitude, p.longitude, p.z, p.height
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
More: [Spatial types](../data-types/spatial.md),
|
|
255
|
+
[Spatial functions](../functions/spatial.md).
|
|
256
|
+
|
|
257
|
+
## Type checks and conversions
|
|
258
|
+
|
|
259
|
+
```cypher
|
|
260
|
+
type.of(x) // 'INTEGER', 'STRING', 'NODE', …
|
|
261
|
+
toInteger(s), toFloat(s), toString(n), toBoolean(s)
|
|
262
|
+
coalesce(a, b, c)
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
More: [Type functions](../functions/overview.md#type-conversion-and-checking).
|
|
266
|
+
|
|
267
|
+
## Entity introspection
|
|
268
|
+
|
|
269
|
+
```cypher
|
|
270
|
+
id(n), id(r)
|
|
271
|
+
labels(n), type(r)
|
|
272
|
+
keys(n), properties(n)
|
|
273
|
+
path.nodes(p), path.edges(p), path.length(p)
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
More: [Entity / path functions](../functions/overview.md#entity-introspection).
|
|
277
|
+
|
|
278
|
+
## Parameters
|
|
279
|
+
|
|
280
|
+
```cypher
|
|
281
|
+
MATCH (u:User {id: $id}) RETURN u;
|
|
282
|
+
UNWIND $rows AS row CREATE (:User {id: row.id})
|
|
283
|
+
```
|
|
284
|
+
|
|
285
|
+
Bind from the host — see [Parameters](./parameters.md).
|
|
286
|
+
|
|
287
|
+
## Conventions
|
|
288
|
+
|
|
289
|
+
| Category | Convention | Example |
|
|
290
|
+
|---|---|---|
|
|
291
|
+
| Labels | `PascalCase` | `:Person`, `:OrderItem` |
|
|
292
|
+
| Relationship types | `UPPER_SNAKE` | `:FOLLOWS`, `:WORKS_AT` |
|
|
293
|
+
| Property keys | `snake_case` or `camelCase` (pick one) | `created_at`, `createdAt` |
|
|
294
|
+
| Variables | Lowercase, short | `u`, `p`, `edge` |
|
|
295
|
+
|
|
296
|
+
## See also
|
|
297
|
+
|
|
298
|
+
- [**Queries → Overview**](./index.md) — clauses and pipeline.
|
|
299
|
+
- [**Cookbook**](../cookbook.md) — scenario-based recipes.
|
|
300
|
+
- [**Query Examples**](./examples.md) — clause-by-clause recipes.
|
|
301
|
+
- [**Limitations**](../limitations.md) — what's intentionally not here.
|
|
302
|
+
- [**Troubleshooting**](../troubleshooting.md) — common errors.
|
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Constraints"
|
|
3
|
+
description: "How to create, inspect, and drop LoraDB schema constraints for uniqueness, existence, node keys, relationship keys, and property types."
|
|
4
|
+
online: "https://loradb.com/docs/queries/constraints"
|
|
5
|
+
package: "@loradb/lora-node@0.36.1"
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
# Constraints
|
|
9
|
+
|
|
10
|
+
LoraDB remains schema-free by default: labels, relationship types, and
|
|
11
|
+
property keys appear when you write them. Constraints are optional
|
|
12
|
+
catalog entries that add validation for selected labels or relationship
|
|
13
|
+
types.
|
|
14
|
+
|
|
15
|
+
Constraints are checked in two places:
|
|
16
|
+
|
|
17
|
+
- when the constraint is created, existing matching data must already
|
|
18
|
+
satisfy it;
|
|
19
|
+
- after creation, writes that would violate the constraint fail.
|
|
20
|
+
|
|
21
|
+
## Create Constraints
|
|
22
|
+
|
|
23
|
+
Every constraint needs a name:
|
|
24
|
+
|
|
25
|
+
```cypher
|
|
26
|
+
CREATE CONSTRAINT user_email
|
|
27
|
+
FOR (u:User)
|
|
28
|
+
REQUIRE u.email IS UNIQUE;
|
|
29
|
+
|
|
30
|
+
CREATE CONSTRAINT author_name
|
|
31
|
+
FOR (a:Author)
|
|
32
|
+
REQUIRE a.name IS NOT NULL;
|
|
33
|
+
|
|
34
|
+
CREATE CONSTRAINT actor_name
|
|
35
|
+
FOR (a:Actor)
|
|
36
|
+
REQUIRE (a.first, a.last) IS NODE KEY;
|
|
37
|
+
|
|
38
|
+
CREATE CONSTRAINT owns_id
|
|
39
|
+
FOR ()-[o:OWNS]-()
|
|
40
|
+
REQUIRE o.ownershipId IS RELATIONSHIP KEY;
|
|
41
|
+
|
|
42
|
+
CREATE CONSTRAINT movie_title
|
|
43
|
+
FOR (m:Movie)
|
|
44
|
+
REQUIRE m.title IS :: STRING;
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
Use `IF NOT EXISTS` to make creation idempotent:
|
|
48
|
+
|
|
49
|
+
```cypher
|
|
50
|
+
CREATE CONSTRAINT user_email IF NOT EXISTS
|
|
51
|
+
FOR (u:User)
|
|
52
|
+
REQUIRE u.email IS UNIQUE;
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
Constraint names may also come from a string parameter:
|
|
56
|
+
|
|
57
|
+
```cypher
|
|
58
|
+
CREATE CONSTRAINT $name
|
|
59
|
+
FOR (u:User)
|
|
60
|
+
REQUIRE u.email IS UNIQUE;
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## Constraint Kinds
|
|
64
|
+
|
|
65
|
+
| Kind | Syntax | Applies to |
|
|
66
|
+
|---|---|---|
|
|
67
|
+
| Property uniqueness | `REQUIRE n.email IS UNIQUE` | Nodes or relationships; single or composite |
|
|
68
|
+
| Property existence | `REQUIRE n.email IS NOT NULL` | Nodes or relationships; single property |
|
|
69
|
+
| Node key | `REQUIRE (n.a, n.b) IS NODE KEY` | Nodes; existence plus uniqueness |
|
|
70
|
+
| Relationship key | `REQUIRE r.id IS RELATIONSHIP KEY` | Relationships; existence plus uniqueness |
|
|
71
|
+
| Property type | `REQUIRE n.title IS :: STRING` | Nodes or relationships; single property |
|
|
72
|
+
|
|
73
|
+
Composite uniqueness and key constraints must wrap the property list in
|
|
74
|
+
parentheses:
|
|
75
|
+
|
|
76
|
+
```cypher
|
|
77
|
+
CREATE CONSTRAINT order_line
|
|
78
|
+
FOR ()-[r:LINE_ITEM]-()
|
|
79
|
+
REQUIRE (r.orderId, r.lineNo) IS UNIQUE;
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
A uniqueness or key constraint is backed by a RANGE index of the same
|
|
83
|
+
name. For a key that is only ever looked up by value (`{key: $k}`,
|
|
84
|
+
`MERGE`), `OPTIONS { indexProvider: 'hash' }` keeps the hash index that
|
|
85
|
+
enforcement and lookups read and drops the sorted copy of each value:
|
|
86
|
+
about 110 bytes less per node for a 58-character string key. Range,
|
|
87
|
+
`STARTS WITH` and `ORDER BY` reads on the key still work, by scanning
|
|
88
|
+
the label.
|
|
89
|
+
|
|
90
|
+
```cypher
|
|
91
|
+
CREATE CONSTRAINT record_key
|
|
92
|
+
FOR (r:Record)
|
|
93
|
+
REQUIRE r.key IS UNIQUE
|
|
94
|
+
OPTIONS { indexProvider: 'hash' };
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
`'range'` (Neo4j's `'range-1.0'` is accepted too) is the default. To
|
|
98
|
+
change the backing, drop the constraint and create it again.
|
|
99
|
+
|
|
100
|
+
Existence constraints are single-property only:
|
|
101
|
+
|
|
102
|
+
```cypher
|
|
103
|
+
CREATE CONSTRAINT published_at
|
|
104
|
+
FOR (p:Post)
|
|
105
|
+
REQUIRE p.publishedAt IS NOT NULL;
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
Existence is judged on the graph as a statement leaves it, so one
|
|
109
|
+
statement may add a label and its required property in either order, or
|
|
110
|
+
replace or remove a required property and set it again. A statement that
|
|
111
|
+
ends without the property is rejected and changes nothing. Uniqueness
|
|
112
|
+
and type constraints are checked at each write.
|
|
113
|
+
|
|
114
|
+
```cypher
|
|
115
|
+
MATCH (d:Draft {id: $id})
|
|
116
|
+
SET d:Post, d.publishedAt = datetime(); // ok
|
|
117
|
+
|
|
118
|
+
MATCH (p:Post {id: $id})
|
|
119
|
+
SET p = {id: $id, title: $title},
|
|
120
|
+
p.publishedAt = datetime(); // ok
|
|
121
|
+
|
|
122
|
+
MATCH (p:Post {id: $id})
|
|
123
|
+
SET p = {id: $id} // rejected, nothing changes
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
## Property Types
|
|
127
|
+
|
|
128
|
+
Property type constraints accept scalar types, lists with non-null
|
|
129
|
+
elements, vectors, and closed unions:
|
|
130
|
+
|
|
131
|
+
```cypher
|
|
132
|
+
CREATE CONSTRAINT movie_released
|
|
133
|
+
FOR (m:Movie)
|
|
134
|
+
REQUIRE m.released IS :: DATE;
|
|
135
|
+
|
|
136
|
+
CREATE CONSTRAINT article_tags
|
|
137
|
+
FOR (a:Article)
|
|
138
|
+
REQUIRE a.tags IS :: LIST<STRING NOT NULL>;
|
|
139
|
+
|
|
140
|
+
CREATE CONSTRAINT doc_embedding
|
|
141
|
+
FOR (d:Doc)
|
|
142
|
+
REQUIRE d.embedding IS :: VECTOR<FLOAT32>(1536);
|
|
143
|
+
|
|
144
|
+
CREATE CONSTRAINT tagline
|
|
145
|
+
FOR (m:Movie)
|
|
146
|
+
REQUIRE m.tagline IS :: STRING | LIST<STRING NOT NULL>;
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
Supported scalar type names are `BOOLEAN`, `STRING`, `INTEGER`,
|
|
150
|
+
`FLOAT`, `DATE`, `LOCAL TIME`, `ZONED TIME`, `LOCAL DATETIME`,
|
|
151
|
+
`ZONED DATETIME`, `DURATION`, and `POINT`.
|
|
152
|
+
|
|
153
|
+
`MAP`, `ANY`, and nullable list element types such as `LIST<STRING>`
|
|
154
|
+
are rejected for property type constraints. Vector dimensions must be
|
|
155
|
+
in `1..=4096`, and the coordinate type must match the stored vector
|
|
156
|
+
type.
|
|
157
|
+
|
|
158
|
+
## Inspect Constraints
|
|
159
|
+
|
|
160
|
+
```cypher
|
|
161
|
+
SHOW CONSTRAINTS;
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
Rows contain:
|
|
165
|
+
|
|
166
|
+
| Column | Meaning |
|
|
167
|
+
|---|---|
|
|
168
|
+
| `name` | Constraint name |
|
|
169
|
+
| `type` | `NODE_PROPERTY_UNIQUENESS`, `RELATIONSHIP_PROPERTY_UNIQUENESS`, `NODE_PROPERTY_EXISTENCE`, `RELATIONSHIP_PROPERTY_EXISTENCE`, `NODE_KEY`, `RELATIONSHIP_KEY`, `NODE_PROPERTY_TYPE`, or `RELATIONSHIP_PROPERTY_TYPE` |
|
|
170
|
+
| `entityType` | `NODE` or `RELATIONSHIP` |
|
|
171
|
+
| `labelsOrTypes` | Label or relationship type scope |
|
|
172
|
+
| `properties` | Constrained property keys |
|
|
173
|
+
| `ownedIndex` | Backing index name for uniqueness and key constraints; `null` otherwise |
|
|
174
|
+
| `indexProvider` | `range` or `hash` for uniqueness and key constraints; `null` otherwise |
|
|
175
|
+
| `propertyType` | Type expression for property type constraints; `null` otherwise |
|
|
176
|
+
|
|
177
|
+
`SHOW CONSTRAINTS` accepts the same `YIELD`-anchored catalog pipeline
|
|
178
|
+
as `SHOW INDEXES`:
|
|
179
|
+
|
|
180
|
+
```cypher
|
|
181
|
+
SHOW CONSTRAINTS
|
|
182
|
+
YIELD name, type
|
|
183
|
+
WHERE type = 'NODE_PROPERTY_UNIQUENESS'
|
|
184
|
+
RETURN name
|
|
185
|
+
ORDER BY name;
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
## Drop Constraints
|
|
189
|
+
|
|
190
|
+
```cypher
|
|
191
|
+
DROP CONSTRAINT user_email;
|
|
192
|
+
DROP CONSTRAINT maybe_missing IF EXISTS;
|
|
193
|
+
DROP CONSTRAINT $name;
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
Uniqueness and key constraints own a backing `RANGE` index with the
|
|
197
|
+
same name. Drop the constraint, not the backing index; direct
|
|
198
|
+
`DROP INDEX` on a constraint-owned index is rejected.
|
|
199
|
+
|
|
200
|
+
## Write Enforcement
|
|
201
|
+
|
|
202
|
+
Constraints are enforced for matching writes:
|
|
203
|
+
|
|
204
|
+
```cypher
|
|
205
|
+
CREATE CONSTRAINT user_email
|
|
206
|
+
FOR (u:User)
|
|
207
|
+
REQUIRE u.email IS UNIQUE;
|
|
208
|
+
|
|
209
|
+
CREATE (:User {email: 'ada@example.com'});
|
|
210
|
+
CREATE (:User {email: 'ada@example.com'}); // rejected
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
Enforcement covers node and relationship creation, property updates,
|
|
214
|
+
property replacement through `SET n = {...}`, property removal, and
|
|
215
|
+
adding a label that activates a node constraint.
|
|
216
|
+
|
|
217
|
+
## Durability
|
|
218
|
+
|
|
219
|
+
Constraint catalog entries are included in snapshots and replayed from
|
|
220
|
+
WAL records during recovery. Uniqueness and key constraints recreate
|
|
221
|
+
their backing indexes as part of the catalog state.
|
|
222
|
+
|
|
223
|
+
## Limitations
|
|
224
|
+
|
|
225
|
+
- Constraints are label/type scoped; there is no database-wide
|
|
226
|
+
uniqueness constraint.
|
|
227
|
+
- Existence constraints are single-property only.
|
|
228
|
+
- Property type constraints do not support `MAP`, `ANY`, or nullable
|
|
229
|
+
list element types.
|
|
230
|
+
- Constraint names are required.
|
|
231
|
+
- Dropping a backing index directly is rejected; use
|
|
232
|
+
`DROP CONSTRAINT`.
|
|
233
|
+
|
|
234
|
+
## See Also
|
|
235
|
+
|
|
236
|
+
- [Indexes](./indexes.md) - backing indexes and catalog inspection.
|
|
237
|
+
- [CREATE](./create.md) - writes that may be checked by constraints.
|
|
238
|
+
- [SET / REMOVE / DELETE](./set-delete.md) - mutation clauses.
|
|
239
|
+
- [Schema-free](../concepts/schema-free.md) - optional schema controls.
|