Skip to content

Commit ae385dd

Browse files
Improved configuration and added documentation
docs: statement, database/collection/index schema functions and placeholders feat: Added profile statement function chore: cleaned up statement class
1 parent ee030a5 commit ae385dd

17 files changed

+684
-154
lines changed

README.md

+18-14
Original file line numberDiff line numberDiff line change
@@ -49,23 +49,27 @@ $statement->execute();
4949
$users = $statement->fetchAll();
5050
```
5151

52+
Alternatively you can traverse over the statement itself to get the results one at a time.
53+
```
54+
$statement = $client->prepare('FOR user in users RETURN user');
55+
$statement->execute();
56+
foreach ($statement as $document) {
57+
//
58+
}
59+
```
60+
5261
## Managers
5362
You have access to several managers that allow you to perform specific tasks on your ArangoDB instance(s).
5463

55-
(ArangoDB's endpoints are mapped to these managers in a semantically functional manner. Therefore a manager
56-
may have functionality from different endpoints within ArangoDB's HTTP API.)
57-
58-
### Admin
59-
Manages administrative functions to manage the server/cluster and retrieve server level information.
60-
```
61-
$client->admin()->getVersion();
62-
```
63-
64-
### Schema
65-
The schema manager allows you perform tasks like creating databases, collections, indexes, views and graphs
66-
```
67-
$client->schema()->createCollection('users');
68-
```
64+
## Documentation
65+
1) [ArangoDB PHP Client](docs/arangodb-client.md)
66+
2) [Statements](docs/statements.md)
67+
3) [Database schema](docs/schema-databases.md)
68+
4) [User schema](docs/schema-users.md)
69+
5) [Collection schema](docs/schema-collections.md)
70+
6) [Index schema](docs/schema-indexes.md)
71+
7) [View schema](docs/schema-views.md)
72+
8) [Admin manager](docs/admin-manager.md)
6973

7074
## Related packages
7175
[AQL query builder](https://github.com/LaravelFreelancerNL/fluentaql)

docs/admin-manager.md

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Admin manager
2+
3+
Manages administrative functions to manage the server/cluster and retrieve server level information.
4+
5+
## Functions
6+
The admin manager supports the following functions:
7+
8+
### getVersion(bool $details = false): array
9+
Get the ArangoDB version of the server
10+
11+
```
12+
$arangoClient->admin()->getVersion();
13+
```

docs/arangodb-client.md

+96
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
# ArangoDB PHP Client
2+
```
3+
$arangoClient = new ArangoClient($config);
4+
```
5+
6+
## Configuration
7+
Upon creation, you can alter the default configuration of the client. The following options are available:
8+
* endpoint = 'http://localhost:8529'
9+
* host = null
10+
* port = null
11+
* username = null
12+
* password = null
13+
* database = '_system'
14+
* connection = 'Keep-Alive'
15+
16+
```
17+
$config = [
18+
'endpoint' => 'http://localhost:8529',
19+
'username' => 'your-database-username',
20+
'password' => 'your-database-password',
21+
'database'=> 'your-database'
22+
];
23+
24+
$arangoClient = new ArangoClient($config);
25+
```
26+
27+
### Support Guzzle configuration
28+
In addition to the above mentioned options you can use the following Guzzle 7 specific options:
29+
* allow_redirects
30+
* connect_timeout
31+
32+
### Endpoint vs host/port
33+
Some common packages and frameworks work with a host/port combination by default.
34+
When no endpoint is provided it is constructed from these two options.
35+
36+
```
37+
$config = [
38+
'host' => 'http://localhost',
39+
'port' => '8529',
40+
'username' => 'your-database-username',
41+
'password' => 'your-database-password',
42+
'database'=> 'your-database'
43+
];
44+
45+
$arangoClient = new ArangoClient($config);
46+
```
47+
48+
## Functions
49+
50+
### request(string $method, string $uri, array $options = []): array
51+
Send a request to ArangoDB's HTTP REST API. This is mostly for internal use but allows you to use unsupported endpoints.
52+
```
53+
$arangoClient->request(
54+
'get',
55+
'/_api/version',
56+
'query' => [
57+
'details' => $details
58+
]
59+
]);
60+
```
61+
62+
### getConfig(): array
63+
Get the current configuration.
64+
```
65+
$arangoClient->getConfig()
66+
```
67+
68+
### getUser(): string
69+
Return the username;
70+
```
71+
$arangoClient->getUser();
72+
```
73+
74+
### setDatabase(string $name): void
75+
Set the database to be used for the upcoming requests
76+
```
77+
$arangoClient->setDatabase('ArangoClientDB');
78+
```
79+
80+
### getDatabase(): string
81+
Return the database name;
82+
```
83+
$database = $arangoClient->getDatabase();
84+
```
85+
86+
### schema(): SchemaManager
87+
Pass chained method to the schema manager.
88+
```
89+
$arangoClient->schema()->createCollection('users');
90+
```
91+
92+
### admin(): AdminManager
93+
Pass chained method to the admin manager.
94+
```
95+
$arangoClient->admin()->getVersion();
96+
```

docs/schema-collections.md

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# Schema manager - Collections
2+
You can use the schema manager to perform CRUD actions on collections within an ArangoDB database.
3+
4+
## Collection functions
5+
The schema manager supports the following collection functions:
6+
7+
### getCollections(bool $excludeSystemCollections = false): array
8+
Get a list of collections within the database
9+
```
10+
$arangoClient->schema()->getCollections();
11+
```
12+
13+
### getCollection(string $name): array
14+
Get the requested collection.
15+
```
16+
$arangoClient->schema()->getCollection('_fishbowl');
17+
```
18+
19+
### getCollectionProperties(string $collection): array
20+
Get the properties of the requested collection.
21+
```
22+
$arangoClient->schema()->getCollectionProperties('_fishbowl');
23+
```
24+
25+
### getCollectionWithDocumentCount(string $collection): array
26+
Get the properties of the requested collection.
27+
```
28+
$arangoClient->schema()->getCollectionWithDocumentCount('_fishbowl');
29+
```
30+
31+
### getCollectionStatistics(string $collection, bool $details = false): array
32+
Get the properties of the requested collection.
33+
```
34+
$arangoClient->schema()->getCollectionStatistics('_fishbowl');
35+
```
36+
37+
### hasCollection(string $collection): bool
38+
Check if a collection exists.
39+
```
40+
$arangoClient->schema()->hasCollection('_fishbowl');
41+
```
42+
43+
### createCollection(string $collection, array $config = [], $waitForSyncReplication = null, $enforceReplicationFactor = null): bool
44+
Create a collection
45+
```
46+
$arangoClient->schema()->createCollection('users');
47+
```
48+
49+
### updateCollection(string $name, array $config = []): array
50+
Update a collection
51+
```
52+
$arangoClient->schema()->updateCollection('users', ['waitForSync' => true]);
53+
```
54+
55+
### renameCollection(string $old, string $new): array
56+
Rename a collection
57+
```
58+
$arangoClient->schema()->renameCollection('users', 'characters');
59+
```
60+
61+
### deleteCollection(string $name): bool
62+
Delete a collection
63+
```
64+
$arangoClient->schema()->deleteCollection('users');
65+
```
66+

docs/schema-databases.md

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Schema manager - Databases
2+
You can use the schema manager to perform CRUD actions on databases within ArangoDB.
3+
4+
## Database functions
5+
6+
### getCurrentDatabase(): array
7+
Get information on the current database
8+
```
9+
$arangoClient->schema()->getCurrentDatabase();
10+
```
11+
12+
### getDatabases(): array
13+
Get a list of databases accessible to the current user.
14+
```
15+
$arangoClient->schema()->getDatabases();
16+
```
17+
18+
### hasDatabase(string $name): bool
19+
Check if a database exists
20+
```
21+
$arangoClient->schema()->hasDatabase('someNoneExistingDatabase');
22+
```
23+
24+
### createDatabase(string $name, $options = null, $users = null): bool
25+
Create a database.
26+
27+
[See ArangoDB's documentation for the current available options](https://www.arangodb.com/docs/stable/http/database-database-management.html#create-database)
28+
```
29+
$arangoClient->schema()->createDatabase('someNoneExistingDatabase');
30+
```
31+
32+
### deleteDatabase(string $name): bool
33+
Delete the given database.
34+
```
35+
$arangoClient->schema()->deleteDatabase('someExistingDatabase');
36+
```

docs/schema-indexes.md

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Schema manager - Collections
2+
You can use the schema manager to perform CRUD actions on indexes within a collection.
3+
4+
## Index functions
5+
The schema manager supports the following index functions:
6+
7+
### createIndex(string $collection, array $index): bool
8+
Create an index on the given collection
9+
```
10+
$arangoClient->schema()->createIndex(
11+
'users',
12+
[
13+
'name' => 'email_persistent_unique',
14+
'type' => 'persistent',
15+
'fields' => ['profile.email'],
16+
'unique' => true,
17+
'sparse' => false
18+
]
19+
);
20+
```
21+
22+
### deleteIndex(string $id): bool
23+
Delete an index by its ID.
24+
```
25+
$arangoClient->schema()->deleteIndex($id);
26+
```
27+
28+
### getIndex(string $id): array
29+
Get an index by its ID.
30+
```
31+
$arangoClient->schema()->getIndex($id);
32+
```
33+
34+
### getIndexByName(string $collection, string $name)
35+
Get an index by its name.
36+
```
37+
$arangoClient->schema()->getIndexByName('email_persistent_unique');
38+
```
39+
40+
### getIndexes(string $collection): array
41+
Get all indexes on a collection.
42+
```
43+
$arangoClient->schema()->getIndexes('users);
44+
```

docs/schema-users.md

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Schema manager - Users
2+
You can use the schema manager to perform CRUD actions on database users.
3+
4+
## User functions
5+
The schema manager supports the following index functions:
6+

docs/schema-views.md

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Schema manager - Views
2+
You can use the schema manager to perform CRUD actions on indexes within a collection.
3+
4+
## View functions
5+
The schema manager supports the following index functions:
6+

docs/statements.md

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# AQL Statements
2+
To run AQL queries you prepare a query, execute it and fetch the results. Much like PHP's PDO extension.
3+
```
4+
$statement = $client->prepare('FOR user in users RETURN user');
5+
$statement->execute();
6+
$users = $statement->fetchAll();
7+
8+
foreach ($users as $user) {
9+
//
10+
}
11+
```
12+
13+
Alternatively you can traverse over the statement itself to get the results one at a time.
14+
```
15+
$statement = $client->prepare('FOR user in users RETURN user');
16+
$statement->execute();
17+
foreach ($statement as $document) {
18+
//
19+
}
20+
```
21+
22+
## Statement functions
23+
24+
### explain(): array
25+
Get information on the current database
26+
```
27+
$statement->explain();
28+
```
29+
30+
### parse(): array
31+
Parses the query and throws an ArangoException if the AQL is invalid.
32+
```
33+
$statement->parse();
34+
```
35+
36+
### profile(): array
37+
Execute the query and return the results and query performance information.
38+
```
39+
$statement->profile();
40+
```
41+
42+
### execute(): bool
43+
Execute the query. The results are loaded in the statement which can be iterated over.
44+
```
45+
$statement->execute();
46+
```
47+
48+
### fetchAll(): array
49+
Execute the query. The results are loaded in the statement which can be iterated over.
50+
```
51+
$statement->execute();
52+
```
53+
54+
### setQuery(string $query): self
55+
Execute the query. The results are loaded in the statement which can be iterated over.
56+
```
57+
$statement->setQuery('FOR user IN users RETURN user');
58+
```
59+
60+
### getQuery(): string
61+
Execute the query. The results are loaded in the statement which can be iterated over.
62+
```
63+
$query = $statement->getQuery();
64+
```
65+
66+
### getCount(): ?int
67+
Get the total number of results from the database. Only available if the corresponding query option is set.
68+
```
69+
$statement->getCount();
70+
```
71+

0 commit comments

Comments
 (0)