Skip to content

Commit

Permalink
v0.2.1.0
Browse files Browse the repository at this point in the history
- Added GROUP BY #54
- Tests updated (added tests for GROUP BY, raw sql tablse selects moved to one func)
- Typing fixing
- Docs upd
- Minor bugfixes
  • Loading branch information
v1a0 committed Feb 7, 2022
1 parent cd9f2ee commit 2a368f8
Show file tree
Hide file tree
Showing 14 changed files with 324 additions and 137 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -122,3 +122,5 @@ dmypy.json

# Statistic
*.prof
*.log.zip
*.zip
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

<img src="./pics/sqllex-logo.svg" width="300px" alt="sqllex logo">

# SQLLEX ORM v0.2.0.6
# SQLLEX ORM v0.2.1.0

![python-3-9]
[![lgtm-quality-img]][lgtm-quality-src]
Expand All @@ -28,7 +28,7 @@ pip install sqllex

| Version | Status | Tests, and actions |
| :--------: | :----------------------------: | :---: |
| `==0.2.0.6` | ✔️ supported <br> ✔️ stable | [![code-ql-img]][code-ql-src] <br> [![sqlite3x-test-img]][sqlite3x-test-src] <br> [![pypi-upload-img]][pypi-upload-img] |
| `==0.2.1.0` | ✔️ supported <br> ✔️ stable | [![code-ql-img]][code-ql-src] <br> [![sqlite3x-test-img]][sqlite3x-test-src] <br> [![pypi-upload-img]][pypi-upload-img] |
| `<=0.2.0.4` | ⚠️ outdated <br> ⚠️ Security issue <br> CVE-2022-0329| ⚠️ Mostly passing |
| `<=0.1.10.4` | ❌️ outdated ||

Expand Down
41 changes: 27 additions & 14 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,21 +38,34 @@ It'll be a lot easier to show then explain. So check out examples down below.

---

## Pages

