Skip to content

Feature/model code gen #23

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

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,6 @@ workspace.xml
*.iml
*.xml
*.sh
fastapi_quickcrud_code_generator_beta.egg-info
src/fastapi_quick_crud_template
src/fastapi_quickcrud_codegen_backup
5 changes: 5 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
include src/fastapi_quickcrud_codegen/model/template/common/*.jinja2
include src/fastapi_quickcrud_codegen/model/template/pydantic/*.jinja2
include src/fastapi_quickcrud_codegen/model/template/route/*.jinja2
include src/fastapi_quickcrud_codegen/model/template/sqlalchemy/*.jinja2
include src/fastapi_quickcrud_codegen/model/template/*.jinja2
87 changes: 87 additions & 0 deletions sample_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import os

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

from fastapi_quickcrud_codegen import crud_router_builder, CrudMethods

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

app = FastAPI()

Base = declarative_base()
metadata = Base.metadata

from sqlalchemy import create_engine

engine = create_engine(TEST_DATABASE_URL, future=True, echo=True,
pool_use_lifo=True, pool_pre_ping=True, pool_recycle=7200)
async_session = sessionmaker(autocommit=False, autoflush=False, bind=engine)


def get_transaction_session():
try:
db = async_session()
yield db
finally:
db.close()


class UntitledTable256(Base):
primary_key_of_table = "primary_key"
unique_fields = ['primary_key', 'int4_value', 'float4_value']
__tablename__ = 'test_build_myself'
__table_args__ = (
UniqueConstraint('primary_key', 'int4_value', 'float4_value'),
)
primary_key = Column(Integer, primary_key=True, info={'alias_name': 'primary_key'}, autoincrement=True,
server_default="nextval('test_build_myself_id_seq'::regclass)")
bool_value = Column(Boolean, nullable=False, server_default=text("false"))
# bytea_value = Column(LargeBinary)
char_value = Column(CHAR(10))
date_value = Column(Date, server_default=text("now()"))
float4_value = Column(Float, nullable=False)
float8_value = Column(Float(53), nullable=False, server_default=text("10.10"))
int2_value = Column(SmallInteger, nullable=False)
int4_value = Column(Integer, nullable=True)
int8_value = Column(BigInteger, server_default=text("99"))
interval_value = Column(INTERVAL)
json_value = Column(JSON)
jsonb_value = Column(JSONB(astext_type=Text()))
numeric_value = Column(Numeric)
text_value = Column(Text)
time_value = Column(Time)
timestamp_value = Column(DateTime)
timestamptz_value = Column(DateTime(True))
timetz_value = Column(Time(True))
uuid_value = Column(UUID(as_uuid=True))
varchar_value = Column(String)
# xml_value = Column(NullType)
array_value = Column(ARRAY(Integer()))
array_str__value = Column(ARRAY(String()))
# box_valaue = Column(NullType)


crud_route_child2 = crud_router_builder(
db_model=UntitledTable256,
prefix="/blog_comment",
tags=["blog_comment"],
db_session=get_transaction_session,
crud_methods=[CrudMethods.FIND_ONE]
)

app = FastAPI()
[app.include_router(i) for i in [crud_route_child2]]


@app.get("/", tags=["child"])
async def root():
return {"message": "Hello World"}


import uvicorn

uvicorn.run(app, host="0.0.0.0", port=8002, debug=False)
11 changes: 8 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from setuptools import setup, find_packages

VERSION = '0.2.1'
VERSION = '0.0.7'

print("""

Expand All @@ -16,7 +16,7 @@

if __name__ == '__main__':
setup(
name='fastapi_quickcrud',
name='fastapi_quickcrud_code_generator_beta',
version=VERSION,
install_requires=["fastapi<=0.68.2","pydantic<=1.8.2","SQLAlchemy<=1.4.30","StrEnum==0.4.7","starlette==0.14.2",
"aiosqlite==0.17.0","uvicorn==0.17.0","greenlet==1.1.2","anyio==3.5.0"],
Expand All @@ -29,7 +29,11 @@
url='https://github.com/LuisLuii/FastAPIQuickCRUD',
license="MIT License",
keywords=["fastapi", "crud", "restful", "routing","SQLAlchemy", "generator", "crudrouter","postgresql","builder"],
packages=find_packages('src'),
packages=find_packages("src", include="*.jinja2"),
package_data={
'': ['*.jinja2'],
'src.fastapi_quickcrud_codegen.model.template.common': ['*.jinja2'],
},
package_dir={'': 'src'},
setup_requires=["setuptools>=31.6.0"],
classifiers=[
Expand Down Expand Up @@ -60,3 +64,4 @@
],
include_package_data=True,
)
print(find_packages("src"))
86 changes: 86 additions & 0 deletions src/sample_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import os

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

from fastapi_quickcrud_codegen import crud_router_builder, CrudMethods

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

app = FastAPI()

Base = declarative_base()
metadata = Base.metadata

from sqlalchemy import create_engine

engine = create_engine(TEST_DATABASE_URL, future=True, echo=True,
pool_use_lifo=True, pool_pre_ping=True, pool_recycle=7200)
async_session = sessionmaker(autocommit=False, autoflush=False, bind=engine)


def get_transaction_session():
try:
db = async_session()
yield db
finally:
db.close()


class UntitledTable256(Base):
primary_key_of_table = "primary_key"
unique_fields = ['primary_key', 'int4_value', 'float4_value']
__tablename__ = 'test_build_myself'
__table_args__ = (
UniqueConstraint('primary_key', 'int4_value', 'float4_value'),
)
primary_key = Column(Integer, primary_key=True, info={'alias_name': 'primary_key'}, autoincrement=True,
server_default="nextval('test_build_myself_id_seq'::regclass)")
bool_value = Column(Boolean, nullable=False, server_default=text("false"))
# bytea_value = Column(LargeBinary)
char_value = Column(CHAR(10))
date_value = Column(Date, server_default=text("now()"))
float4_value = Column(Float, nullable=False)
float8_value = Column(Float(53), nullable=False, server_default=text("10.10"))
int2_value = Column(SmallInteger, nullable=False)
int4_value = Column(Integer, nullable=True)
int8_value = Column(BigInteger, server_default=text("99"))
interval_value = Column(INTERVAL)
json_value = Column(JSON)
jsonb_value = Column(JSONB(astext_type=Text()))
numeric_value = Column(Numeric)
text_value = Column(Text)
time_value = Column(Time)
timestamp_value = Column(DateTime)
timestamptz_value = Column(DateTime(True))
timetz_value = Column(Time(True))
uuid_value = Column(UUID(as_uuid=True))
varchar_value = Column(String)
# xml_value = Column(NullType)
array_value = Column(ARRAY(Integer()))
array_str__value = Column(ARRAY(String()))
# box_valaue = Column(NullType)


crud_route_child2 = crud_router_builder(
db_model=UntitledTable256,
prefix="/blog_comment",
tags=["blog_comment"],
db_session=get_transaction_session
)

app = FastAPI()
[app.include_router(i) for i in [crud_route_child2]]


@app.get("/", tags=["child"])
async def root():
return {"message": "Hello World"}


import uvicorn

uvicorn.run(app, host="0.0.0.0", port=8002, debug=False)
1 change: 1 addition & 0 deletions tutorial/foreign_tree/async_m2m.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import asyncio
import inspect

from fastapi import FastAPI
from sqlalchemy import Column, Integer, \
Expand Down