Skip to content

Commit

Permalink
Added query-builder docs [ci skip]
Browse files Browse the repository at this point in the history
  • Loading branch information
Gusakov Nikita committed May 5, 2014
1 parent c8b83d6 commit 1adac3f
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 3 deletions.
40 changes: 38 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ Unlike PDO you can re-use the same placeholder as long as necessary.
Also you have to specifying the type of the placeholder just once.

```php
$stmt = $flame->prepare('SELECT * FROM users WHERE age >= i:age OR (registered < d:registered AND age = :age)');
$users = $stmt->execute(['age' => $age]);
$users = $flame->prepare(
'SELECT * FROM users WHERE age >= i:age OR (registered < d:registered AND age = :age)'
)->execute(['age' => $age]);
```

You don't need cast every integer values, Flame do it for you.
Expand Down Expand Up @@ -61,6 +62,41 @@ Placeholder types
- **t**: time


Query builder
=============

Flame also provide powerful query builder. Connection provide base wrappers:

- `Connection::select(string $column...)`
- `Connection::update(string $table, array $columns)`
- `Connection::insert(string $table, array $columns)`

Every sql statement provides by method with same name in `camelCase`.

Examples:

```php
$posts = $db->prepare(
$db->select('p.id', 'p.title', 'p.content')
->from('posts p')
->join('post_tags pt', 'p.id', 'pt.post_id')
->join('tags t', 't.id', 'pt.tag_id')
->where(function ($e) {
$e->equal('t.name', ':tag');
})
)->execute(['tag' => $tag]);

$db->prepare($db->insert('users', [
'username' => ':name',
'password' => ':pass',
'registered' => 'd:now'
]))->execute([
'name' => $name,
'pass' => $pass,
'now' => new \DateTime()
]);
```

Usage
-----

Expand Down
2 changes: 1 addition & 1 deletion src/QueryBuilder/InsertQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ public function __toString()
. '(' . join(', ', array_keys($this->columns)) . ') VALUES('
. join(', ', array_values($this->columns)) . ')';
}
}
}

0 comments on commit 1adac3f

Please sign in to comment.