Skip to content

Commit 863f7f2

Browse files
committed
v0.3.0b2
- Docs update - Changed abstractions sructure for psql engine
1 parent 93a4ef4 commit 863f7f2

File tree

11 files changed

+131
-64
lines changed

11 files changed

+131
-64
lines changed

docs/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ So It's currently best suited especially for work with it.
4747

4848
PostgreSQL now is only partially support.
4949
It has the same api interface as SQLite3x so feel free to use documentation
50-
of it for PostgreSQLx.
50+
of it for PostgreSQLx. Need to installed ``
5151

5252
---
5353

docs/about-column.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# AbstractColumn
1+
# Column
22

33
Sub-class of AbstractTable, itself it's one abstract column inside abstract table.
44
Primary have the same methods but without table name argument.

docs/about-engines.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Engine
2+
3+
Engine is abstract class or module to isolate sqllex code from unnecessary dependencies.
4+
Engine have to be corresponding to AbstractEngine class.
5+
You can find the current abstraction for engine in `sqllex/core/entities/abc/{engine.py | connection.py}`
6+
7+
## PostgreSQLx engine
8+
Current abstraction for PostgreSQLx located in `sqllex/core/entities/postgresqlx/engine.py`
9+
10+
> Recommend to use psycopg2 (from the box)
11+
12+
```shell
13+
pip install psycopg2
14+
```
15+
16+
```python
17+
import psycopg2
18+
import sqllex as sx
19+
20+
21+
db = sx.PostgreSQLx(
22+
engine=psycopg2, # Postgres engine
23+
dbname="test_sqllex", # database name
24+
user="postgres", # username
25+
password="admin", # user's password
26+
host="127.0.0.1", # psql host address
27+
port="5432", # connection port
28+
29+
# Optional parameters
30+
template={
31+
'users': {
32+
'id': [sx.INTEGER, sx.AUTOINCREMENT],
33+
'name': sx.TEXT
34+
}
35+
},
36+
37+
# Create connection to database with database class object initialisation
38+
init_connection=True
39+
)
40+
```
41+
42+
Read more in [./about-postgresqlx.md](about-postgresqlx.md)

docs/about-postgresqlx.md

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
# PostgreSQLx
22

33
Main class to interact with PostgreSQL databases, belongs to the sqllex-databases family, child of AbstractDatabase.
4+
Postgres database need `engine`, we recommend to use psycopg2, just import this lib and give it to Database class constructor.
5+
You can read more [about engines here](./about-engines.md).
46

57
```python
6-
# from sqllex import PostgreSQLx, INTEGER, TEXT, AUTOINCREMENT
7-
from sqllex.classes import PostgreSQLx
8-
from sqllex.constants.sqlite import INTEGER, TEXT, AUTOINCREMENT
8+
import psycopg2
9+
import sqllex as sx
910

1011

11-
db = PostgreSQLx(
12-
dbname="sqllextests", # database name
12+
db = sx.PostgreSQLx(
13+
engine=psycopg2, # Postgres engine
14+
dbname="test_sqllex", # database name
1315
user="postgres", # username
1416
password="admin", # user's password
1517
host="127.0.0.1", # psql host address
@@ -18,17 +20,21 @@ db = PostgreSQLx(
1820
# Optional parameters
1921
template={
2022
'users': {
21-
'id': [INTEGER, AUTOINCREMENT],
22-
'name': TEXT
23+
'id': [sx.INTEGER, sx.AUTOINCREMENT],
24+
'name': sx.TEXT
2325
}
2426
},
2527

2628
# Create connection to database with database class object initialisation
2729
init_connection=True
2830
)
29-
3031
```
3132

33+
PostgreSQL now is only partially support.
34+
It has the same api interface as SQLite3x so feel free to use documentation
35+
of it for PostgreSQLx. Just replace `SQLite3x` at `PostgreSQLx`.
36+
37+
3238
## PostgreSQLx Public Methods
3339

3440
- [add_column](database-add_column.md)

docs/about-table.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# AbstractTable
1+
# Table
22

