arakaki-yuji / cosmosdb-client
Installs: 1 565
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 1
Open Issues: 0
Requires
- guzzlehttp/guzzle: ^6.3
Requires (Dev)
- phpunit/phpunit: ^7.5
README
tiny cosmosdb client library for PHP.
installation
Include arakaki-yuji/cosmosdb-client in your project, by adding it to your composer.json file.
{ "require": { "arakaki-yuji/cosmosdb-client": "^0.0.5" } }
Usage
Init
$client = new \CosmosdbClient\CosmosdbClient($cosmosdbSecretKey, $cosmosdbAccountName);
Database
// create database $client->database->create('database_id'); // list database $client->database->list(); // get database $client->database->get('database_id'); // delete database $client->database->delete('database_id');
Collection
// create collection $indexingPolicy = ['indexingMode' => 'lazy']; $partitionKey = ['paths' => ['/Name']]; $client->collection->create('database_id', 'collection_id', $indexingPolicy, $partitionKey); // list collection $client->collection->list('database_id'); // get collection $client->collection->get('database_id', 'collection_id'); // replace/update collection $client->collection->replace('database_id', 'collection_id', $indexingPolicy, $partitionKey); // delete collection $client->collection->delete('database_id', 'collection_id');
Document
// create document $doc = [ 'id' => 1, 'name' => 'Yuji Arakaki', 'email' => 'example@test.com' ]; $partitionKeyValue = $doc['name']; $client->document->create('database_id', 'collection_id', $doc, $partitionKeyValue); // list document $client->document->list('database_id', 'collection_id'); // get document $client->document->get('database_id', 'collection_id', $doc['id'], $partitionKeyValue); // replace/update document $client->document->replace('database_id', 'collection_id', $doc, $partitionKeyValue); // query document $query = "SELECT * FROM c WHERE c.name = @name"; $parameters = [['name' => '@name', 'value' => 'Yuji Arakaki']]; $client->document->query('database_id', 'collection_id', $query, $parameters); // delete document $client->document->delete('database_id', 'collection_id', $doc['id'], $partitionKeyValue);