Skip to content

add code examples in different programming languages #174

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 64 additions & 31 deletions commands/graph.config-get.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,34 +13,67 @@ FalkorDB configuration parameters are detailed [here](/configuration).

`*` can be used to retrieve the value of all FalkorDB configuration parameters.

```
127.0.0.1:6379> graph.config get *
1) 1) "TIMEOUT"
2) (integer) 0
2) 1) "CACHE_SIZE"
2) (integer) 25
3) 1) "ASYNC_DELETE"
2) (integer) 1
4) 1) "OMP_THREAD_COUNT"
2) (integer) 8
5) 1) "THREAD_COUNT"
2) (integer) 8
6) 1) "RESULTSET_SIZE"
2) (integer) -1
7) 1) "VKEY_MAX_ENTITY_COUNT"
2) (integer) 100000
8) 1) "MAX_QUEUED_QUERIES"
2) (integer) 4294967295
9) 1) "QUERY_MEM_CAPACITY"
2) (integer) 0
10) 1) "DELTA_MAX_PENDING_CHANGES"
2) (integer) 10000
11) 1) "NODE_CREATION_BUFFER"
2) (integer) 16384
```

```
127.0.0.1:6379> graph.config get TIMEOUT
1) "TIMEOUT"
2) (integer) 0
```
{% capture shell_0 %}
graph.config get *
# Output:
# 1) 1) "TIMEOUT"
# 2) (integer) 0
# ...
{% endcapture %}

{% capture python_0 %}
from falkordb import FalkorDB
client = FalkorDB()
config = client.get_config('*')
print(config)
{% endcapture %}

{% capture javascript_0 %}
import { FalkorDB } from 'falkordb';
const client = await FalkorDB.connect();
const config = await client.getConfig('*');
console.log(config);
{% endcapture %}

{% capture java_0 %}
FalkorDB client = new FalkorDB();
Map<String, Object> config = client.getConfig("*");
System.out.println(config);
{% endcapture %}

{% capture rust_0 %}
let client = FalkorDB::connect_default();
let config = client.get_config("*")?;
println!("{:?}", config);
{% endcapture %}

{% include code_tabs.html id="config_get_tabs" shell=shell_0 python=python_0 javascript=javascript_0 java=java_0 rust=rust_0 %}

{% capture shell_1 %}
graph.config get TIMEOUT
# Output:
# 1) "TIMEOUT"
# 2) (integer) 0
{% endcapture %}

{% capture python_1 %}
timeout = client.get_config('TIMEOUT')
print(timeout)
{% endcapture %}

{% capture javascript_1 %}
const timeout = await client.getConfig('TIMEOUT');
console.log(timeout);
{% endcapture %}

{% capture java_1 %}
Object timeout = client.getConfig("TIMEOUT");
System.out.println(timeout);
{% endcapture %}

{% capture rust_1 %}
let timeout = client.get_config("TIMEOUT")?;
println!("{:?}", timeout);
{% endcapture %}

{% include code_tabs.html id="config_get_timeout_tabs" shell=shell_1 python=python_1 javascript=javascript_1 java=java_1 rust=rust_1 %}
95 changes: 80 additions & 15 deletions commands/graph.config-set.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,83 @@ FalkorDB configuration parameters are detailed [here](/configuration).

Note: As detailed in the link above, not all FalkorDB configuration parameters can be set at run-time.

```
127.0.0.1:6379> graph.config get TIMEOUT
1) "TIMEOUT"
2) (integer) 0
127.0.0.1:6379> graph.config set TIMEOUT 10000
OK
127.0.0.1:6379> graph.config get TIMEOUT
1) "TIMEOUT"
2) (integer) 10000
```

```
127.0.0.1:6379> graph.config set THREAD_COUNT 10
(error) This configuration parameter cannot be set at run-time
```
{% capture shell_0 %}
graph.config get TIMEOUT
graph.config set TIMEOUT 10000
graph.config get TIMEOUT
# Output:
# 1) "TIMEOUT"
# 2) (integer) 0
# OK
# 1) "TIMEOUT"
# 2) (integer) 10000
{% endcapture %}

{% capture python_0 %}
from falkordb import FalkorDB
client = FalkorDB()
print(client.get_config('TIMEOUT'))
client.set_config('TIMEOUT', 10000)
print(client.get_config('TIMEOUT'))
{% endcapture %}

{% capture javascript_0 %}
import { FalkorDB } from 'falkordb';
const client = await FalkorDB.connect();
console.log(await client.getConfig('TIMEOUT'));
await client.setConfig('TIMEOUT', 10000);
console.log(await client.getConfig('TIMEOUT'));
{% endcapture %}

