Skip to content

Commit 671f8c6

Browse files
committed
wip
1 parent efea48a commit 671f8c6

File tree

2 files changed

+183
-47
lines changed

2 files changed

+183
-47
lines changed

docs/constraint.md

Lines changed: 91 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,98 @@
11
# Constraint
22

3-
Constraints are entities which contain the following attributes:
3+
Constraints are used to enforce specific data schemas within a database.
4+
There are two different types of constraints, one for nodes and one for relationships.
5+
They can be created as following:
46

5-
- **ConstraintName**: Zero or one constraint name, usually one. They are basically strings with validation. They must be
6-
snake_case as per [Neo4j's examples](https://neo4j.com/docs/cypher-manual/current/constraints/examples/).
7-
Constraint names can start with a single underscore, although this is reserved for internal logic.
8-
You can overwrite the validation part by creating your own implementation of
9-
`Syndesi\CypherDataStructures\Contract\ConstraintNameInterface`.
10-
- **ConstraintType**: Defines how the constraint works, must be set manually.
11-
- **For**: Can be either a `NodeLabel` or `RelationType`.
12-
- **Properties**: Properties on which the constraint applies to. At least one is required.
13-
- **Options**: Options which configure constraint dependant settings, usually empty.
7+
```php
8+
use Syndesi\CypherDataStructures\Type\NodeConstraint;
9+
use Syndesi\CypherDataStructures\Type\RelationConstraint;
10+
11+
$nodeConstraint = new NodeConstraint();
12+
$relationConstraint = new RelationConstraint();
13+
14+
// note: the later examples use $someConstraint when the specific type does not matter
15+
```
16+
17+
!> **Important**: Constraints are not part of the OpenCypher specification and are different for each database type.
18+
19+
!> **Note**: The creation of constraints might create internal indexes as well.
20+
21+
## Name
22+
23+
The name of constraints must be unique across the whole database.
24+
The name is usually written in [lowercase snake case](https://neo4j.com/docs/cypher-manual/current/constraints/examples/).
25+
26+
```php
27+
// set the name of a constraint:
28+
$someConstraint->setName('some_name');
29+
30+
// get the name of a constraint:
31+
$someConstraint->getName();
32+
```
33+
34+
## For
35+
36+
Constraints are always created for a specific node or relationship label/type.
37+
38+
```php
39+
// set the node label for a node label constraint:
40+
$nodeConstraint->setFor('NodeLabel');
41+
42+
// set the relationship type for a relationship constraint:
43+
$relationConstraint->setFor('RELATIONSHIP_TYPE');
44+
45+
// get the node label or relationship type from a constraint, depending on the constraint type:
46+
$someConstraint->getFor();
47+
```
48+
49+
## Type
50+
51+
Constraints have a specific type, e.g. `UNIQUE`. These types depend on the database as well as the database version.
52+
53+
!> **Important**: Depending on the database, not all constraint types are available for nodes as well as relationships.
54+
55+
```php
56+
// set the type of constraint:
57+
$someConstraint->setType('UNIQUE');
58+
59+
// get the type of constraint:
60+
$someConstraint->getType();
61+
```
62+
63+
## Properties
1464

15-
## Examples
65+
Constraints can specify the properties of a node/relationship on which they should act.
66+
67+
!> **Note**: Most of the time only the property names are important. Setting the property values to null is therefore
68+
ok.
1669

1770
```php
18-
use Syndesi\CypherDataStructures\Type\ConstraintName;
19-
use Syndesi\CypherDataStructures\Type\Constraint;
20-
use Syndesi\CypherDataStructures\Type\ConstraintType;
21-
use Syndesi\CypherDataStructures\Type\NodeLabel;
22-
use Syndesi\CypherDataStructures\Type\PropertyName;
23-
24-
$constraint = new Constraint();
25-
$constraint
26-
->setConstraintName(new ConstraintName('some_name'))
27-
->setConstraintType(ConstraintType::UNIQUE)
28-
->setFor(new NodeLabel('SomeNode'))
29-
->addProperty(new PropertyName('id'));
71+
// add property to a constraint with default value null:
72+
$someConstraint->addProperty('propertyName');
73+
74+
// add multiple properties to a constraint:
75+
$someConstraint->addProperties([
76+
'id' => null,
77+
'hello' => 'world :D'
78+
]);
79+
80+
// check if a constraint has a specific property:
81+
$someConstraint->hasProperty('id');
82+
83+
// get the value of a specific property:
84+
$someConstraint->getProperty('id');
85+
86+
// get all properties from a constraint:
87+
$someConstraint->getProperties();
88+
89+
// remove a specific property from a constraint:
90+
$someConstraint->removeProperty('hello');
91+
92+
// remove all properties from a constraint:
93+
$someConstraint->removeProperties();
3094
```
95+
96+
## Options
97+
98+
WIP

docs/type.index.md

Lines changed: 92 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,99 @@
11
# Index
22

3-
Indexes are entities which contain the following attributes:
3+
Indexes are hints for the database to optimize the way data is stored so that specific operations are faster.
4+
There are two different types of indexes, one for nodes and one for relationships.
5+
They can be created as following:
46

5-
- **IndexName**: Zero or one index name, usually one. They are basically strings with validation. They must be
6-
snake_case as per [Neo4j's examples
7-
](https://neo4j.com/docs/cypher-manual/current/indexes-for-search-performance/#administration-indexes-examples).
8-
Index names can start with a single underscore, although this is reserved for internal logic.
9-
You can overwrite the validation part by creating your own implementation of
10-
`Syndesi\CypherDataStructures\Contract\IndexNameInterface`.
11-
- **IndexType**: Defines how the index works, should usually be set to `BTREE`.
12-
- **For**: Can be either a `NodeLabel` or `RelationType`.
13-
- **Properties**: Properties on which the index applies to. At least one is required.
14-
- **Options**: Options which configure index dependant settings, usually empty.
7+
```php
8+
use Syndesi\CypherDataStructures\Type\NodeIndex;
9+
use Syndesi\CypherDataStructures\Type\RelationIndex;
10+
11+
$nodeIndex = new NodeIndex();
12+
$relationIndex = new RelationIndex();
13+
14+
// note: the later examples use $someIndex when the specific type does not matter
15+
```
16+
17+
!> **Important**: Indexes are not part of the OpenCypher specification and are different for each database type.
18+
19+
!> **Note**: The creation of constraints might create internal indexes as well.
20+
21+
## Name
22+
23+
The name of indexes must be unique across the whole database.
24+
The name is usually written in [lowercase snake case](https://neo4j.com/docs/cypher-manual/current/indexes-for-search-performance/#administration-indexes-examples).
25+
26+
```php
27+
// set the name of an index:
28+
$someIndex->setName('some_name');
29+
30+
// get the name of an index:
31+
$someIndex->getName();
32+
```
33+
34+
## For
35+
36+
Indexes are always created for a specific node or relationship label/type.
37+
38+
```php
39+
// set the node label for a node label index:
40+
$nodeIndex->setFor('NodeLabel');
41+
42+
// set the relationship type for a relationship index:
43+
$relationIndex->setFor('RELATIONSHIP_TYPE');
44+
45+
// get the node label or relationship type from an index, depending on the index type:
46+
$someIndex->getFor();
47+
```
48+
49+
## Type
50+
51+
Indexes have a specific type, e.g. `BTREE` or `RANGE`. These types depend on the database as well as the database
52+
version.
53+
54+
!> **Important**: Depending on the database, not all index types are available for nodes as well as relationships.
55+
56+
```php
57+
// set the type of index:
58+
$someIndex->setType('BTREE');
59+
60+
// get the type of index:
61+
$someIndex->getType();
62+
```
63+
64+
## Properties
1565

16-
## Examples
66+
Indexes can specify the properties of a node/relationship on which they should act.
67+
68+
!> **Note**: Most of the time only the property names are important. Setting the property values to null is therefore
69+
ok.
1770

1871
```php
19-
use Syndesi\CypherDataStructures\Type\IndexName;
20-
use Syndesi\CypherDataStructures\Type\Index;
21-
use Syndesi\CypherDataStructures\Type\IndexType;
22-
use Syndesi\CypherDataStructures\Type\NodeLabel;
23-
use Syndesi\CypherDataStructures\Type\PropertyName;
24-
25-
$index = new Index();
26-
$index
27-
->setIndexName(new IndexName('some_name'))
28-
->setIndexType(IndexType::BTREE)
29-
->setFor(new NodeLabel('SomeNode'))
30-
->addProperty(new PropertyName('id'));
72+
// add property to an index with default value null:
73+
$someIndex->addProperty('propertyName');
74+
75+
// add multiple properties to an index:
76+
$someIndex->addProperties([
77+
'id' => null,
78+
'hello' => 'world :D'
79+
]);
80+
81+
// check if an index has a specific property:
82+
$someIndex->hasProperty('id');
83+
84+
// get the value of a specific property:
85+
$someIndex->getProperty('id');
86+
87+
// get all properties from an index:
88+
$someIndex->getProperties();
89+
90+
// remove a specific property from an index:
91+
$someIndex->removeProperty('hello');
92+
93+
// remove all properties from an index:
94+
$someIndex->removeProperties();
3195
```
96+
97+
## Options
98+
99+
WIP

0 commit comments

Comments
 (0)