Skip to content

Commit

Permalink
Update docs for Edgy style
Browse files Browse the repository at this point in the history
  • Loading branch information
tarsil committed Nov 30, 2023
1 parent e68900e commit f4ad4ef
Show file tree
Hide file tree
Showing 11 changed files with 185 additions and 9 deletions.
96 changes: 87 additions & 9 deletions docs/queries/queries.md
Original file line number Diff line number Diff line change
Expand Up @@ -559,6 +559,14 @@ into your queries and therefore Edgy provides a simple integration with those.
Edgy provides the [and_](#and), [or_](#or) and [not_](#not) operators directly for you to use, although
this ones come with a slighly different approach.

For all the examples, let us use the model below.

```python
{!> ../docs_src/queries/clauses/model.py !}
```

### SQLAlchemy style

Since Edgy is built on the top of SQL Alchemy core, that also means we can also use directly that
same functionality within our queries.

Expand All @@ -570,13 +578,7 @@ In other words, uses the [SQLAlchemy style](#sqlalchemy-style).

This might sound confusing so let us see some examples.

For all the examples, let us use the model below.

```python
{!> ../docs_src/queries/clauses/model.py !}
```

### AND
#### AND

As the name suggests, you want to add the `AND` explicitly.

Expand All @@ -596,7 +598,7 @@ And you can do nested `querysets` like multiple [filters](#filter).
{!> ../docs_src/queries/clauses/and_m_filter.py !}
```

### OR
#### OR

The same principle as the [and_](#and) but applied to the `OR`.

Expand All @@ -616,7 +618,7 @@ And you can do nested `querysets` like multiple [filters](#filter).
{!> ../docs_src/queries/clauses/or_m_filter.py !}
```

### NOT
#### NOT

This is simple and direct, this is where you apply the `NOT`.

Expand All @@ -635,3 +637,79 @@ And you can do nested `querysets` like multiple [filters](#filter).
```python
{!> ../docs_src/queries/clauses/not_m_filter.py !}
```

### Edgy Style

This is the most common used scenario where you can use the [related](./related-name.md) for your
queries and all the great functionalities of Edgy while using the operands.

!!! Tip
The same way you apply the filters for the queries using the [related](./related-name.md), this
can also be done with the **Edgy style** but the same cannot be said for the
[SQLAlchemy style](#sqlalchemy-style-1). So if you want to leverage the full power of Edgy,
it is advised to go Edgy style.

#### AND

The `AND` operand with the syntax is the same as using the [filter](#filter) or any queryset
operatator but for visualisation purposes this is also available in the format of `and_`.

```python
{!> ../docs_src/queries/clauses/style/and_two.py !}
```

With multiple parameters.

```python
{!> ../docs_src/queries/clauses/style/and.py !}
```

And you can do nested `querysets` like multiple [filters](#filter).

```python
{!> ../docs_src/queries/clauses/style/and_m_filter.py !}
```

#### OR

The same principle as the [and_](#and-1) but applied to the `OR`.

```python
{!> ../docs_src/queries/clauses/style/or.py !}
```

With multiple `or_` or nultiple parametes in the same `or_`

```python
{!> ../docs_src/queries/clauses/style/or_two.py !}
```

And you can do nested `querysets` like multiple [filters](#filter).

```python
{!> ../docs_src/queries/clauses/style/or_m_filter.py !}
```

#### NOT

The `not_` as the same principle as the [exclude](#exclude) and like the [and](#and-1), for
representation purposes, Edgy also has that function.

```python
{!> ../docs_src/queries/clauses/style/not.py !}
```

With multiple `not_`.

```python
{!> ../docs_src/queries/clauses/style/not_two.py !}
```

And you can do nested `querysets` like multiple [filters](#filter).

```python
{!> ../docs_src/queries/clauses/style/not_m_filter.py !}
```

Internally, the `not_` is calling the [exclude](#exclude) and applying the operators so this is
more for *cosmetic* purposes than anything else, really.
9 changes: 9 additions & 0 deletions docs_src/queries/clauses/style/and.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import edgy

# Create some records

await User.query.create(name="Adam", email="[email protected]")
await User.query.create(name="Eve", email="[email protected]")

# Query using the and_
await User.query.and_(name="Adam", email="[email protected]")
9 changes: 9 additions & 0 deletions docs_src/queries/clauses/style/and_m_filter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import edgy

# Create some records

await User.query.create(name="Adam", email="[email protected]")
await User.query.create(name="Eve", email="[email protected]")

# Query using the and_
await User.query.filter(name="Adam").and_(email="[email protected]")
9 changes: 9 additions & 0 deletions docs_src/queries/clauses/style/and_two.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import edgy

# Create some records

await User.query.create(name="Adam", email="[email protected]")
await User.query.create(name="Eve", email="[email protected]")

# Query using the and_
await User.query.and_(email__icontains="edgy")
13 changes: 13 additions & 0 deletions docs_src/queries/clauses/style/model.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import edgy
from edgy import Database, Registry

database = Database("sqlite:///db.sqlite")
models = Registry(database=database)


class User(edgy.Model):
first_name: str = edgy.CharField(max_length=50, null=True)
email: str = edgy.EmailField(max_lengh=100, null=True)

class Meta:
registry = models
9 changes: 9 additions & 0 deletions docs_src/queries/clauses/style/not.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import edgy

# Create some records

await User.query.create(name="Adam", email="[email protected]")
await User.query.create(name="Eve", email="[email protected]")

# Query using the not_
await User.query.not_(name="Adam")
10 changes: 10 additions & 0 deletions docs_src/queries/clauses/style/not_m_filter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import edgy

# Create some records

await User.query.create(name="Adam", email="[email protected]")
await User.query.create(name="Eve", email="[email protected]")
await User.query.create(name="John", email="[email protected]")

# Query using the not_
await User.query.filter(email__icontains="edgy").not_(name__iexact="Adam")
9 changes: 9 additions & 0 deletions docs_src/queries/clauses/style/not_two.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import edgy

# Create some records

await User.query.create(name="Adam", email="[email protected]")
await User.query.create(name="Eve", email="[email protected]")

# Query using the not_
await User.query.not_(email__icontains="edgy").not_(name__icontains="a")
9 changes: 9 additions & 0 deletions docs_src/queries/clauses/style/or.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import edgy

# Create some records

await User.query.create(name="Adam", email="[email protected]")
await User.query.create(name="Eve", email="[email protected]")

# Query using the or_
await User.query.or_(name="Adam", email="[email protected]")
9 changes: 9 additions & 0 deletions docs_src/queries/clauses/style/or_m_filter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import edgy

# Create some records

await User.query.create(name="Adam", email="[email protected]")
await User.query.create(name="Eve", email="[email protected]")

# Query using the or_
await User.query.or_(name="Adam").filter(email="[email protected]")
12 changes: 12 additions & 0 deletions docs_src/queries/clauses/style/or_two.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import edgy

# Create some records

await User.query.create(name="Adam", email="[email protected]")
await User.query.create(name="Eve", email="[email protected]")

# Query using the multiple or_
await User.query.or_(email__icontains="edgy").or_(name__icontains="a")

# Query using the or_ with multiple fields
await User.query.or_(email__icontains="edgy", name__icontains="a")

0 comments on commit f4ad4ef

Please sign in to comment.