{% capture java_0 %}
FalkorDB client = new FalkorDB();
System.out.println(client.getConfig("TIMEOUT"));
client.setConfig("TIMEOUT", 10000);
System.out.println(client.getConfig("TIMEOUT"));
{% endcapture %}

{% capture rust_0 %}
let client = FalkorDB::connect_default();
println!("{:?}", client.get_config("TIMEOUT")?);
client.set_config("TIMEOUT", 10000)?;
println!("{:?}", client.get_config("TIMEOUT")?);
{% endcapture %}

{% include code_tabs.html id="config_set_tabs" shell=shell_0 python=python_0 javascript=javascript_0 java=java_0 rust=rust_0 %}

{% capture shell_1 %}
graph.config set THREAD_COUNT 10
# Output:
# (error) This configuration parameter cannot be set at run-time
{% endcapture %}

{% capture python_1 %}
try:
client.set_config('THREAD_COUNT', 10)
except Exception as e:
print(e)
{% endcapture %}

{% capture javascript_1 %}
try {
await client.setConfig('THREAD_COUNT', 10);
} catch (e) {
console.error(e);
}
{% endcapture %}

{% capture java_1 %}
try {
client.setConfig("THREAD_COUNT", 10);
} catch (Exception e) {
System.out.println(e);
}
{% endcapture %}

{% capture rust_1 %}
if let Err(e) = client.set_config("THREAD_COUNT", 10) {
println!("{}", e);
}
{% endcapture %}

{% include code_tabs.html id="config_set_error_tabs" shell=shell_1 python=python_1 javascript=javascript_1 java=java_1 rust=rust_1 %}
133 changes: 89 additions & 44 deletions commands/graph.constraint-create.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,65 +125,110 @@ is a list of `propCount` property names.

To create a unique constraint for all nodes with label `Person` enforcing uniqueness on the combination of values of attributes `first_name` and `last_name`, issue the following commands:

```sh
{% capture shell_0 %}
redis> GRAPH.QUERY g "CREATE INDEX FOR (p:Person) ON (p.first_name, p.last_name)"
1) 1) "Indices created: 2"
2) "Cached execution: 0"
3) "Query internal execution time: 25.779500 milliseconds"
redis> GRAPH.CONSTRAINT CREATE g UNIQUE NODE Person PROPERTIES 2 first_name last_name
PENDING
```

Since v2.12 indexes are constructed asynchronously. The constraint construction will start once the index is fully constructed.
# Output: PENDING
{% endcapture %}

{% capture python_0 %}
from falkordb import FalkorDB
client = FalkorDB()
graph = client.select_graph('g')
graph.query("CREATE INDEX FOR (p:Person) ON (p.first_name, p.last_name)")
result = client.create_constraint('g', 'UNIQUE', 'NODE', 'Person', ['first_name', 'last_name'])
print(result)
{% endcapture %}

{% capture javascript_0 %}
import { FalkorDB } from 'falkordb';
const client = await FalkorDB.connect();
const graph = client.selectGraph('g');
await graph.query("CREATE INDEX FOR (p:Person) ON (p.first_name, p.last_name)");
const result = await client.createConstraint('g', 'UNIQUE', 'NODE', 'Person', ['first_name', 'last_name']);
console.log(result);
{% endcapture %}

{% capture java_0 %}
FalkorDB client = new FalkorDB();
Graph graph = client.selectGraph("g");
graph.query("CREATE INDEX FOR (p:Person) ON (p.first_name, p.last_name)");
String result = client.createConstraint("g", "UNIQUE", "NODE", "Person", Arrays.asList("first_name", "last_name"));
System.out.println(result);
{% endcapture %}

{% capture rust_0 %}
let client = FalkorDB::connect_default();
let graph = client.select_graph("g");
graph.query("CREATE INDEX FOR (p:Person) ON (p.first_name, p.last_name)")?;
let result = client.create_constraint("g", "UNIQUE", "NODE", "Person", &["first_name", "last_name"])?;
println!("{}", result);
{% endcapture %}

{% include code_tabs.html id="unique_constraint_tabs" shell=shell_0 python=python_0 javascript=javascript_0 java=java_0 rust=rust_0 %}

### Creating a mandatory constraint for a relationship type

To create a mandatory constraint for all edges with relationship-type `Visited`, enforcing the existence of a `date` attribute, issue the following command:

```sh
{% capture shell_1 %}
redis> GRAPH.CONSTRAINT CREATE g MANDATORY RELATIONSHIP Visited PROPERTIES 1 date
PENDING
```
# Output: PENDING
{% endcapture %}

