Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
Nuno Chaves authored Sep 27, 2018
1 parent fcd5189 commit af168c7
Showing 1 changed file with 43 additions and 24 deletions.
67 changes: 43 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,47 +15,66 @@ Include jupitern/table in your project, by adding it to your composer.json file.
## Usage
```php

// make connection
$docdb = new AzureCosmosDb($uri, $key);
$conn = $docdb->selectDB($db);
$conn = app()->resolve('DocDB');

$rid = \Jupitern\CosmosDb\QueryBuilder::instance()
->setConnection($conn)
->collection("Users")
->save(['id' => '1', 'name' => 'John Doe', 'age' => 22]);

echo "record inserted: $rid";

$rid = \Jupitern\CosmosDb\QueryBuilder::instance()
->setConnection($conn)
->collection("Users")
->save(['id' => '2', 'name' => 'Jane doe', 'age' => 35]);

echo "record inserted: $rid";

$res = \Jupitern\CosmosDb\QueryBuilder::instance()
->setConnection($conn)
->collection("Users")
->save(["_rid" => $rid, 'id' => '2', 'name' => 'Jane Doe Something', 'age' => 36]);

echo "record updated: $rid";

// get one row as array
$res = \Jupitern\CosmosDb\QueryBuilder::instance()
->setConnection($conn)
->collection("Users")
->select("Users.id, Users.username")
->where("Users.id = '4uc234ocu23h4o'")
->find()
->toArray();
->setConnection($conn)
->collection("Users")
->select("Users.id, Users.name")
->where("Users.age > 30")
->find()
->toArray();

var_dump($res);

// get 5 rows as array
$res = \Jupitern\CosmosDb\QueryBuilder::instance()
->setConnection($conn)
->collection("Users")
->select("Users.id, Users.username")
->where("Users.age > 18")
->limit(5)
->findAll()
->toArray();
->setConnection($conn)
->collection("Users")
->select("Users.id, Users.username")
->where("Users.age > 20")
->limit(5)
->findAll()
->toArray();

var_dump($res);

// delete one document
$res = \Jupitern\CosmosDb\QueryBuilder::instance()
->setConnection($conn)
->collection("Users")
->where("Users.age > 18")
->delete();
->setConnection($conn)
->collection("Users")
->where("Users.age > 30")
->delete();

var_dump($res);

// delete all documents
$res = \Jupitern\CosmosDb\QueryBuilder::instance()
->setConnection($conn)
->collection("Users")
->where("Users.age > 18")
->deleteAll();
->setConnection($conn)
->collection("Users")
->where("Users.age > 20")
->deleteAll();

var_dump($res);

0 comments on commit af168c7

Please sign in to comment.