Skip to content

Commit

Permalink
v0.3.0b1
Browse files Browse the repository at this point in the history
- Docs update (issue #60)
  • Loading branch information
v1a0 committed Mar 31, 2022
1 parent 2b4dfd1 commit 93a4ef4
Show file tree
Hide file tree
Showing 37 changed files with 463 additions and 292 deletions.
55 changes: 39 additions & 16 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Here you can find some explanations and examples for Sqllex ORM <br>

### What the heck is Sqllex? 🤔

Sqllex is a python ORM library for comfortable and safe interaction with databases.
Sqllex is a python ORM for comfortable and safe interaction with databases.

If you've ever worked with databases using python, you know what does "Eat nails while writing SQL-scripts" means.
So give a sqllex deal with it, just call needed method, give it a data or necessary parameters and done.
Expand All @@ -38,13 +38,35 @@ It'll be a lot easier to show then explain. So check out examples down below.

---

### SQLite3

Sqllex was originally created for SQLite.
So It's currently best suited especially for work with it.

### Postgres

PostgreSQL now is only partially support.
It has the same api interface as SQLite3x so feel free to use documentation
of it for PostgreSQLx.

---


## Contents

- ### Main classes
- - [Database](./about-sqlite3x.md)
- - [Table](./about-table.md)
- - [Column](./about-column.md)
- - [SearchConditions](./about-searchcondition.md)
- Database
- - [SQLite3x](./about-sqlite3x.md)
- - [PostgreSQLx](./about-postgresqlx.md)
- [Table](./about-table.md)
- - [SQLite3xTable](./about-table.md)
- - [PostgreSQLxTable](./about-table.md)
- [Column](./about-column.md)
- - [SQLite3xColumn](./about-column.md)
- - [PostgreSQLxColumn](./about-column.md)
- [SearchConditions](./about-searchcondition.md)


- ### Main methods
- - [db.select](./database-select.md)
- - [db.insert](./database-insert.md)
Expand All @@ -62,7 +84,9 @@ It'll be a lot easier to show then explain. So check out examples down below.
- ### Features
- - [db['table_name']](./database-get_table.md)
- - [db.transaction <b>(NEW!)</b>](./database-transaction.md)
- ### [Database properties](./database-properties.md)
- ### [SQLite3x properties](./sqlite3x-properties.md)
- ### [SQLite3xTable properties](./sqlite3x-table-properties.md)
- ### [PostgreSQLx properties](./postgresqlx-properties.md)
- ### Examples
- - [Awesome example #0](./examples/sqlite3x-aex-0.md)
- - [Awesome example #1](./examples/sqlite3x-aex-1.md)
Expand Down Expand Up @@ -132,19 +156,18 @@ With the sqllex you can interact with this database in the craziest way

```python
# Import necessary modules
from sqllex.classes import SQLite3x
from sqllex.constants.sqlite import *
import sqllex as sx

# Database
db = SQLite3x('server.db')
db = sx.SQLite3x('server.db')

# Create this table
db.create_table(
'users',
{
'id': INTEGER,
'name': TEXT,
'age': INTEGER
'id': sx.INTEGER,
'name': sx.TEXT,
'age': sx.INTEGER
},
IF_NOT_EXIST=True
)
Expand Down Expand Up @@ -179,27 +202,27 @@ column_name = table_users['name']

print(
table_users.select(
WHERE=(column_age > 40) & (column_name |LIKE| 'kin%')
WHERE=(column_age > 40) & (column_name |sx.LIKE| 'kin%')
)
) # [(3, 'kingabzpro', 44)]
```

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

```python
self.db['employee'].select(
db['employee'].select(
SELECT=[
db['employee']['id'],
db['employee']['firstName'],
db['position']['name']
],
JOIN=(
(
LEFT_JOIN, db['position'],
sx.LEFT_JOIN, db['position'],
ON, db['position']['id'] == db['employee']['positionID']
),
(
INNER_JOIN, self.db['payments'],
sx.INNER_JOIN, db['payments'],
ON, db['employee']['id'] == db['payments']['employeeID']
)
),
Expand Down
11 changes: 6 additions & 5 deletions docs/about-column.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,17 @@ class AbstractColumn:
# Examples

```python
from sqllex.classes import AbstractDatabase, AbstractColumn
from sqllex.constants import *
import sqllex as sx
from sqllex.classes import

db: AbstractDatabase = ...
db = sx.SQLite3x(path='db-1.db')
# db = sx.PostgreSQL(...)

db.create_table(
'users',
{
'id': [INTEGER, PRIMARY_KEY, UNIQUE],
'name': [TEXT, NOT_NULL, DEFAULT, 'Unknown']
'id': [sx.INTEGER, sx.PRIMARY_KEY, sx.UNIQUE],
'name': [sx.TEXT, sx.NOT_NULL, sx.DEFAULT, 'Unknown']
}
)

Expand Down
6 changes: 3 additions & 3 deletions docs/about-postgresqlx.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ db = PostgreSQLx(
- [connection](postgresqlx-properties.md#postgresqlxconnection)
- [dbname *](postgresqlx-properties.md#postgresqlxdbname)
- [host *](postgresqlx-properties.md#postgresqlxhost)
- [placeholder](database-properties.md#abstractdatabaseplaceholder)
- [placeholder](postgresqlx-properties.md#postgresqlxplaceholder)
- [port *](postgresqlx-properties.md#postgresqlxport)
- [tables](database-properties.md#abstractdatabasetables)
- [tables_names](database-properties.md#abstractdatabasetables_names)
- [tables](postgresqlx-properties.md#postgresqlxtables)
- [tables_names](postgresqlx-properties.md#postgresqlxtables_names)
- [user *](postgresqlx-properties.md#postgresqlxuser)


Expand Down
12 changes: 6 additions & 6 deletions docs/about-searchcondition.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@ Special class for generating condition with AbstractColumn.
## Examples

```python
from sqllex import *
from sqllex.classes import SearchCondition
import sqllex as sx

db = SQLite3x(path='database.db')
db = sx.SQLite3x(path='database.db')
# db = sx.PostgreSQL(...)

db.create_table(
'users',
{
'id': [INTEGER, PRIMARY_KEY, UNIQUE],
'name': [TEXT, NOT_NULL, DEFAULT, 'Unknown']
'id': [sx.INTEGER, sx.PRIMARY_KEY, sx.UNIQUE],
'name': [sx.TEXT, sx.NOT_NULL, sx.DEFAULT, 'Unknown']
}
)

Expand Down Expand Up @@ -87,7 +87,7 @@ db.update(
WHERE=(
(id_col != 1) & (id_col !=2) # <---- SearchCondition !!!!
),
OR=IGNORE
OR=sx.IGNORE
)

db.update(
Expand Down
16 changes: 7 additions & 9 deletions docs/about-sqlite3x.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,16 @@
Main class to interact with SQLite3 databases, belongs to the sqllex-databases family, child of AbstractDatabase.

```python
# from sqllex import SQLite3x, INTEGER, TEXT, AUTOINCREMENT
from sqllex.classes import SQLite3x
from sqllex.constants.sqlite import INTEGER, TEXT, AUTOINCREMENT
import sqllex as sx

db = SQLite3x(
db = sx.SQLite3x(
path="data/my_data.db", # path to db location, might be Path type

# Optional parameters
template={
'users': {
'id': [INTEGER, AUTOINCREMENT],
'name': TEXT
'id': [sx.INTEGER, sx.AUTOINCREMENT],
'name': sx.TEXT
}
},

Expand Down Expand Up @@ -63,9 +61,9 @@ db = SQLite3x(

- [path *](sqlite3x-properties.md#sqlite3xpath)
- [connection](sqlite3x-properties.md#sqlite3xconnection)
- [placeholder](database-properties.md#abstractdatabaseplaceholder)
- [tables](database-properties.md#abstractdatabasetables)
- [tables_names](database-properties.md#abstractdatabasetables_names)
- [placeholder](sqlite3x-properties.md#sqlite3xplaceholder)
- [tables](sqlite3x-properties.md#sqlite3xtables)
- [tables_names](sqlite3x-properties.md#sqlite3xtables_names)
- [transaction (NEW!)](database-transaction.md)


Expand Down
23 changes: 11 additions & 12 deletions docs/about-table.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,23 +31,22 @@ I guess you sharp person, but anyway I'll show you a few examples.
## Examples

```python
from sqllex.classes import AbstractDatabase, AbstractTable
from sqllex.constants.sqlite import *
import sqllex as sx

db: AbstractDatabase = ...
db = sx.SQLite3x(path='database.db')
# db = sx.PostgreSQL(...)

db.create_table(
'users',
{
'id': [INTEGER, PRIMARY_KEY, UNIQUE],
'name': [TEXT, NOT_NULL, DEFAULT, 'Unknown'],
'group': [INTEGER, NOT_NULL]
'id': [sx.INTEGER, sx.PRIMARY_KEY, sx.UNIQUE],
'name': [sx.TEXT, sx.NOT_NULL, sx.DEFAULT, 'Unknown'],
'group': [sx.INTEGER, sx.NOT_NULL]
}
)

users: AbstractTable = db['users'] # <--- HERE WE GOT AbstractTable

# users: SQLite3xTable = db['users']
users: sx.SQLite3xTable = db['users'] # <--- HERE WE GOT AbstractTable
# users: PostgreSQLxTable = db['users']

users.insert([1, 'Alex', 1])

Expand All @@ -59,10 +58,10 @@ users.insertmany(
]
)

users.select(ALL) # [(1, 'Alex', 1), (2, 'Blex', 2), (3, 'Clex', 1), (4, 'Dlex', 2)]
users.select(sx.ALL) # [(1, 'Alex', 1), (2, 'Blex', 2), (3, 'Clex', 1), (4, 'Dlex', 2)]

users.select(
ALL,
sx.ALL,
WHERE=(
users['group'] == 1
)
Expand All @@ -71,7 +70,7 @@ users.select(

users.remove_column('group')

users.select(ALL) # [(1, 'Alex'), (2, 'Blex'), (3, 'Clex'), (4, 'Dlex')]
users.select(sx.ALL) # [(1, 'Alex'), (2, 'Blex'), (3, 'Clex'), (4, 'Dlex')]

# And so on
```
Expand Down
22 changes: 12 additions & 10 deletions docs/all-parameters.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ TABLE = "my_table", # string

#### Usage
```python
from sqllex.classes import AbstractDatabase
from sqllex.constants import TEXT, INTEGER
import sqllex as sx

db: AbstractDatabase = ...
db = sx.SQLite3x(path='db-1.db')
# db = sx.PostgreSQL(...)

db.insert(
"my_table", # <--- HERE !!! (TABLE is the fires parameter)
Expand Down Expand Up @@ -96,10 +96,11 @@ WHERE: WhereType
Parameter for highlighting the cells of the method action, in accordance with the specified pattern.

```python
from sqllex.classes import AbstractDatabase
import sqllex as sx
from sqllex.constants import LIKE

db: AbstractDatabase = ...
db = sx.SQLite3x(path='db-1.db')
# db = sx.PostgreSQL(...)

# id == 1

Expand Down Expand Up @@ -214,9 +215,10 @@ ORDER_BY: Union[str, int, AbstractColumn, List[int, str, AbstractColumn], List[L
An optional parameter to set ordering of selected elements. Awaiting column or lost of columns with ordering parameter

```python
from sqllex.classes import AbstractDatabase
import sqllex as sx

db: AbstractDatabase = ...
db = sx.SQLite3x(path='db-1.db')
# db = sx.PostgreSQL(...)

ORDERD_BY = "id",

Expand Down Expand Up @@ -292,11 +294,11 @@ JOIN: Union[str, List[str], List[List[str]]]
SQL JOIN-ing.

```python
from sqllex.classes import AbstractDatabase, AbstractTable
import sqllex as sx
from sqllex.constants import AS, ON, CROSS_JOIN, INNER_JOIN

db: AbstractDatabase = ...
users: AbstractTable = db['users']
db = sx.SQLite3x(path='db-1.db')
users: sx.SQLite3xTable = db['users']

# Old and simple way
db.select(
Expand Down
13 changes: 7 additions & 6 deletions docs/database-add_column.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# AbstractDatabase.add_column
# SQLite3x.add_column

```python
def add_column(
Expand Down Expand Up @@ -26,15 +26,16 @@ def add_column(
# Examples

```python
from sqllex import *
import sqllex as sx

db = SQLite3x(path='database.db')
db = sx.SQLite3x(path='database.db')
# db = sx.PostgreSQL(...)

db.create_table(
'users',
{
'id': [INTEGER, PRIMARY_KEY, UNIQUE],
'name': [TEXT, NOT_NULL, DEFAULT, 'Unknown']
'id': [sx.INTEGER, sx.PRIMARY_KEY, sx.UNIQUE],
'name': [sx.TEXT, sx.NOT_NULL, sx.DEFAULT, 'Unknown']
}
)

Expand All @@ -43,7 +44,7 @@ print(db.get_columns_names('users')) # ['id', 'name']
db.add_column(
'users',
{
'group': [INTEGER, NOT_NULL]
'group': [sx.INTEGER, sx.NOT_NULL]
},
)

Expand Down
Loading

0 comments on commit 93a4ef4

Please sign in to comment.