Skip to content

Commit 450b90b

Browse files
cheat sheet tags
1 parent beac214 commit 450b90b

File tree

7 files changed

+69
-0
lines changed

7 files changed

+69
-0
lines changed

modules/ROOT/pages/schema/constraints/create-constraints.adoc

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,13 @@ For the full command syntax to create a property uniqueness constraint, see xref
3838
======
3939
4040
.Create a constraint requiring `Book` nodes to have unique `isbn` properties
41+
// tag::schema_constraints_property_uniqueness[]
4142
[source, cypher]
4243
----
4344
CREATE CONSTRAINT book_isbn
4445
FOR (book:Book) REQUIRE book.isbn IS UNIQUE
4546
----
47+
// end::schema_constraints_property_uniqueness[]
4648
4749
.Result
4850
[source, queryresult]
@@ -106,11 +108,13 @@ Added 1 constraint.
106108
======
107109
108110
.Create a constraint requiring `PREQUEL_OF` relationships to have unique combinations of `order` and `author` properties
111+
// tag::schema_constraints_composite_property_uniqueness[]
109112
[source, cypher]
110113
----
111114
CREATE CONSTRAINT prequels
112115
FOR ()-[prequel:PREQUEL_OF]-() REQUIRE (prequel.order, prequel.author) IS UNIQUE
113116
----
117+
// end::schema_constraints_composite_property_uniqueness[]
114118
115119
.Result
116120
[source, queryresult]
@@ -183,11 +187,13 @@ It is not possible to create composite existence constraints on several properti
183187
======
184188
185189
.Create a constraint requiring `Author` nodes to have a `name` property
190+
// tag::schema_constraints_property_existence[]
186191
[source, cypher]
187192
----
188193
CREATE CONSTRAINT author_name
189194
FOR (author:Author) REQUIRE author.name IS NOT NULL
190195
----
196+
// end::schema_constraints_property_existence[]
191197
192198
.Result
193199
[source, queryresult]
@@ -301,11 +307,13 @@ Added 1 constraint.
301307
======
302308
303309
.Create a constraint requiring `order` properties on `PART_OF` relationships to be of type `INTEGER`
310+
// tag::schema_constraints_property_type[]
304311
[source, cypher]
305312
----
306313
CREATE CONSTRAINT part_of
307314
FOR ()-[part:PART_OF]-() REQUIRE part.order IS :: INTEGER
308315
----
316+
// end::schema_constraints_property_type[]
309317
310318
.Result
311319
[source, queryresult]
@@ -324,11 +332,13 @@ A closed dynamic union allows a node or relationship property to maintain some t
324332
======
325333
326334
.Create a constraint requiring `tagline` properties on `Movie` nodes to be either of type `STRING` or `LIST<STRING NOT NULL>`
335+
// tag::schema_constraints_property_type_dynamic_union[]
327336
[source, cypher]
328337
----
329338
CREATE CONSTRAINT movie_tagline
330339
FOR (movie:Movie) REQUIRE movie.tagline IS :: STRING | LIST<STRING NOT NULL>
331340
----
341+
// end::schema_constraints_property_type_dynamic_union[]
332342
333343
.Result
334344
[source, queryresult]
@@ -471,11 +481,13 @@ For the full command syntax to create a key constraint, see xref:schema/syntax.a
471481
======
472482
473483
.Create a constraint requiring `Director` nodes to have a unique `imdbId` property as a node key.
484+
// tag::schema_constraints_key[]
474485
[source, cypher]
475486
----
476487
CREATE CONSTRAINT director_imdbId
477488
FOR (director:Director) REQUIRE (director.imdbId) IS NODE KEY
478489
----
490+
// end::schema_constraints_key[]
479491
480492
.Result
481493
[source, queryresult]
@@ -541,9 +553,11 @@ Added 1 constraint.
541553
.Create a constraint requiring `KNOWS` relationships to have a unique combination of `since` and `how` properties as a relationship key
542554
[source, cypher]
543555
----
556+
// tag::schema_constraints_composite_key[]
544557
CREATE CONSTRAINT knows_since_how
545558
FOR ()-[knows:KNOWS]-() REQUIRE (knows.since, knows.how) IS RELATIONSHIP KEY
546559
----
560+
// end::schema_constraints_composite_key[]
547561
548562
.Result
549563
[source, queryresult]
@@ -609,11 +623,13 @@ All constraint types can be created with a parameterized name.
609623
----
610624
611625
.Create a node property uniqueness constraint with a parameterized name
626+
// tag::schema_constraints_parameter[]
612627
[source, cypher]
613628
----
614629
CREATE CONSTRAINT $name
615630
FOR (book:Book) REQUIRE book.prop1 IS UNIQUE
616631
----
632+
// end::schema_constraints_parameter[]
617633
618634
.Result
619635
[source, queryresult]