- ### [SQLite3x](about-sqlite3x.md)
- [SQLite3xTable](about-table.md)
- **Examples**
- [Awesome example #0](examples/sqlite3x-aex-0.md)
- [Awesome example #1](examples/sqlite3x-aex-1.md)

- ### [PostgreSQLx](about-postgresqlx.md)
- [PostgreSQLxTable](about-table.md)

- ### [AbstractColumn](about-column.md)

- ### [SearchCondition](about-searchcondition.md)
## Must have links

- ### Main classes
- - [Database](./about-sqlite3x.md)
- - [Table](./about-table.md)
- - [Column](./about-column.md)
- - [SearchConditions](./about-searchcondition.md)
- ### Main method
- - [db.select](./database-select.md)
- - [db.insert](./database-insert.md)
- - [db.insertmany](./database-insertmany.md)
- - [db.update](./database-update.md)
- - [db.delete](./database-delete.md)
- - [db.drop](./database-drop.md)
- - [db.markup](./database-markup.md)
- - [db.create_table](./database-create_table.md)
- - [db.add_column](./database-add_column.md)
- - [db.remove_column](./database-remove_column.md)
- - [db.connect](./sqlite3x-connect.md)
- - [db.disconnect](./database-disconnect.md)
- - [db['table_name']](./database-get_table.md)
- ### [Database properties](./database-properties.md)
- ### Examples
- - [Awesome example #0](./examples/sqlite3x-aex-0.md)
- - [Awesome example #1](./examples/sqlite3x-aex-1.md)

---

- ### [Project Showcase](sqllex-showcase.md)
- [Vaccine Update System](sqllex-showcase.md#vaccine-update-systemcase-vsu-src-by-kingabzprokingabzpro)
- [Sqllex for Data Science Using Pandas](sqllex-showcase.md#sqllex-for-data-science-using-pandascase-dsup-src-by-kingabzprokingabzpro)
Expand Down
37 changes: 35 additions & 2 deletions docs/all-parameters.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,10 @@ TABLE = ["my_awesome_table", "mat"], # use alias "mat" in code instead of "my_

## SELECT
```python
SELECT: Union[str, SQLite3xColumn, List[Union[str, SQLite3xColumn]]]
SELECT: Union[
AnyStr, AbstractColumn, ConstantType,
List[Union[AbstractColumn, AnyStr]], Tuple[Union[AbstractColumn, AnyStr]]
] = None
```

Parameter of select-like methods to specify selecting columns. Can be string or column object SQLite3xColumn,
Expand Down Expand Up @@ -90,7 +93,7 @@ SELECT = (db['users']['id'], db['users']['username']), # Tuple[AbstractColumn
WHERE: WhereType
```

parameter for highlighting the cells of the method action, in accordance with the specified pattern.
Parameter for highlighting the cells of the method action, in accordance with the specified pattern.

```python
from sqllex.classes import AbstractDatabase
Expand Down Expand Up @@ -333,6 +336,36 @@ JOIN=(
),


```

---

## GROUP_BY
```python
GROUP_BY: Union[GroupByType, AbstractColumn] = None
```

Optional parameter for group data in database response.

```python
GROUP_BY = 'column1'

GROUP_BY = db['table1']['column1']

GROUP_BY = ('column1',)

GROUP_BY = (
db['table1']['column1'],
db['table1']['column2']
)

GROUP_BY = ['column1',]

GROUP_BY = [
db['table1']['column1'],
db['table1']['column2']
]

```

---
Expand Down
56 changes: 34 additions & 22 deletions docs/database-select.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,31 @@
```python
def select(
self,
TABLE: Union[AnyStr, AbstractTable] = None,
SELECT: Union[AnyStr, AbstractColumn, List, Tuple] = None,
WHERE: WhereType = None,
WITH: WithType = None,
SELECT: Union[
AnyStr, AbstractColumn, ConstantType,
List[Union[AbstractColumn, AnyStr]], Tuple[Union[AbstractColumn, AnyStr]]
] = None,
WHERE: Union[WhereType, SearchCondition] = None,
ORDER_BY: OrderByType = None,
LIMIT: LimitOffsetType = None,
OFFSET: LimitOffsetType = None,
FROM: Union[AnyStr, AbstractTable] = None,
JOIN: JoinArgType = None,
_method="SELECT",
GROUP_BY: Union[GroupByType, AbstractColumn] = None,
**kwargs,
) -> Tuple:
) -> Tuple[Tuple]:
"""
SELECT data from table
Parameters
----------
TABLE: Union[AnyStr, AbstractTable]
Name of table
SELECT : Union[str, List[str]]
columns to select. Value '*' by default
> SELECT=['id', 'name']
WHERE : WhereType
optional parameter for conditions
> WHERE=(db['table_name']['column_name'] == 'some_value')
WITH : WithType
Disabled!
optional parameter for conditions
> db: AbstractDatabase
> ...
> WHERE=(db['table_name']['column_name'] == 'some_value')
ORDER_BY : OrderByType
optional parameter for conditions
> ORDER_BY=['age', 'DESC']
Expand All @@ -41,20 +39,34 @@ def select(
OFFSET : LimitOffsetType
Set offset for selecting records
> OFFSET=5
FROM : str
Name of table, same at TABLE
JOIN: JoinArgType
JOIN: Union[str, List[str], List[List[str]]]
optional parameter for joining data from other tables ['groups'],
_method: str
DON'T CHANGE IT! special argument for unite select_all, select_distinct into select()
GROUP_BY: Union[GroupByType, AbstractColumn]
optional parameter for group data in database response
Returns
----------
List[Tuple]
Tuple of Selected data
Tuple[Tuple]
Selected records
"""
```

## Parameters

| Parameter | Description |
| :--- | :--- |
| [TABLE](./all-parameters.md#table) | Table name or table object SQLite3xTable to select from |
| [SELECT *](./all-parameters.md#select) | Column or columns to select from table (ALL by default) |
| [WHERE *](./all-parameters.md#where) | Expression that have to be true for selecting records |
| [ORDER_BY *](./all-parameters.md#order_by) | Sort selected records in specific order |
| [LIMIT *](./all-parameters.md#limit) | Limit selected values amount |
| [FROM *](./all-parameters.md#from) | Same as TABLE, exists just for backward compatibility |
| [JOIN *](./all-parameters.md#join) | JOIN data from another table |
| [GROUP_BY *](./all-parameters.md#group_by) | Group elements by value from specific column or columns |

<small>* - optional parameter</small>

## Examples

```python
Expand Down
2 changes: 1 addition & 1 deletion sqllex/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# "\033[0m"
# "\n")

__version__ = '0.2.0.6'
__version__ = '0.2.1.0'

__all__ = [
# classes
Expand Down
36 changes: 32 additions & 4 deletions sqllex/core/entities/abc/sql_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,12 +199,16 @@ def insertmany(

def select(
self,
SELECT: Union[AnyStr, AbstractColumn, ConstantType, List[Union[AnyStr, AbstractColumn]]] = None,
SELECT: Union[
AnyStr, AbstractColumn, ConstantType,
List[Union[AbstractColumn, AnyStr]], Tuple[Union[AbstractColumn, AnyStr]]
] = None,
WHERE: Union[WhereType, SearchCondition] = None,
ORDER_BY: OrderByType = None,
LIMIT: LimitOffsetType = None,
OFFSET: LimitOffsetType = None,
JOIN: JoinArgType = None,
GROUP_BY: Union[GroupByType, AbstractColumn] = None,
**kwargs,
) -> Tuple[Tuple]:
"""
Expand Down Expand Up @@ -232,6 +236,8 @@ def select(
> OFFSET=5
JOIN: Union[str, List[str], List[List[str]]]
optional parameter for joining data from other tables ['groups'],
GROUP_BY: Union[GroupByType, AbstractColumn]
optional parameter for group data in database response
Returns
----------
Expand All @@ -248,18 +254,23 @@ def select(
LIMIT=LIMIT,
OFFSET=OFFSET,
JOIN=JOIN,
GROUP_BY=GROUP_BY,
**kwargs,
)

def select_distinct(
self,
SELECT: Union[str, AbstractColumn, ConstantType, List[Union[str, AbstractColumn]]] = None,
SELECT: Union[
AnyStr, AbstractColumn, ConstantType,
List[Union[AbstractColumn, AnyStr]], Tuple[Union[AbstractColumn, AnyStr]]
] = None,
WHERE: Union[WhereType, SearchCondition] = None,
WITH: WithType = None,
ORDER_BY: OrderByType = None,
LIMIT: LimitOffsetType = None,
OFFSET: LimitOffsetType = None,
JOIN: Union[str, List[str], List[List[str]]] = None,
GROUP_BY: Union[GroupByType, AbstractColumn] = None,
**kwargs,
) -> Tuple[Tuple]:
return self.db.select_distinct(
Expand All @@ -271,6 +282,7 @@ def select_distinct(
LIMIT=LIMIT,
OFFSET=OFFSET,
JOIN=JOIN,
GROUP_BY=GROUP_BY,
**kwargs,
)

Expand All @@ -282,6 +294,7 @@ def select_all(
LIMIT: LimitOffsetType = None,
OFFSET: LimitOffsetType = None,
JOIN: Union[str, List[str], List[List[str]]] = None,
GROUP_BY: Union[GroupByType, AbstractColumn] = None,
**kwargs,
) -> Tuple[Tuple]:
"""
Expand All @@ -306,6 +319,8 @@ def select_all(
> OFFSET=5
JOIN: Union[str, List[str], List[List[str]]]
optional parameter for joining data from other tables ['groups'],
GROUP_BY: Union[GroupByType, AbstractColumn]
optional parameter for group data in database response
Returns
----------
Expand All @@ -322,6 +337,7 @@ def select_all(
LIMIT=LIMIT,
OFFSET=OFFSET,
JOIN=JOIN,
GROUP_BY=GROUP_BY,
**kwargs,
)

Expand Down Expand Up @@ -1436,8 +1452,9 @@ def select(
ORDER_BY: OrderByType = None,
LIMIT: LimitOffsetType = None,
OFFSET: LimitOffsetType = None,
FROM: Union[AnyStr, AbstractTable] = None,
FROM: Union[str, List[str], Tuple[str], AbstractTable] = None,
JOIN: JoinArgType = None,
GROUP_BY: Union[GroupByType, AbstractColumn] = None,
_method="SELECT",
**kwargs,
) -> Tuple[Tuple]:
Expand Down Expand Up @@ -1470,6 +1487,8 @@ def select(
Name of table, same at TABLE
JOIN: JoinArgType
optional parameter for joining data from other tables ['groups'],
GROUP_BY: Union[GroupByType, AbstractColumn]
optional parameter for group data in database response
_method: str
DON'T CHANGE IT! special argument for unite select_all, select_distinct into select()
Expand Down Expand Up @@ -1503,6 +1522,7 @@ def select(
LIMIT=LIMIT,
OFFSET=OFFSET,
JOIN=JOIN,
GROUP_BY=GROUP_BY,
**kwargs,
)

Expand All @@ -1519,6 +1539,7 @@ def select_distinct(
OFFSET: LimitOffsetType = None,
FROM: Union[str, List[str], Tuple[str], AbstractTable] = None,
JOIN: JoinArgType = None,
GROUP_BY: Union[GroupByType, AbstractColumn] = None,
**kwargs,
) -> Tuple[Tuple]:
"""
Expand Down Expand Up @@ -1551,6 +1572,8 @@ def select_distinct(
> OFFSET=5
JOIN: Union[str, List[str], List[List[str]]]
optional parameter for joining data from other tables ['groups'],
GROUP_BY: Union[GroupByType, AbstractColumn]
optional parameter for group data in database response
FROM : str
Name of table, same at TABLE
Expand All @@ -1572,6 +1595,7 @@ def select_distinct(
OFFSET=OFFSET,
FROM=FROM,
JOIN=JOIN,
GROUP_BY=GROUP_BY,
**kwargs
)

Expand All @@ -1584,8 +1608,9 @@ def select_all(
ORDER_BY: OrderByType = None,
LIMIT: LimitOffsetType = None,
OFFSET: LimitOffsetType = None,
FROM: Union[str, List[str], AbstractTable] = None,
FROM: Union[str, List[str], Tuple[str], AbstractTable] = None,
JOIN: JoinArgType = None,
GROUP_BY: Union[GroupByType, AbstractColumn] = None,
**kwargs,
) -> Tuple[Tuple]:
"""
Expand Down Expand Up @@ -1618,6 +1643,8 @@ def select_all(
> OFFSET=5
JOIN: Union[str, List[str], List[List[str]]]
optional parameter for joining data from other tables ['groups'],
GROUP_BY: Union[GroupByType, AbstractColumn]
optional parameter for group data in database response
FROM : Union[str, List[str], AbstractTable]
Name of table, same at TABLE
Expand All @@ -1639,6 +1666,7 @@ def select_all(
OFFSET=OFFSET,
FROM=FROM,
JOIN=JOIN,
GROUP_BY=GROUP_BY,
**kwargs
)

Expand Down
Loading

0 comments on commit 2a368f8

Please sign in to comment.