2017 © Pedro Peláez
 

library database

Nette Database Component

image

esports/database

Nette Database Component

  • Tuesday, October 20, 2015
  • by Svaťa Šimara
  • Repository
  • 4 Watchers
  • 4 Stars
  • 431 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 84 Forks
  • 1 Open issues
  • 18 Versions
  • 0 % Grown

The README.md

Nette/Esports Database

@see nette/database, (*1)

Rozšíření API, (*2)

Podmínka v LEFT JOIN

Podmínka je připojena k LEFT JOIN klauzuli, (*3)

...->left(), (*4)

$selection = $context->table('book')
        ->left(':product_price.active', 1)
        ->select('book.*, :product_price.value');
SELECT book.*, product_price.value
FROM book
LEFT JOIN product_price ON book.id = product_price.book_id
AND (product_price.active = 1)

$selection = $context->table('book')
        ->left(':product_price.active', 1)
        ->where(':book_tag.tag.name LIKE', 'PHP')
        ->left(':product_price.value > ?', 0)
        ->left(':book_tag.tag_id IS NOT NULL')
        ->select('book.*, :product_price.value');
SELECT book.*, product_price.value FROM book
LEFT JOIN book_tag ON book.id = book_tag.book_id AND (book_tag.tag_id IS NOT NULL)
LEFT JOIN tag ON book_tag.tag_id = tag.id
LEFT JOIN product_price ON book.id = product_price.book_id AND (product_price.active = 1 AND product_price.value > 0)
WHERE (tag.name LIKE "PHP")

Podmínky lze libovolně míchat, jenom je třeba mít na paměti, že bude podmínka připojena k LEFT JOIN klauzuli podle prvního sloupečku v podmínce (obvykle je uveden jenom jeden, takže netřeba řešit)., (*5)

$selection = $context->table('book')
        ->left(':product_price.active', 1)
        ->left(':book_tag.tag_id IS NOT NULL OR :product_price.active IS NOT NULL') // bude pripojeno k book_tag
        ->select('book.*, :product_price.value');

```sql SELECT book.*, product_price.value FROM book LEFT JOIN product_price ON book.id = product_price.book_id AND (product_price.active = 1) LEFT JOIN book_tag ON book.id = book_tag.book_id AND (book_tag.tag_id IS NOT NULL OR product_price.active IS NOT NULL), (*6)

Aliasování
----------

``` ...->alias() ```

```php
$selection = $context
        ->table('book')
        ->alias(':product_price', 'pp')
        ->left('pp.active', 1)
        ->select('book.*, pp.value');

```sql SELECT book.*, pp.value FROM book LEFT JOIN product_price AS pp ON book.id = pp.book_id AND (pp.active = 1), (*7)

-------------------------------------
```php
$selection = $context->table('book')
        ->alias(':product_price', 'pp')
        ->left('pp.active', 1)
        ->alias(':book_tag.tag', 't')
        ->where('t.name LIKE', 'PHP')
        ->left('pp.value > ?', 0)
        ->left(':book_tag.tag_id IS NOT NULL')
        ->select('book.*, pp.value');

```sql SELECT book.*, pp.value FROM book LEFT JOIN book_tag ON book.id = book_tag.book_id AND (book_tag.tag_id IS NOT NULL) LEFT JOIN tag AS t ON book_tag.tag_id = t.id LEFT JOIN product_price AS pp ON book.id = pp.book_id AND (pp.active = 1 AND pp.value > 0) WHERE (t.name LIKE "PHP"), (*8)

-------------------------------------
LEFT JOIN s aliasem, ale vybira se z ne-aliasovane

```php
$selection = $context
        ->table('book')
        ->alias(':product_price', 'pp')
        ->left('pp.active', 1)
        ->select('book.*, :product_price.value');//tricky

```sql SELECT book.*, product_price.value FROM book LEFT JOIN product_price AS pp ON book.id = pp.book_id AND (pp.active = 1) LEFT JOIN product_price ON book.id = product_price.book_id, (*9)


Vyřazení řetězce z vyhledávání ------------------------------- Stává se, že v subselectu je třeba použít alias tabulky, a s ním pracovat. Klasická Selection se snaží tento alias dohledat, což končí chybou: ```php ...->where('author.id = (SELECT b.author_id FROM book AS b LIMIT 1)');

Řešením je použití vykřičníku před !b.author_id, celé to vypadá:, (*10)

