Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Develop #17

Merged
merged 24 commits into from
Mar 6, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix codacy
  • Loading branch information
LuisLuii committed Mar 6, 2022
commit 8850fbdc5e619926c63ae5959b47069a32f73507
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,6 @@ app.include_router(crud_route_2)
```python
import uvicorn
from fastapi import FastAPI, Depends
from sqlalchemy.orm import declarative_base
from fastapi_quickcrud import CrudMethods
from fastapi_quickcrud import sqlalchemy_to_pydantic
from fastapi_quickcrud.misc.memory_sql import sync_memory_db
Expand Down
1 change: 0 additions & 1 deletion src/fastapi_quickcrud/crud_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
Depends, APIRouter
from pydantic import \
BaseModel
from sqlalchemy.orm import declarative_base
from sqlalchemy.sql.schema import Table

from . import sqlalchemy_to_pydantic
Expand Down
14 changes: 7 additions & 7 deletions src/fastapi_quickcrud/misc/abstract_query.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from abc import ABC
from typing import List, Union

from sqlalchemy import and_, select, update, text
from sqlalchemy import and_, select, text
from sqlalchemy.dialects.postgresql import insert
from sqlalchemy.sql.elements import BinaryExpression
from sqlalchemy.sql.schema import Table
Expand Down Expand Up @@ -302,7 +302,7 @@ def upsert(self, *,
unique_fields: List[str],
upsert_one=True,
) -> BinaryExpression:
raise NotImplemented('upsert only support PostgreSQL')
raise NotImplementedError


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


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


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


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


class SQLAlchemyNotSupportQueryService(SQLAlchemyGeneralSQLQueryService):
Expand All @@ -412,4 +412,4 @@ def upsert(self, *,
unique_fields: List[str],
upsert_one=True,
) -> BinaryExpression:
raise NotImplemented('upsert only support PostgreSQL')
raise NotImplementedError
4 changes: 1 addition & 3 deletions src/fastapi_quickcrud/misc/abstract_route.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@


class SQLAlchemyGeneralSQLBaseRouteSource(ABC):
'''
This route will support the SQL SQLAlchemy dialects
'''
""" This route will support the SQL SQLAlchemy dialects. """

@classmethod
def find_one(cls, api,
Expand Down
7 changes: 6 additions & 1 deletion src/fastapi_quickcrud/misc/memory_sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@


class MemorySql():
def __init__(self, async_mode=False):
def __init__(self, async_mode: bool = False):
"""

@type async_mode: bool
used to build sync or async memory sql connection
"""
self.async_mode = async_mode
SQLALCHEMY_DATABASE_URL = f"sqlite{'+aiosqlite' if async_mode else ''}://"
if not async_mode:
Expand Down
9 changes: 2 additions & 7 deletions src/fastapi_quickcrud/misc/schema_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def _add_orm_model_config_into_pydantic_model(pydantic_model, **kwargs) -> BaseM
# __validators__={**validators})

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

return pydantic_dataclass(kls).__pydantic_model__

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

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

# Create Request and Response Model
all_field = deepcopy(self.all_field)
Expand Down Expand Up @@ -994,9 +992,6 @@ def create_many(self) -> Tuple:
insert_fields = []
response_fields = []

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

# Ready the Request and Response Model
all_field = deepcopy(self.all_field)
for i in all_field:
Expand Down
Empty file.
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import os

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

TEST_DATABASE_URL = os.environ.get('TEST_DATABASE_URL', 'postgresql://postgres:[email protected]:5432/postgres')

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from fastapi import FastAPI
from sqlalchemy import BigInteger, Boolean, CHAR, Column, Date, DateTime, Float, Integer, \
LargeBinary, Numeric, SmallInteger, String, Text, Time, UniqueConstraint, func
LargeBinary, Numeric, SmallInteger, String, Text, Time, UniqueConstraint
from sqlalchemy.orm import declarative_base
from starlette.testclient import TestClient

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
ForeignKey, Table
from sqlalchemy.orm import declarative_base, sessionmaker, relationship

from src.fastapi_quickcrud.misc.type import SqlType
from src.fastapi_quickcrud.crud_router import crud_router_builder

app = FastAPI()
Expand Down Expand Up @@ -61,34 +60,34 @@ class ChildSecond(Base):
db_model=Child,
prefix="/child",
tags=["child"],

)

crud_route_association_table_second = crud_router_builder(db_session=get_transaction_session,
db_model=association_table_second,
prefix="/association_table_second",
tags=["association_table_second"],

)

crud_route_child_second = crud_router_builder(db_session=get_transaction_session,
db_model=Child,
prefix="/child_second",
tags=["child_second"],

)

crud_route_parent = crud_router_builder(db_session=get_transaction_session,
db_model=Parent,
prefix="/parent",
tags=["parent"],

)
crud_route_association = crud_router_builder(db_session=get_transaction_session,
db_model=association_table,
prefix="/association",
tags=["association"],

)
from starlette.testclient import TestClient

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
Column('array_value', ARRAY(Integer())),
Column('array_str__value', ARRAY(String())),
)
from sqlalchemy.orm import declarative_base, synonym, sessionmaker
from sqlalchemy.orm import sessionmaker
import os
from sqlalchemy import create_engine
TEST_DATABASE_URL = os.environ.get('TEST_DATABASE_ASYNC_URL',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@
from sqlalchemy.dialects.postgresql import INTERVAL, JSONB, UUID
from sqlalchemy.orm import declarative_base

from src.fastapi_quickcrud import crud_router_builder, sqlalchemy_to_pydantic
from src.fastapi_quickcrud.misc.utils import table_to_declarative_base
from src.fastapi_quickcrud import sqlalchemy_to_pydantic
from src.fastapi_quickcrud import CrudMethods
from src.fastapi_quickcrud.misc.exceptions import ColumnTypeNotSupportedException

Base = declarative_base()

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from sqlalchemy import ARRAY, BigInteger, Boolean, CHAR, Column, Date, DateTime, Float, Integer, \
JSON, LargeBinary, Numeric, SmallInteger, String, Text, Time, text, PrimaryKeyConstraint
from sqlalchemy.dialects.postgresql import INTERVAL, JSONB, UUID
from sqlalchemy.orm import declarative_base, synonym
from sqlalchemy.orm import declarative_base

from src.fastapi_quickcrud import sqlalchemy_to_pydantic, CrudMethods
from src.fastapi_quickcrud.misc.exceptions import SchemaException
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from sqlalchemy import ARRAY, BigInteger, Boolean, CHAR, Column, Date, DateTime, Float, Integer, \
JSON, LargeBinary, Numeric, SmallInteger, String, Text, Time, text, PrimaryKeyConstraint
from sqlalchemy.dialects.postgresql import INTERVAL, JSONB, UUID
from sqlalchemy.orm import declarative_base, synonym
from sqlalchemy.orm import declarative_base

from src.fastapi_quickcrud import sqlalchemy_to_pydantic, CrudMethods
from src.fastapi_quickcrud.misc.exceptions import SchemaException
Expand Down