modules/ROOT/pages/schema/constraints/drop-constraints.adoc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,12 @@ FOR ()-[wrote:WROTE]-() REQUIRE wrote.published IS NOT NULL
5959
======
6060
6161
.Drop the constraint `book_isbn`
62+
// tag::schema_constraints_drop[]
6263
[source, cypher]
6364
----
6465
DROP CONSTRAINT book_isbn
6566
----
67+
// tag::schema_constraints_drop[]
6668
6769
.Result
6870
[source, queryresult]
@@ -102,10 +104,12 @@ Constraints can be dropped with a parameterized name.
102104
----
103105
104106
.Drop a constraint with a parameterized name
107+
// tag::schema_constraints_drop_parameter[]
105108
[source, cypher]
106109
----
107110
DROP CONSTRAINT $name
108111
----
112+
// end::schema_constraints_drop_parameter[]
109113
110114
.Result
111115
[source, queryresult]

modules/ROOT/pages/schema/constraints/list-constraints.adoc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,12 @@ FOR ()-[wrote:WROTE]-() REQUIRE wrote.published IS NOT NULL
6666
======
6767
6868
.Query
69+
// tag::schema_constraints_show[]
6970
[source, cypher, test-exclude-cols=id]
7071
----
7172
SHOW CONSTRAINTS
7273
----
74+
// end::schema_constraints_show[]
7375
7476
.Result
7577
[source, queryresult]
@@ -104,10 +106,12 @@ SHOW CONSTRAINTS
104106
To return the full details of the constraints on a database, use `SHOW CONSTRAINTS YIELD *`
105107
106108
.List all constraints with `YIELD *`
109+
// tag::schema_constraints_show_full[]
107110
[source, cypher, test-exclude-cols=id]
108111
----
109112
SHOW CONSTRAINTS YIELD *
110113
----
114+
// end::schema_constraints_show_full[]
111115
112116
.Result
113117
[source, queryresult]
@@ -145,10 +149,12 @@ The filtering of rows can be done using constraint type keywords or a `WHERE` cl
145149
======
146150
147151
.List only key constraints
152+
// tag::schema_constraints_show_type_filter[]
148153
[source, cypher, test-exclude-cols=id]
149154
----
150155
SHOW KEY CONSTRAINTS
151156
----
157+
// end::schema_constraints_show_type_filter[]
152158
153159
.Result
154160
[source, queryresult]
@@ -204,11 +210,13 @@ WHERE entityType = 'RELATIONSHIP'
204210
It is possible to return only specific columns of the available constraints using the `YIELD` clause:
205211
206212
.List only the `name`, `type`, and `createStatement` columns
213+
// tag::schema_constraints_show_specific_columns[]
207214
[source, cypher, test-exclude-cols=id]
208215
----
209216
SHOW CONSTRAINTS
210217
YIELD name, type, createStatement
211218
----
219+
// end::schema_constraints_show_specific_columns[]
212220
213221
.Result
214222
[source, queryresult]

modules/ROOT/pages/schema/graph-types/alter-element-types.adoc

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,22 @@ ALTER CURRENT GRAPH TYPE ALTER {
4444
}
4545
----
4646

