Skip to content

Commit 3dea0e7

Browse files
authored
Update README.md
1 parent 407b973 commit 3dea0e7

1 file changed

Lines changed: 16 additions & 13 deletions

File tree

README.md

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,16 @@ Also there is the method to get all binded values for such substitutors.
55

66
### Installation
77
------
8-
The package is intended to be used via Composer. It currently is not on Packagist, so add this repository description to you composer.json:
9-
```
10-
"repositories": [
11-
{
12-
"type": "vcs",
13-
"url": "https://github.com/efoft/query-builder"
14-
},
15-
]
16-
```
17-
and require it:
8+
The package is intended to be used via Composer. Add this to you composer.json:
189
```
1910
"require": {
2011
"efoft/query-builder" : "dev-master"
2112
}
2213
```
14+
or just run via command-line:
15+
```
16+
composer require efoft/query-builder
17+
```
2318

2419
### Initialization
2520
------
@@ -64,15 +59,16 @@ Examples below illustrate it in more details.
6459
#### Select
6560
Method ->select(). Can chain and can be called multiple times. Duplicates are automatically removed.
6661
For specifying aliases use associative arrays: array('field'=>'alias', ...).
67-
The following methods allow to set ORDER BY, GROUP BY and LIMIT
62+
The following methods allow to set ORDER BY, GROUP BY, LIMIT and DISTINCT directives:
6863
* order()
6964
* group()
7065
* limit()
66+
* distinct()
7167

7268
```
7369
// select
7470
$q->from('table1, table2 ')->from('table2')->select(array('table2.age'=>'a','table1.name'=>'n'))->where(array('id'=>13));
75-
$q->where(array('age'=>'/3.*/'))->order('name')->limit(100);
71+
$q->where(array('age'=>'/3.*/'))->order('name')->limit(100)->distinct();
7672
echo $q->getQuery() . PHP_EOL;
7773
echo print_r($q->getBindings()) . PHP_EOL;
7874
@@ -137,6 +133,13 @@ Array
137133
[id] => 13
138134
)
139135
```
136+
#### Join
137+
Method ->join(). It has 3 mandatory arguments (joined table, key field in main table, key fields in joined table) and 1 optional - type of join (by default LEFT is used). For key fields there is no need to specify them as fully-qualified, it's done automatically. Join is applicable to select, update and delete statements and can be run multiple time if many tables are joined.
138+
```
139+
$q->from('table1')->select(array('table1.age'=>'a','table1.name'=>'n'))->order('n')->limit(100);
140+
$q->join('tags','id','relid')->join('imgs','id','relid')->distinct();
141+
$q->where(array('$or'=>array(array('tags.value'=>'three'),array('imgs.value'=>'image1.png'))));
142+
```
140143

141144
#### Retrieve results
142145
To get resulted query:
@@ -147,4 +150,4 @@ $sql = $q->getQuery();
147150
To get binded values:
148151
```
149152
$values = $q->getBindings()'
150-
```
153+
```

0 commit comments

Comments
 (0)