Skip to content

Commit bdf1fe3

Browse files
author
Nuno Chaves
authored
Merge pull request #7 from jupitern/development
->setDatabase($db) no longer needed
2 parents 16c808a + 87404ad commit bdf1fe3

File tree

3 files changed

+3
-32
lines changed

3 files changed

+3
-32
lines changed

README.md

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ $collection = $db->selectCollection('collectionName');
5252

5353
// insert a record
5454
$rid = \Jupitern\CosmosDb\QueryBuilder::instance()
55-
->setDatabase($db)
5655
->setCollection($collection)
5756
->setPartitionKey('country')
5857
->save(['id' => '1', 'name' => 'John Doe', 'age' => 22, 'country' => 'Portugal']);
@@ -61,7 +60,6 @@ echo "record inserted: $rid".PHP_EOL;
6160

6261
// insert a record
6362
$rid = \Jupitern\CosmosDb\QueryBuilder::instance()
64-
->setDatabase($db)
6563
->setCollection($collection)
6664
->setPartitionKey('country')
6765
->save(['id' => '2', 'name' => 'Jane doe', 'age' => 35, 'country' => 'Portugal']);
@@ -70,7 +68,6 @@ echo "record inserted: $rid".PHP_EOL;
7068

7169
// update a record
7270
$rid = \Jupitern\CosmosDb\QueryBuilder::instance()
73-
->setDatabase($db)
7471
->setCollection($collection)
7572
->setPartitionKey('country')
7673
->save(["_rid" => $rid, 'id' => '2', 'name' => 'Jane Doe Something', 'age' => 36, 'country' => 'Portugal']);
@@ -81,7 +78,6 @@ echo "get one row as array:".PHP_EOL;
8178

8279
// get one row as array
8380
$res = \Jupitern\CosmosDb\QueryBuilder::instance()
84-
->setDatabase($db)
8581
->setCollection($collection)
8682
->select("c.id, c.name")
8783
->where("c.age > @age and c.country = @country")
@@ -95,7 +91,6 @@ echo "get 5 rows as array with id as array key:".PHP_EOL;
9591

9692
// get top 5 rows as array with id as array key
9793
$res = \Jupitern\CosmosDb\QueryBuilder::instance()
98-
->setDatabase($db)
9994
->setCollection($collection)
10095
->select("c.id, c.username")
10196
->where("c.age > @age and c.country = @country")
@@ -110,7 +105,6 @@ echo "get rows as array of objects with collection alias and cross partition que
110105

111106
// get rows as array of objects with collection alias and cross partition query
112107
$res = \Jupitern\CosmosDb\QueryBuilder::instance()
113-
->setDatabase($db)
114108
->setCollection($collection)
115109
->select("TestColl.id, TestColl.name")
116110
->from("TestColl")
@@ -124,7 +118,6 @@ echo "delete one document:".PHP_EOL;
124118

125119
// delete one document that match criteria (single partition)
126120
$res = \Jupitern\CosmosDb\QueryBuilder::instance()
127-
->setDatabase($db)
128121
->setCollection($collection)
129122
->setPartitionKey('country')
130123
->where("c.age > 30 and c.country = 'Portugal'")
@@ -136,12 +129,11 @@ echo "delete all documents:".PHP_EOL;
136129

137130
// delete all documents that match criteria (cross partition)
138131
$res = \Jupitern\CosmosDb\QueryBuilder::instance()
139-
->setDatabase($db)
140-
->setPartitionKey('country')
141132
->setCollection($collection)
133+
->setPartitionKey('country')
142134
->where("c.age > 20")
143135
->deleteAll(true);
144136

145137
var_dump($res);
146138

147-
```
139+
```

examples/example1.php

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
// insert a record
1515
$rid = \Jupitern\CosmosDb\QueryBuilder::instance()
16-
->setDatabase($db)
1716
->setCollection($collection)
1817
->setPartitionKey('country')
1918
->save(['id' => '1', 'name' => 'John Doe', 'age' => 22, 'country' => 'Portugal']);
@@ -22,7 +21,6 @@
2221

2322
// insert a record
2423
$rid = \Jupitern\CosmosDb\QueryBuilder::instance()
25-
->setDatabase($db)
2624
->setCollection($collection)
2725
->setPartitionKey('country')
2826
->save(['id' => '2', 'name' => 'Jane doe', 'age' => 35, 'country' => 'Portugal']);
@@ -31,7 +29,6 @@
3129

3230
// update a record
3331
$rid = \Jupitern\CosmosDb\QueryBuilder::instance()
34-
->setDatabase($db)
3532
->setCollection($collection)
3633
->setPartitionKey('country')
3734
->save(["_rid" => $rid, 'id' => '2', 'name' => 'Jane Doe Something', 'age' => 36, 'country' => 'Portugal']);
@@ -42,7 +39,6 @@
4239

4340
// get one row as array
4441
$res = \Jupitern\CosmosDb\QueryBuilder::instance()
45-
->setDatabase($db)
4642
->setCollection($collection)
4743
->select("c.id, c.name")
4844
->where("c.age > @age and c.country = @country")
@@ -56,7 +52,6 @@
5652

5753
// get top 5 rows as array with id as array key
5854
$res = \Jupitern\CosmosDb\QueryBuilder::instance()
59-
->setDatabase($db)
6055
->setCollection($collection)
6156
->select("c.id, c.username")
6257
->where("c.age > @age and c.country = @country")
@@ -71,7 +66,6 @@
7166

7267
// get rows as array of objects with collection alias and cross partition query
7368
$res = \Jupitern\CosmosDb\QueryBuilder::instance()
74-
->setDatabase($db)
7569
->setCollection($collection)
7670
->select("Users.id, Users.name")
7771
->from("Users")
@@ -85,7 +79,6 @@
8579

8680
// delete one document that match criteria
8781
$res = \Jupitern\CosmosDb\QueryBuilder::instance()
88-
->setDatabase($db)
8982
->setCollection($collection)
9083
->setPartitionKey('country')
9184
->where("c.age > 30 and c.country = 'Portugal'")
@@ -97,7 +90,6 @@
9790

9891
// delete all documents that match criteria
9992
$res = \Jupitern\CosmosDb\QueryBuilder::instance()
100-
->setDatabase($db)
10193
->setPartitionKey('country')
10294
->setCollection($collection)
10395
->where("c.age > 20")

src/QueryBuilder.php

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ class QueryBuilder
2222
{
2323

2424
/** @var \Jupitern\CosmosDb\CosmosDbDatabase $db */
25-
private $db = null;
2625
private $collection = "";
2726
private $partitionKey = null;
2827
private $fields = "";
@@ -49,17 +48,6 @@ public static function instance()
4948
}
5049

5150

52-
/**
53-
* @param CosmosDbDatabase $db
54-
* @return $this
55-
*/
56-
public function setDatabase(CosmosDbDatabase $db)
57-
{
58-
$this->db = $db;
59-
return $this;
60-
}
61-
62-
6351
/**
6452
* @param CosmosDbCollection $collection
6553
* @return $this
@@ -244,8 +232,7 @@ public function save($document)
244232
return $resultObj->_rid ?? null;
245233
}
246234

247-
248-
/* delete */
235+
/* DELETE */
249236

250237
/**
251238
* @param boolean $isCrossPartition

0 commit comments

Comments
 (0)