33
```python
44
class AbstractTable(ABC):

sqllex/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
# "\033[0m"
1818
# "\n")
1919

20-
__version__ = '0.3.0b1'
20+
__version__ = '0.3.0b2'
2121

2222
__all__ = [
2323
# classes

sqllex/core/entities/abc/connection.py

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,8 @@
22

33

44
class AbstractConnection(ABC):
5-
"""
6-
Abstract connection
7-
8-
"""
95

106
class AbstractCursor(ABC):
11-
"""
12-
Abstract cursor
13-
14-
"""
157

168
@abstractmethod
179
def execute(self, script, values=None):
@@ -33,19 +25,19 @@ def executemany(self, script, values=None):
3325
"""
3426
pass
3527

36-
@abstractmethod
37-
def executescript(self, script, values=None):
38-
"""
39-
script:
40-
INSERT (?, ?, ?) INTO 'table_name';
41-
SELECT * FROM 'table_name' WHERE col=?
42-
values:
43-
(
44-
1, 2, 3,
45-
'Column_value'
46-
)
47-
"""
48-
pass
28+
# @abstractmethod
29+
# def executescript(self, script, values=None):
30+
# """
31+
# script:
32+
# INSERT (?, ?, ?) INTO 'table_name';
33+
# SELECT * FROM 'table_name' WHERE col=?
34+
# values:
35+
# (
36+
# 1, 2, 3,
37+
# 'Column_value'
38+
# )
39+
# """
40+
# pass
4941

5042
@abstractmethod
5143
def fetchall(self):

sqllex/core/entities/abc/engine.py

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,9 @@
11
from abc import ABC, abstractmethod
2+
from sqllex.core.entities.abc.connection import AbstractConnection
23

34

45
class AbstractEngine(ABC):
56

6-
class AbstractExtensions(ABC):
7-
@abstractmethod
8-
def new_type(self, *args, **kwargs):
9-
pass
10-
11-
@abstractmethod
12-
def register_type(self, *args, **kwargs):
13-
pass
14-
15-
@property
16-
@abstractmethod
17-
def extensions(self):
18-
pass
19-
207
@abstractmethod
21-
def connect(
22-
self,
23-
dbname=None,
24-
user=None,
25-
password=None,
26-
host=None,
27-
port=None,
28-
**kwargs
29-
):
8+
def connect(self) -> AbstractConnection:
309
pass
31-
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
from sqllex.core.entities.abc.engine import AbstractEngine
2+
from sqllex.core.entities.abc.engine import AbstractConnection
3+
4+
5+
class PostgreSQLxConnection(AbstractConnection):
6+
class PostgreSQLxCursor:
7+
8+
def execute(self, script, values=None):
9+
pass
10+
11+
def executemany(self, script, values=None):
12+
pass
13+
14+
def fetchall(self):
15+
pass
16+
17+
def cursor(self) -> PostgreSQLxCursor:
18+
pass
19+
20+
def commit(self):
21+
pass
22+
23+
def close(self):
24+
pass
25+
26+
27+
class PostgreSQLxExtensions:
28+
def new_type(self, *args, **kwargs):
29+
pass
30+
31+
def register_type(self, *args, **kwargs):
32+
pass
33+
34+
35+
class PostgreSQLxEngine(AbstractEngine):
36+
@property
37+
def extensions(self) -> PostgreSQLxExtensions:
38+
return PostgreSQLxExtensions()
39+
40+
def connect(
41+
self,
42+
dbname=None,
43+
user=None,
44+
password=None,
45+
host=None,
46+
port=None,
47+
**kwargs
48+
) -> PostgreSQLxConnection:
49+
pass

sqllex/core/entities/postgresqlx/postgresqlx.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
import sqllex.core.entities.postgresqlx.middleware as middleware
1414
from sqllex.core.tools.docs_helpers import copy_docs
1515
from types import ModuleType
16-
from sqllex.core.entities.abc import AbstractEngine
17-
from sqllex.core.entities.abc import AbstractConnection
16+
from sqllex.core.entities.postgresqlx.empty_engine import PostgreSQLxEngine
17+
from sqllex.core.entities.postgresqlx.empty_engine import PostgreSQLxConnection
1818

1919

2020
class PostgreSQLxTransaction(AbstractTransaction):
@@ -85,7 +85,7 @@ class PostgreSQLx(ABDatabase):
8585

8686
def __init__(
8787
self,
88-
engine: Union[AbstractEngine, ModuleType],
88+
engine: Union[PostgreSQLxEngine, ModuleType],
8989
dbname: AnyStr = "postgres",
9090
user: AnyStr = "postgres",
9191
password: AnyStr = None,
@@ -173,7 +173,7 @@ def __bool__(self):
173173

174174
@property
175175
@copy_docs(ABDatabase.connection)
176-
def connection(self) -> Union[AbstractConnection, None]:
176+
def connection(self) -> Union[PostgreSQLxConnection, None]:
177177
return self.__connection
178178

179179
@property

0 commit comments

Comments
 (0)