From 7750ab95c6e81ae28e71af0252da26feb7c19503 Mon Sep 17 00:00:00 2001 From: Juan Pablo Vial Date: Thu, 8 Sep 2022 22:13:48 -0400 Subject: [PATCH] Readme --- Readme.md | 72 ++++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 61 insertions(+), 11 deletions(-) diff --git a/Readme.md b/Readme.md index d949f8b..a78b9f7 100644 --- a/Readme.md +++ b/Readme.md @@ -49,20 +49,70 @@ QueryBuilder include_once 'vendor/autoload.php'; $qb = new QueryBuilder(); -$query = $qb->select(); -$query = $qb->insert(); -$query = $qb->update(); -$query = $qb->delete(); +$query = $qb->select(<*columns>); +$query = $qb->insert(); +$query = $qb->update(
); +$query = $qb->delete(
); ``` ### Queries -Select -``` -$query = $qb->select(); -$query = $qb->select(['id', 'column1']); +#### Select +`SELECT FROM
[ JOIN ON
. = .][ WHERE [ AND|OR ]][ GROUP BY [, ]][ HAVING [ AND|OR ]][ ORDER BY ASC|DESC[, ASC|DESC]]` -$query = $query->from('table'); -$query = $query->joins([['table2', 'table1.column = table2.column']]); -$query = $query->where([['table2.column2', 10]]); +Mysql also include `[ LIMIT [ OFFSET ]]` ``` +$query = $qb->select(); // use '*' for columns +or +$query = $qb->select()->select(['id', 'column1',]); +or +$query = $qb->select(['id', 'column1',]); + +$query->from('table1'); +$query->joins([['table2', 'table1.column1 = table2.column21'],]); +$query->where(['table2.column22 = 10',]); +$query->groupBy(['table1.column1',]); +$query->having(['table1.column1 < 10',]); +$query->orderBy(['table2.column22',]); +$query->limit(10, 10); +``` + +#### Insert +`INSERT INTO
[ ()]` +with two options +`
SET = [, = ][ WHERE [ AND|OR ]]` +``` +$query = $qb->update('table'); +$query->set([['column1', 10],]); or $query->set([['column' => 'column1', 'value' => 10],]); +$query->where(['column2 = 10', ]); +``` + +#### Delete +`DELETE FROM
WHERE [ AND|OR ]` +``` +$query = $qb->delete('table'); +$query->where(['column1 = 10',]); +``` + + +Pass the query to a string +``` +$str = $query->build(); +or +$str = "{$query}"; +``` + +## TODO +Implement other databases