## Deleting a constraint
{% capture python_1 %}
result = client.create_constraint('g', 'MANDATORY', 'RELATIONSHIP', 'Visited', ['date'])
print(result)
{% endcapture %}

See [GRAPH.CONSTRAINT DROP](/commands/graph.constraint-drop)
{% capture javascript_1 %}
const result = await client.createConstraint('g', 'MANDATORY', 'RELATIONSHIP', 'Visited', ['date']);
console.log(result);
{% endcapture %}

{% capture java_1 %}
String result = client.createConstraint("g", "MANDATORY", "RELATIONSHIP", "Visited", Arrays.asList("date"));
System.out.println(result);
{% endcapture %}

{% capture rust_1 %}
let result = client.create_constraint("g", "MANDATORY", "RELATIONSHIP", "Visited", &["date"])?;
println!("{}", result);
{% endcapture %}

## Listing constraints
{% include code_tabs.html id="mandatory_constraint_tabs" shell=shell_1 python=python_1 javascript=javascript_1 java=java_1 rust=rust_1 %}

### Listing constraints

To list all constraints enforced on a given graph, use the `db.constraints` procedure:

```sql
GRAPH.RO_QUERY <key> "CALL db.constraints()"
```
{% capture shell_2 %}
redis> GRAPH.RO_QUERY g "call db.constraints()"
# Output: ...
{% endcapture %}

For each constraint the procedure will yield the following fields:
{% capture python_2 %}
result = graph.ro_query("call db.constraints()")
print(result)
{% endcapture %}

| Field | Description |
| ------------ | ------------------------------------------------------ |
| `type` | type of constraint, either `UNIQUE` or `MANDATORY` |
| `label` | label or relationship-type enforced by the constraint |
| `properties` | list of properties enforced by the constraint |
| `entitytype` | type of entity, either `NODE` or `RELATIONSHIP` |
| `status` | either `UNDER CONSTRUCTION`, `OPERATIONAL` or `FAILED` |
{% capture javascript_2 %}
const result = await graph.ro_query("call db.constraints()");
console.log(result);
{% endcapture %}

Example:
{% capture java_2 %}
ResultSet result = graph.ro_query("call db.constraints()");
System.out.println(result);
{% endcapture %}

```sh
redis> GRAPH.RO_QUERY g "call db.constraints()"
1) 1) "type"
2) "label"
3) "properties"
4) "entitytype"
5) "status"
2) 1) 1) "UNIQUE"
2) "Person"
3) "[birthdate]"
4) "NODE"
5) "UNDER CONSTRUCTION"
2) 1) "MANDATORY"
2) "Person"
3) "[first_name, last_name]"
4) "NODE"
5) "OPERATIONAL"
```
{% capture rust_2 %}
let result = graph.ro_query("call db.constraints()")?;
println!("{:?}", result);
{% endcapture %}

{% include code_tabs.html id="list_constraints_tabs" shell=shell_2 python=python_2 javascript=javascript_2 java=java_2 rust=rust_2 %}

## Deleting a constraint

See [GRAPH.CONSTRAINT DROP](/commands/graph.constraint-drop)
34 changes: 31 additions & 3 deletions commands/graph.constraint-drop.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,35 @@ is a list of `propCount` property names.

To delete a unique constraint for all nodes with label `Person` enforcing uniqueness on the combination of values of attributes `first_name` and `last_name`, issue the following command:

```
{% capture shell_0 %}
redis> GRAPH.CONSTRAINT DROP g UNIQUE NODE Person PROPERTIES 2 first_name last_name
OK
```
# Output: OK
{% endcapture %}

{% capture python_0 %}
from falkordb import FalkorDB
client = FalkorDB()
result = client.drop_constraint('g', 'UNIQUE', 'NODE', 'Person', ['first_name', 'last_name'])
print(result)
{% endcapture %}

{% capture javascript_0 %}
import { FalkorDB } from 'falkordb';
const client = await FalkorDB.connect();
const result = await client.dropConstraint('g', 'UNIQUE', 'NODE', 'Person', ['first_name', 'last_name']);
console.log(result);
{% endcapture %}

{% capture java_0 %}
FalkorDB client = new FalkorDB();
String result = client.dropConstraint("g", "UNIQUE", "NODE", "Person", Arrays.asList("first_name", "last_name"));
System.out.println(result);
{% endcapture %}

{% capture rust_0 %}
let client = FalkorDB::connect_default();
let result = client.drop_constraint("g", "UNIQUE", "NODE", "Person", &["first_name", "last_name"])?;
println!("{}", result);
{% endcapture %}

{% include code_tabs.html id="drop_constraint_tabs" shell=shell_0 python=python_0 javascript=javascript_0 java=java_0 rust=rust_0 %}
Loading
Loading