Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
v1a0 committed Feb 6, 2022
2 parents 68083e6 + cd9f2ee commit b543619
Show file tree
Hide file tree
Showing 23 changed files with 1,562 additions and 1,287 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This workflow run tests for sqllex.SQLite3x class

name: Test Sqlite3x
name: Test Sqllex

on:
push:
Expand Down Expand Up @@ -35,13 +35,11 @@ jobs:
- name: Moving tests to current dir
run: |
mv ./tests/sqlite3x/* ./
mv ./tests/* ./
- name: Main test - tests/new_test_all.py
- name: Running unit tests (tests/test_sqllex.py)
run: |
python new_test_all.py
python old_test_all_1.py
python old_test_all_2.py
python -m unittest test_sqllex.py

python-3-8:
Expand All @@ -60,10 +58,8 @@ jobs:
- name: Moving tests to current dir
run: |
mv ./tests/sqlite3x/* ./
mv ./tests/* ./
- name: Main test - tests/new_test_all.py
- name: Running unit tests (tests/test_sqllex.py)
run: |
python new_test_all.py
python old_test_all_1.py
python old_test_all_2.py
python -m unittest test_sqllex.py
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.5
# SQLLEX ORM v0.2.0.6

![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.5` | ✔️ 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.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.0.4` | ⚠️ outdated <br> ⚠️ Security issue <br> CVE-2022-0329| ⚠️ Mostly passing |
| `<=0.1.10.4` | ❌️ outdated ||

Expand Down
30 changes: 28 additions & 2 deletions docs/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div style="text-align: center">
<div style="text-align: center">
<h1> Welcome to the Sqllex Documentation! 👋</h1>
<br>
Here you can find some explanations and examples for Sqllex ORM <br>
Expand Down Expand Up @@ -166,5 +166,31 @@ print(
WHERE=(column_age > 40) & (column_name |LIKE| 'kin%')
)
) # [(3, 'kingabzpro', 44)]
```

### Also, you can do crazy things like this

```python
self.db['employee'].select(
SELECT=[
db['employee']['id'],
db['employee']['firstName'],
db['position']['name']
],
JOIN=(
(
LEFT_JOIN, db['position'],
ON, db['position']['id'] == db['employee']['positionID']
),
(
INNER_JOIN, self.db['payments'],
ON, db['employee']['id'] == db['payments']['employeeID']
)
),
ORDER_BY=(
db['payments']['amount'],
'DESC'
)
)
```

```
57 changes: 34 additions & 23 deletions docs/all-parameters.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
## How to use this document
# All Parameters

### How to use this document

Here you can find all possible parameter for sqllex databases methods.

```markdown
## TABLE <-- parameter
### TABLE <-- parameter

TABLE: Union[str, List[str], SQLite3xTable] <-- expected data types

Expand All @@ -15,7 +17,7 @@ TABLE = "my_table", # string
<-- the end -->
```

### Usage
#### Usage
```python
from sqllex.classes import AbstractDatabase
from sqllex.constants import TEXT, INTEGER
Expand All @@ -35,7 +37,7 @@ db.select(

---

# All Parameters
# Parameters

## TABLE
```python
Expand Down Expand Up @@ -293,35 +295,44 @@ from sqllex.constants import AS, ON, CROSS_JOIN, INNER_JOIN
db: AbstractDatabase = ...
users: AbstractTable = db['users']

# Old and simple way
db.select(
TABLE='users',
SELECT=['username', 'group_name', 'description'],
JOIN=[
['groups', AS, 'gr', ON, 'users.group_id == gr.group_id'], # INNER JOIN by default
[CROSS_JOIN, 'about', 'ab', ON, 'ab.group_id == gr.group_id']
],
JOIN=(
('groups', AS, 'gr', ON, 'users.group_id == gr.group_id'),
(INNER_JOIN, 'about', 'ab', ON, 'ab.group_id == gr.group_id')
),
WHERE= (users['username'] != 'user_1') & (users['username'] != 'user_2')
)

# Old and simple way
JOIN=(
(INNER_JOIN, 'groups', AS, 'gr', ON, 'users.group_id == gr.group_id'),
(CROSS_JOIN, 'about', 'ab', ON, 'ab.group_id == gr.group_id')
),

# Modern and most stable way
JOIN=(
(INNER_JOIN, db['groups'], ON, db['users']['group_id'] == db['groups']['group_id']),
(CROSS_JOIN, db['about'], ON, db['about']['group_id'] == db['users']['group_id'])
),

JOIN=(
('groups', 'gr', ON, 'users.group_id == gr.group_id'), # INNER JOIN by default
('about', 'ab', ON, 'ab.group_id == gr.group_id') # INNER JOIN by default
),

JOIN=[
[INNER_JOIN, 'groups', AS, 'gr', ON, 'users.group_id == gr.group_id'],
[CROSS_JOIN, 'about', 'ab', ON, 'ab.group_id == gr.group_id']
],
JOIN=(
('groups', ON, 'users.group_id == groups.group_id'), # INNER JOIN by default
('about', ON, 'about.group_id == groups.group_id') # INNER JOIN by default
),

JOIN=[
['groups', 'gr', ON, 'users.group_id == gr.group_id'], # INNER JOIN by default
['about', 'ab', ON, 'ab.group_id == gr.group_id'] # INNER JOIN by default
],
JOIN=(
('groups', ON, 'users.group_id == groups.group_id'), # INNER JOIN by default
),

JOIN=[
['groups', ON, 'users.group_id == groups.group_id'], # INNER JOIN by default
['about', ON, 'about.group_id == groups.group_id'] # INNER JOIN by default
],

JOIN=[
['groups', ON, 'users.group_id == groups.group_id'], # INNER JOIN by default
],
```

---
Expand Down
176 changes: 157 additions & 19 deletions docs/database-select.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,32 +144,170 @@ db.select(
LIMIT=50,
OFFSET=20
)
```


# JOIN EXAMPLES

## 1. Simples but not the best way

```python
# Old and simple way
some_table.select(
SELECT=[ # SELECT username, group_name, description
'username',
'group_name',
'description'
],
JOIN=( # JOIN
('groups', AS, 'gr', ON, 'users.group_id == gr.group_id'), # INNER JOIN groups AS gr ON us.group_id == gr.group_id
(LEFT_JOIN, 'about', 'ab', ON, 'ab.group_id == gr.group_id') # LEFT JOIN about ab ON ab.group_id == gr.group_id
),
WHERE= (users['username'] != 'user_1') & (users['username'] != 'user_2'), # WHERE (users.username<>'user_1') AND (users.username<>'user_2')
ORDER_BY='age DESC', # ORDER BY age DESC
LIMIT=50, # LIMIT 50
OFFSET=20 # OFFSET 20
)
```

### SQL script

```shell
SELECT username, group_name, description
FROM x_table
INNER JOIN groups AS gr ON us.group_id == gr.group_id
LEFT JOIN about ab ON ab.group_id == gr.group_id
WHERE (users.username<>'user_1') AND (users.username<>'user_2')
ORDER BY age DESC
LIMIT 50
OFFSET 20
```

# For some another table

x_table.select(
SELECT=['username', 'group_name', 'description'], # SELECT username, group_name, description
JOIN=[ # JOIN
['groups', AS, 'gr', ON, 'users.group_id == gr.group_id'], # INNER JOIN groups AS gr ON us.group_id == gr.group_id
[CROSS_JOIN, 'about', 'ab', ON, 'ab.group_id == gr.group_id'] # CROSS JOIN about ab ON ab.group_id == gr.group_id
## 2. Better way

```python
# DATABASE SCHEMA
# {
# 'position': {
# 'id': [INTEGER, PRIMARY_KEY, AUTOINCREMENT],
# 'name': TEXT,
# 'description': [TEXT, DEFAULT, NULL],
# },
# 'employee': {
# 'id': [INTEGER, PRIMARY_KEY, AUTOINCREMENT],
# 'firstName': TEXT,
# 'surname': TEXT,
# 'age': [INTEGER, NOT_NULL],
# 'positionID': INTEGER,
#
# FOREIGN_KEY: {
# 'positionID': ['position', 'id']
# }
# },
# 'payments': {
# 'date': [TEXT],
# 'employeeID': INTEGER,
# 'amount': [INTEGER, NOT_NULL],
#
# FOREIGN_KEY: {
# 'positionID': ['employee', 'id']
# },
# }
# }

db['employee'].select(
SELECT=[
db['employee']['id'],
db['employee']['firstName'],
db['position']['name']
],
WHERE= (x_table['username'] != 'user_1') & (x_table['username'] != 'user_2'), # WHERE (users.username<>'user_1') AND (users.username<>'user_2')
ORDER_BY='age DESC', # order by age DESC
LIMIT=50, # limit = 50
OFFSET=20 # offset = 20
JOIN=(
INNER_JOIN, self.db['position'],
ON, db['position']['id'] == db['employee']['positionID']
),
ORDER_BY=(
db['position']['id'],
'DESC'
)
)
```

# Same as SQL script like
# SELECT username, group_name, description
# FROM x_table
# INNER JOIN groups AS gr ON us.group_id == gr.group_id
# CROSS JOIN about ab ON ab.group_id == gr.group_id
# WHERE (users.username<>'user_1') AND (users.username<>'user_2')
# ORDER BY age DESC
# LIMIT 50
# OFFSET 20
### SQL script

```shell
SELECT e.id, e.firstName, p.name
FROM employee e
INNER JOIN position p
ON e.positionID == p.id
ORDER BY e.positionID DESC
```

## 3. More than one JOIN

```python
# DATABASE SCHEMA
# {
# 'position': {
# 'id': [INTEGER, PRIMARY_KEY, AUTOINCREMENT],
# 'name': TEXT,
# 'description': [TEXT, DEFAULT, NULL],
# },
# 'employee': {
# 'id': [INTEGER, PRIMARY_KEY, AUTOINCREMENT],
# 'firstName': TEXT,
# 'surname': TEXT,
# 'age': [INTEGER, NOT_NULL],
# 'positionID': INTEGER,
#
# FOREIGN_KEY: {
# 'positionID': ['position', 'id']
# }
# },
# 'payments': {
# 'date': [TEXT],
# 'employeeID': INTEGER,
# 'amount': [INTEGER, NOT_NULL],
#
# FOREIGN_KEY: {
# 'positionID': ['employee', 'id']
# },
# }
# }

self.db['employee'].select(
SELECT=[
db['employee']['id'],
db['employee']['firstName'],
db['position']['name']
],
JOIN=(
(
LEFT_JOIN, db['position'],
ON, db['position']['id'] == db['employee']['positionID']
),
(
INNER_JOIN, self.db['payments'],
ON, db['employee']['id'] == db['payments']['employeeID']
)
),
ORDER_BY=(
db['payments']['amount'],
'DESC'
)
)
```

### SQL script

```shell
SELECT e.id, e.firstName, p.name
FROM employee e
LEFT JOIN position p
ON e.positionID == p.id
INNER JOIN payments
ON e.id == payments.employeeID
ORDER BY payments.amount DESC
```

### [Back to home](README.md)
Loading

0 comments on commit b543619

Please sign in to comment.