47+
////
48+
Cheat sheet example (necessary to exclude <1> tag in the cheat sheet):
49+
50+
// tag::schema_graph_types_alter[]
51+
[source, cypher]
52+
----
53+
ALTER CURRENT GRAPH TYPE ADD {
54+
ALTER {
55+
(:Robot => :Resident&Machine {application :: STRING NOT NULL, id :: INTEGER NOT NULL}),
56+
(:Resident)-[:LIVES_IN => {since :: ANY NOT NULL}]->(:City)
57+
}
58+
----
59+
// end::schema_graph_types_alter[]
60+
61+
////
62+
4763
<1> Nodes with a `Robot` label must now also have a `Machine` label.
4864
`Robot` nodes are also required to have an `id` property of type `INTEGER`.
4965
<2> `since` properties on `LIVES_IN` relationships can now be of `ANY` type (they were previously constrained to be of type `DATE`).

modules/ROOT/pages/schema/graph-types/drop-graph-type-elements.adoc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,15 @@ ALTER CURRENT GRAPH TYPE SET {
3131
To fully drop a xref:schema/graph-types/set-graph-types.adoc#node-element-types[node] or xref:schema/graph-types/set-graph-types.adoc#relationship-element-types[relationship element type], it is only necessary to define its identifying node label/relationship type appended with `\=>`.
3232

3333
.Drop node and relationship element types
34+
// tag::schema_graph_types_drop_elements[]
3435
[source, cypher]
3536
----
3637
ALTER CURRENT GRAPH TYPE DROP {
3738
(:Pet => ),
3839
()-[:LIVES_IN => ]->()
3940
}
4041
----
42+
// end::schema_graph_types_drop_elements[]
4143

4244
You can also define the full element type when dropping an element type.
4345
Partial definitions, however, are not allowed.
@@ -121,13 +123,15 @@ Property existence and property type constraints defined on non-identifying node
121123
The names of constraints are returned by the xref:schema/constraints/list-constraints.adoc[`SHOW CONSTRAINTS`] command or as part of their definitions in xref:schema/graph-types/list-graph-types.adoc[`SHOW CURRENT GRAPH TYPE`].
122124

123125
.Drop explicitly named and generated name key and property uniqueness constraint
126+
// tag::schema_graph_types_drop_constraints[]
124127
[source, cypher]
125128
----
126129
ALTER CURRENT GRAPH TYPE DROP {
127130
CONSTRAINT animal_id,
128131
CONSTRAINT constraint_302a3693
129132
}
130133
----
134+
// end::schema_graph_types_drop_constraints[]
131135

132136
These constraints can also be dropped from the graph type using the xref:schema/constraints/drop-constraints.adoc[`DROP CONSTRAINT`] command.
133137

@@ -144,10 +148,12 @@ To drop a full graph type, use the `ALTER CURRENT GRAPH TYPE SET` command.
144148
This will replace the existing graph type with a new (possibly empty) graph type.
145149

146150
.Drop full graph type and replace it with an empty graph type
151+
// tag::schema_graph_types_drop_full[]
147152
[source, cypher]
148153
----
149154
ALTER CURRENT GRAPH TYPE SET { }
150155
----
156+
// end::schema_graph_types_drop_full[]
151157

152158
.Drop full graph type and replace with a new graph type
153159
[source, cypher]

modules/ROOT/pages/schema/graph-types/extend-graph-types.adoc

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ Extending a graph type requires the following privileges:
1414
====
1515

1616
.Set graph type
17+
// tag::schema_graph_types_set[]
1718
[source, cypher]
1819
----
1920
ALTER CURRENT GRAPH TYPE SET {
@@ -28,6 +29,7 @@ ALTER CURRENT GRAPH TYPE SET {
2829
CONSTRAINT resident_address FOR (resident:Resident) REQUIRE resident.address :: STRING
2930
}
3031
----
32+
// end::schema_graph_types_set[]
3133

3234
[NOTE]
3335
For details about the different elements a graph type can contain, see xref:schema/graph-types/set-graph-types.adoc[].
@@ -44,6 +46,21 @@ ALTER CURRENT GRAPH TYPE ADD {
4446
<1> This adds a node element type with an identifying label also used by an existing key constraint in the graph type (`company_name`).
4547
This addition is possible for property uniqueness and key constraints originally not defined on an identifying label, but not for property existence and property type constraints.
4648

49+
////
50+
Cheat sheet example (necessary to exclude <1> tag in the cheat sheet):
51+
52+
// tag::schema_graph_types_add[]
53+
[source, cypher]
54+
----
55+
ALTER CURRENT GRAPH TYPE ADD {
56+
(:Company => {name :: STRING, address :: STRING IS UNIQUE}),
57+
(:Person)-[:WORKS_FOR => {role :: STRING}]->(:Company)
58+
}
59+
----
60+
// end::schema_graph_types_add[]
61+
62+
////
63+
4764
The extension adds one node element type and one relationship element type to the graph type.
4865
It is implemented with the following constraints:
4966

modules/ROOT/pages/schema/graph-types/list-graph-types.adoc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,12 @@ ALTER CURRENT GRAPH TYPE SET {
2626
----
2727

2828
.Show the full graph type
29+
// tag::schema_graph_types_show[]
2930
[source, cypher]
3031
----
3132
SHOW CURRENT GRAPH TYPE
3233
----
34+
// end::schema_graph_types_show[]
3335

3436
.Result
3537
[source, "queryresult"]

0 commit comments

Comments
 (0)