Skip to content

Commit 327e1f7

Browse files
committed
Merge branch 'feature/foreign_tree' into develop
2 parents 2c0a550 + 8850fbd commit 327e1f7

File tree

14 files changed

+29
-37
lines changed

14 files changed

+29
-37
lines changed

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,6 @@ app.include_router(crud_route_2)
161161
```python
162162
import uvicorn
163163
from fastapi import FastAPI, Depends
164-
from sqlalchemy.orm import declarative_base
165164
from fastapi_quickcrud import CrudMethods
166165
from fastapi_quickcrud import sqlalchemy_to_pydantic
167166
from fastapi_quickcrud.misc.memory_sql import sync_memory_db

src/fastapi_quickcrud/crud_router.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
Depends, APIRouter
1111
from pydantic import \
1212
BaseModel
13-
from sqlalchemy.orm import declarative_base
1413
from sqlalchemy.sql.schema import Table
1514

1615
from . import sqlalchemy_to_pydantic

src/fastapi_quickcrud/misc/abstract_query.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from abc import ABC
22
from typing import List, Union
33

4-
from sqlalchemy import and_, select, update, text
4+
from sqlalchemy import and_, select, text
55
from sqlalchemy.dialects.postgresql import insert
66
from sqlalchemy.sql.elements import BinaryExpression
77
from sqlalchemy.sql.schema import Table
@@ -302,7 +302,7 @@ def upsert(self, *,
302302
unique_fields: List[str],
303303
upsert_one=True,
304304
) -> BinaryExpression:
305-
raise NotImplemented('upsert only support PostgreSQL')
305+
raise NotImplementedError
306306

307307

308308
class SQLAlchemyMySQLQueryService(SQLAlchemyGeneralSQLQueryService):
@@ -324,7 +324,7 @@ def upsert(self, *,
324324
unique_fields: List[str],
325325
upsert_one=True,
326326
) -> BinaryExpression:
327-
raise NotImplemented('upsert only support PostgreSQL')
327+
raise NotImplementedError
328328

329329

330330
class SQLAlchemyMariaDBQueryService(SQLAlchemyGeneralSQLQueryService):
@@ -346,7 +346,7 @@ def upsert(self, *,
346346
unique_fields: List[str],
347347
upsert_one=True,
348348
) -> BinaryExpression:
349-
raise NotImplemented('upsert only support PostgreSQL')
349+
raise NotImplementedError
350350

351351

352352
class SQLAlchemyOracleQueryService(SQLAlchemyGeneralSQLQueryService):
@@ -368,7 +368,7 @@ def upsert(self, *,
368368
unique_fields: List[str],
369369
upsert_one=True,
370370
) -> BinaryExpression:
371-
raise NotImplemented('upsert only support PostgreSQL')
371+
raise NotImplementedError
372372

373373

374374
class SQLAlchemyMSSqlQueryService(SQLAlchemyGeneralSQLQueryService):
@@ -390,7 +390,7 @@ def upsert(self, *,
390390
unique_fields: List[str],
391391
upsert_one=True,
392392
) -> BinaryExpression:
393-
raise NotImplemented('upsert only support PostgreSQL')
393+
raise NotImplementedError
394394

395395

396396
class SQLAlchemyNotSupportQueryService(SQLAlchemyGeneralSQLQueryService):
@@ -412,4 +412,4 @@ def upsert(self, *,
412412
unique_fields: List[str],
413413
upsert_one=True,
414414
) -> BinaryExpression:
415-
raise NotImplemented('upsert only support PostgreSQL')
415+
raise NotImplementedError

src/fastapi_quickcrud/misc/abstract_route.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@
1010

1111

1212
class SQLAlchemyGeneralSQLBaseRouteSource(ABC):
13-
'''
14-
This route will support the SQL SQLAlchemy dialects
15-
'''
13+
""" This route will support the SQL SQLAlchemy dialects. """
1614

1715
@classmethod
1816
def find_one(cls, api,

src/fastapi_quickcrud/misc/memory_sql.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,12 @@
1010

1111

1212
class MemorySql():
13-
def __init__(self, async_mode=False):
13+
def __init__(self, async_mode: bool = False):
14+
"""
15+
16+
@type async_mode: bool
17+
used to build sync or async memory sql connection
18+
"""
1419
self.async_mode = async_mode
1520
SQLALCHEMY_DATABASE_URL = f"sqlite{'+aiosqlite' if async_mode else ''}://"
1621
if not async_mode:

src/fastapi_quickcrud/misc/schema_builder.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ def _add_orm_model_config_into_pydantic_model(pydantic_model, **kwargs) -> BaseM
9090
# __validators__={**validators})
9191

9292
def _model_from_dataclass(kls: DataClassT) -> Type[BaseModel]:
93-
""" Converts a stdlib dataclass to a pydantic BaseModel """
93+
""" Converts a stdlib dataclass to a pydantic BaseModel. """
9494

9595
return pydantic_dataclass(kls).__pydantic_model__
9696

@@ -899,7 +899,7 @@ def upsert_many(self) -> Tuple:
899899
Optional[List[str]],
900900
Body(set(all_column_) - set(self.unique_fields),
901901
description='update_columns should contain which columns you want to update '
902-
f'when the unique columns got conflict'))
902+
'when the unique columns got conflict'))
903903
conflict_model = make_dataclass(
904904
f'{self.db_name + str(uuid.uuid4())}_Upsert_many_request_update_columns_when_conflict_request_body_model',
905905
[conflict_columns])
@@ -957,8 +957,6 @@ def create_one(self) -> Tuple:
957957
request_fields = []
958958
response_fields = []
959959

960-
# Create on_conflict Model
961-
all_column_ = [i['column_name'] for i in self.all_field]
962960

963961
# Create Request and Response Model
964962
all_field = deepcopy(self.all_field)
@@ -994,9 +992,6 @@ def create_many(self) -> Tuple:
994992
insert_fields = []
995993
response_fields = []
996994

997-
# Create on_conflict Model
998-
all_column_ = [i['column_name'] for i in self.all_field]
999-
1000995
# Ready the Request and Response Model
1001996
all_field = deepcopy(self.all_field)
1002997
for i in all_field:

tests/test_implementations/other/__init__.py

Whitespace-only changes.

tests/test_implementations/test_memory_sqlalchemy/api_async_test/__init__.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
import os
22

33
from fastapi import FastAPI
4-
from sqlalchemy import ARRAY, BigInteger, Boolean, CHAR, Column, Date, DateTime, Float, Integer, \
5-
JSON, LargeBinary, Numeric, SmallInteger, String, Text, Time, UniqueConstraint, text
6-
from sqlalchemy.dialects.postgresql import INTERVAL, JSONB, UUID
7-
from sqlalchemy.orm import declarative_base, sessionmaker, synonym
4+
from sqlalchemy import BigInteger, Boolean, CHAR, Column, Date, DateTime, Float, Integer, \
5+
LargeBinary, Numeric, SmallInteger, String, Text, Time, UniqueConstraint, text
6+
from sqlalchemy.orm import declarative_base
87

98
TEST_DATABASE_URL = os.environ.get('TEST_DATABASE_URL', 'postgresql://postgres:1234@127.0.0.1:5432/postgres')
109

tests/test_implementations/test_memory_sqlalchemy/api_async_test/test_other_default_value.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
from fastapi import FastAPI
99
from sqlalchemy import BigInteger, Boolean, CHAR, Column, Date, DateTime, Float, Integer, \
10-
LargeBinary, Numeric, SmallInteger, String, Text, Time, UniqueConstraint, func
10+
LargeBinary, Numeric, SmallInteger, String, Text, Time, UniqueConstraint
1111
from sqlalchemy.orm import declarative_base
1212
from starlette.testclient import TestClient
1313

tests/test_implementations/test_memory_sqlalchemy/api_test/join_relationship/test_relationship_m2m.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
ForeignKey, Table
44
from sqlalchemy.orm import declarative_base, sessionmaker, relationship
55

6-
from src.fastapi_quickcrud.misc.type import SqlType
76
from src.fastapi_quickcrud.crud_router import crud_router_builder
87

98
app = FastAPI()
@@ -61,34 +60,34 @@ class ChildSecond(Base):
6160
db_model=Child,
6261
prefix="/child",
6362
tags=["child"],
64-
63+
6564
)
6665

6766
crud_route_association_table_second = crud_router_builder(db_session=get_transaction_session,
6867
db_model=association_table_second,
6968
prefix="/association_table_second",
7069
tags=["association_table_second"],
71-
70+
7271
)
7372

7473
crud_route_child_second = crud_router_builder(db_session=get_transaction_session,
7574
db_model=Child,
7675
prefix="/child_second",
7776
tags=["child_second"],
78-
77+
7978
)
8079

8180
crud_route_parent = crud_router_builder(db_session=get_transaction_session,
8281
db_model=Parent,
8382
prefix="/parent",
8483
tags=["parent"],
85-
84+
8685
)
8786
crud_route_association = crud_router_builder(db_session=get_transaction_session,
8887
db_model=association_table,
8988
prefix="/association",
9089
tags=["association"],
91-
90+
9291
)
9392
from starlette.testclient import TestClient
9493

0 commit comments

Comments
 (0)