Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
v1a0 committed Jan 20, 2022
2 parents fe0219b + fa5c549 commit 023e5a7
Show file tree
Hide file tree
Showing 11 changed files with 193 additions and 54 deletions.
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.3
# SQLLEX ORM v0.2.0.4

![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.3` | ✔️ 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` | ✔️ supported <br> ✔️ stable | [![code-ql-img]][code-ql-src] <br> [![sqlite3x-test-img]][sqlite3x-test-src] <br> [![pypi-upload-img]][pypi-upload-img] |
| `0.1.10.5` | ⚠️ outdated <br> | ⚠️ Mostly passing |
| `<=0.1.10.4` | ❌️ outdated ||

Expand Down
5 changes: 4 additions & 1 deletion docs/about-postgresqlx.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ db = PostgreSQLx(
'id': [INTEGER, AUTOINCREMENT],
'name': TEXT
}
}
},

# Create connection to database with database class object initialisation
init_connection=True
)

```
Expand Down
5 changes: 4 additions & 1 deletion docs/about-sqlite3x.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ db = SQLite3x(
'id': [INTEGER, AUTOINCREMENT],
'name': TEXT
}
}
},

# Create connection to database with database class object initialisation
init_connection=True
)

```
Expand Down
25 changes: 23 additions & 2 deletions docs/postgresqlx-connect.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,29 @@
# PostgreSQLx.connect

```python
@copy_docs(ABDatabase.connect)
def connect(self, password: AnyStr):
def connect(
self,
password: AnyStr,
dbname=None,
user=None,
host=None,
port=None,
**kwargs
):
"""
Creating psycopg2.extensions.connection to interact with database
Optional parameters (default):
dbname=self.dbname,
user=self.user,
host=self.host,
port=self.port,
Additional kwargs for psycopg2.connect()
dsn=None,
connection_factory=None,
cursor_factory=None,
"""
```

Expand All @@ -18,6 +37,8 @@ Highly recommend create connection manually.

## Examples

### Casual

```python
import sqllex

Expand Down
38 changes: 36 additions & 2 deletions docs/sqlite3x-connect.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,26 @@
# SQLite3x.connect

```python
def connect(self):
def connect(
self,
path=None,
**kwargs
) -> sqlite3.Connection:
"""
Create connection to database
Creating sqlite3.connect() connection to interact with database
Optional parameters (default):
path=self.path
Additional kwargs for sqlite3.connect()
path=None,
timeout=None,
detect_types=None,
isolation_level=None,
check_same_thread=None,
factory=None,
cached_statements=None,
uri=None,
"""
```

Expand All @@ -17,6 +33,8 @@ Highly recommend create connection manually.

## Examples

### Casual

```python
from sqllex import SQLite3x
from sqllex.constants.sqlite import *
Expand All @@ -33,7 +51,23 @@ for i in range(1000):
# ---------------------------- THE END ----------------------------------