$selection = $context->table('author')
        ->where('author.id = (SELECT !b.author_id FROM book AS b LIMIT 1)');
SELECT *
FROM author
WHERE (author.id = (SELECT b.author_id FROM book AS b LIMIT 1))

Force index

Stejně jako v SQL: Zajistí použití požadovaného indexu., (*11)

...->forceIndex(), (*12)

$selection = $context->table('book')
        ->forceIndex('use_this_index')
        ->select('book.*');
SELECT book.* FROM book
FORCE INDEX (`use_this_index`)

The Versions

20/10 2015

2.3.x-dev

2.3.9999999.9999999-dev https://nette.org

Nette Database Component

  Sources   Download

GPL-3.0 BSD-3-Clause GPL-2.0

The Requires

 

The Development Requires

04/08 2015

dev-master

9999999-dev http://nette.org

Nette Database Component

  Sources   Download

GPL-3.0 BSD-3-Clause GPL-2.0

The Requires

 

The Development Requires

04/08 2015

v2.3.4

2.3.4.0 http://nette.org

Nette Database Component

  Sources   Download

GPL-3.0 BSD-3-Clause GPL-2.0

The Requires

 

The Development Requires

22/04 2015

v2.3.0.3

2.3.0.3 http://nette.org

Nette Database Component

  Sources   Download

GPL-3.0 BSD-3-Clause GPL-2.0

The Requires

 

The Development Requires

02/03 2015

v2.3.0.2

2.3.0.2 http://nette.org

Nette Database Component

  Sources   Download

GPL-3.0 BSD-3-Clause GPL-2.0

The Requires

 

The Development Requires

02/03 2015

dev-b2.2.3

dev-b2.2.3 http://nette.org

Nette Database Component

  Sources   Download

GPL-3.0 BSD-3-Clause GPL-2.0

The Requires

 

The Development Requires

02/03 2015

v2.2.3.1

2.2.3.1 http://nette.org

Nette Database Component

  Sources   Download

GPL-3.0 BSD-3-Clause GPL-2.0

The Requires

 

The Development Requires

02/03 2015

dev-php7

dev-php7 http://nette.org

Nette Database Component

  Sources   Download

GPL-3.0 BSD-3-Clause GPL-2.0

The Requires

 

The Development Requires

26/02 2015

v2.3.0.1

2.3.0.1 http://nette.org

Nette Database Component

  Sources   Download

GPL-3.0 BSD-3-Clause GPL-2.0

The Requires

 

The Development Requires

23/02 2015

v2.3.0

2.3.0.0 http://nette.org

Nette Database Component

  Sources   Download

GPL-3.0 BSD-3-Clause GPL-2.0

The Requires

 

The Development Requires

23/02 2015

v2.2.3

2.2.3.0 http://nette.org

Nette Database Component

  Sources   Download

GPL-3.0 BSD-3-Clause GPL-2.0

The Requires

 

The Development Requires

25/08 2014

v2.2.2

2.2.2.0 http://nette.org

Nette Database Component

  Sources   Download

GPL-3.0 BSD-3-Clause GPL-2.0

The Requires

 

The Development Requires

29/07 2014

dev-navrh

dev-navrh http://nette.org

Nette Database Component

  Sources   Download

GPL-3.0 BSD-3-Clause GPL-2.0

The Requires

 

The Development Requires

25/05 2014

v2.2.1

2.2.1.0 http://nette.org

Nette Database Component

  Sources   Download

GPL-3.0 BSD-3-Clause GPL-2.0

The Requires

 

The Development Requires

11/05 2014

v2.2.0

2.2.0.0 http://nette.org

Nette Database Component

  Sources   Download

GPL-3.0 BSD-3-Clause GPL-2.0

The Requires

 

The Development Requires

14/04 2014

dev-alias

dev-alias http://nette.org

Nette Database Component

  Sources   Download

GPL-3.0 BSD-3-Clause GPL-2.0

The Requires

 

The Development Requires

10/04 2014

dev-test-environment

dev-test-environment http://nette.org

Nette Database Component

  Sources   Download

GPL-3.0 BSD-3-Clause GPL-2.0

The Requires

 

The Development Requires

02/04 2014

2.2.x-dev

2.2.9999999.9999999-dev http://nette.org

Nette Database Component

  Sources   Download

GPL-3.0 BSD-3-Clause GPL-2.0

The Requires

 

The Development Requires