db.disconnect()
```
<!--
### Recommended
```python
from sqllex import SQLite3x
from sqllex.constants.sqlite import *
db = SQLite3x('db-1', init_connection=False)
with db.connect() as conn:
db.create_table("numbers", {"value": [INTEGER]}, IF_NOT_EXIST=True)
for i in range(1000):
db.insert("numbers", i, execute=False)
```
-->

### [Back to home](README.md)
24 changes: 12 additions & 12 deletions sqllex/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@
from sqllex.constants import *
from sqllex.debug import logger

print(
"\033[91m"
"WARNING: SQLLEX v0.2+ have major changes that may breaks your old code! "
"Please, read https://github.com/v1a0/sqllex/blob/main/UPDATES.md#0200. "
"Especially if you are moving v0.1.10.5 -> v0.2+"
"\033[0m"
"\33[93m"
"\n"
"Thanks for you support and feedback!"
"\033[0m"
"\n")
# print(
# "\033[91m"
# "WARNING: SQLLEX v0.2+ have major changes that may breaks your old code! "
# "Please, read https://github.com/v1a0/sqllex/blob/main/UPDATES.md#0200. "
# "Especially if you are moving v0.1.x -> v0.2+"
# "\033[0m"
# "\33[93m"
# "\n"
# "Thanks for you support and feedback!"
# "\033[0m"
# "\n")

__version__ = '0.2.0.3'
__version__ = '0.2.0.4'

__all__ = [
# classes
Expand Down
14 changes: 7 additions & 7 deletions sqllex/core/entities/abc/sql_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ def select(
OFFSET: LimitOffsetType = None,
JOIN: JoinArgType = None,
**kwargs,
) -> List[Tuple]:
) -> Tuple[Tuple]:
"""
SELECT data from table
Expand Down Expand Up @@ -261,7 +261,7 @@ def select_distinct(
OFFSET: LimitOffsetType = None,
JOIN: Union[str, List[str], List[List[str]]] = None,
**kwargs,
) -> List[Tuple]:
) -> Tuple[Tuple]:
return self.db.select_distinct(
self.name,
SELECT=SELECT,
Expand All @@ -283,7 +283,7 @@ def select_all(
OFFSET: LimitOffsetType = None,
JOIN: Union[str, List[str], List[List[str]]] = None,
**kwargs,
) -> List[Tuple]:
) -> Tuple[Tuple]:
"""
SELECT ALL data from table
Expand Down Expand Up @@ -411,7 +411,7 @@ def find(
ORDER_BY: OrderByType = None,
LIMIT: LimitOffsetType = None,
**kwargs,
) -> List[Tuple]:
) -> Tuple[Tuple]:
"""
Find all records in table where_
Expand Down Expand Up @@ -1436,7 +1436,7 @@ def select(
JOIN: JoinArgType = None,
_method="SELECT",
**kwargs,
) -> List[Tuple]:
) -> Tuple[Tuple]:
"""
SELECT data from table
Expand Down Expand Up @@ -1516,7 +1516,7 @@ def select_distinct(
FROM: Union[str, List[str], Tuple[str], AbstractTable] = None,
JOIN: JoinArgType = None,
**kwargs,
) -> List[Tuple]:
) -> Tuple[Tuple]:
"""
SELECT distinct from table
Expand Down Expand Up @@ -1583,7 +1583,7 @@ def select_all(
FROM: Union[str, List[str], AbstractTable] = None,
JOIN: JoinArgType = None,
**kwargs,
) -> List[Tuple]:
) -> Tuple[Tuple]:
"""
SELECT all data from table
Expand Down
63 changes: 50 additions & 13 deletions sqllex/core/entities/postgresqlx/postgresqlx.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,16 @@ class PostgreSQLx(ABDatabase):

# ============================ MAGIC METHODS =================================

def __init__(self,
dbname: AnyStr = "postgres",
user: AnyStr = "postgres",
password: AnyStr = None,
host: AnyStr = "127.0.0.1",
port: AnyStr = "5432",
template: DBTemplateType = None):
def __init__(
self,
dbname: AnyStr = "postgres",
user: AnyStr = "postgres",
password: AnyStr = None,
host: AnyStr = "127.0.0.1",
port: AnyStr = "5432",
template: DBTemplateType = None,
init_connection=True,
):
"""
Initialization
Expand All @@ -95,6 +98,8 @@ def __init__(self,
Port of postgres server, 5432 by default
template : DBTemplateType
template of database structure (DBTemplateType)
init_connection : bool
Create connection to database with database class object initialisation
"""

Expand All @@ -108,7 +113,8 @@ def __init__(self,
self.__port = port
self.__connection = None # init connection

self.connect(password=password) # creating connection with db
if init_connection:
self.connect(password=password) # creating connection with db

DEC2FLOAT = psycopg2.extensions.new_type(
psycopg2.extensions.DECIMAL.values,
Expand Down Expand Up @@ -255,18 +261,49 @@ def _get_tables_names(self) -> Tuple:
# ============================== ABC PUBLIC METHODS ============================

@copy_docs(ABDatabase.connect)
def connect(self, password: AnyStr):
def connect(
self,
password: AnyStr,
dbname=None,
user=None,
host=None,
port=None,
**kwargs
):
"""
Creating psycopg2.extensions.connection to interact with database
Optional parameters (default):
dbname=self.dbname,
user=self.user,
host=self.host,
port=self.port,
Additional kwargs for psycopg2.connect()
dsn=None,
connection_factory=None,
cursor_factory=None,
"""
if dbname is None:
dbname = self.dbname
if user is None:
user = self.user
if host is None:
host = self.host
if port is None:
port = self.port

if not self.connection:
self.__connection = psycopg2.connect(
dbname=self.__dbname,
user=self.__user,
dbname=dbname,
user=user,
password=password,
host=self.__host,
port=self.__port
host=host,
port=port,
**kwargs
)
return self.connection

else:
logger.warning("Connection already exist")
Expand Down

0 comments on commit 023e5a7

Please sign in to comment.