-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from zy7y/develop
Develop
- Loading branch information
Showing
11 changed files
with
275 additions
and
200 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
name: pip install check | ||
|
||
on: | ||
push: | ||
branches: | ||
- develop | ||
|
||
jobs: | ||
build: | ||
runs-on: ${{ matrix.os }} | ||
strategy: | ||
matrix: | ||
os: [ windows-latest, ubuntu-latest, macos-latest ] | ||
python-version: [ "3.8", "3.9", "3.10", "3.11" ] | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Set up Python ${{ matrix.python-version }} | ||
uses: actions/setup-python@v3 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
- name: Install dependencies | ||
run: | | ||
pip install -r requirements.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
name: release | ||
|
||
on: | ||
push: | ||
tags: | ||
- v* | ||
|
||
jobs: | ||
|
||
# 创建发布 | ||
release: | ||
runs-on: ubuntu-latest | ||
# 输出变量 | ||
outputs: | ||
upload_url: ${{ steps.create_release.outputs.upload_url }} | ||
steps: | ||
- name: Create release | ||
id: create_release | ||
uses: actions/create-release@v1 | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.TOKEN }} | ||
with: | ||
tag_name: ${{ github.ref }} | ||
release_name: Release ${{ github.ref }} | ||
body: | | ||
Release ${{ github.ref }} | ||
draft: false | ||
prerelease: false | ||
|
||
|
||
# 打包上传 | ||
build-windows-app: | ||
needs: release | ||
runs-on: windows-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Set up Python 3.10 | ||
uses: actions/setup-python@v3 | ||
with: | ||
python-version: "3.10" | ||
- name: Install dependencies | ||
run: | | ||
pip install -r requirements.txt | ||
- name: Build executable | ||
run: | | ||
pyinstaller --windowed --onefile main.py | ||
- name: Upload executables | ||
uses: actions/upload-release-asset@v1 | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.TOKEN }} | ||
with: | ||
# 获取变量 | ||
upload_url: ${{ needs.release.outputs.upload_url }} | ||
asset_path: ./dist/main.exe | ||
asset_name: dfs-generate.exe | ||
asset_content_type: application/octet-stream |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
import uuid | ||
from typing import Generic, List, Optional, TypeVar | ||
|
||
import black | ||
import isort | ||
from pydantic import BaseModel, ConfigDict, field_serializer | ||
from pydantic.alias_generators import to_camel | ||
from sqlmodel import Field, MetaData, Session, SQLModel, create_engine, select | ||
|
||
db_uri = "sqlite:///main.sqlite" | ||
engine = create_engine(db_uri) | ||
|
||
|
||
def get_metadata_by_db_uri(uri: str): | ||
db_engine = create_engine(uri) | ||
db_metadata = MetaData() | ||
db_metadata.reflect(bind=db_engine) | ||
return db_metadata | ||
|
||
|
||
class Conf(SQLModel, table=True): | ||
__tablename__ = "dfs_conf" | ||
id: int = Field(None, primary_key=True) | ||
db_uri: str = Field(..., description="数据库连接") | ||
|
||
@classmethod | ||
def get_db_uri_last_new(cls): | ||
"""获取最新的db_url""" | ||
with Session(engine) as session: | ||
query = select(cls).order_by(cls.id.desc()) | ||
latest_conf = session.exec(query).first() | ||
if latest_conf: | ||
return latest_conf.db_uri | ||
else: | ||
return None | ||
|
||
@classmethod | ||
def create(cls, uri) -> "Conf": | ||
with Session(engine) as session: | ||
obj = cls(db_uri=uri) | ||
session.add(obj) | ||
session.commit() | ||
session.refresh(obj) | ||
return obj | ||
|
||
@classmethod | ||
def get_last_uri_with_metadata(cls): | ||
uri = cls.get_db_uri_last_new() | ||
return uri, get_metadata_by_db_uri(uri) | ||
|
||
|
||
T = TypeVar("T") | ||
|
||
|
||
class R(BaseModel, Generic[T]): | ||
code: int = 20000 | ||
msg: str = "ok" | ||
data: Optional[T] = None | ||
|
||
@classmethod | ||
def success(cls, **kwargs): | ||
return cls(**kwargs) | ||
|
||
@classmethod | ||
def error(cls, msg): | ||
return cls(code=40000, msg=msg) | ||
|
||
|
||
class RList(R[T]): | ||
data: List[T] = Field(default_factory=list) | ||
|
||
|
||
class BaseVo(SQLModel): | ||
key: uuid.UUID = Field(default_factory=uuid.uuid4) | ||
model_config = ConfigDict(alias_generator=to_camel, populate_by_name=True) | ||
|
||
|
||
class Table(BaseVo): | ||
table_name: str | ||
table_comment: Optional[str] = None | ||
|
||
|
||
class DBConf(SQLModel): | ||
user: str | ||
password: str | ||
port: int | ||
host: str | ||
db: str | ||
|
||
def get_db_uri(self): | ||
return f"mysql+pymysql://{self.user}:{self.password}@{self.host}:{self.port}/{self.db}" | ||
|
||
def get_metadata(self): | ||
return get_metadata_by_db_uri(self.get_db_uri()) | ||
|
||
|
||
class CodeGen(BaseVo): | ||
name: str | ||
code: str | ||
|
||
@field_serializer("code") | ||
def serialize_code(self, code: str, _info): | ||
_code = black.format_str(code, mode=black.FileMode()) | ||
return isort.code(_code) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +0,0 @@ | ||
from generate.db import render as db_code_render | ||
from generate.main import render as main_render | ||
from generate.model import GenerateEntity | ||
from generate.router import render as router_render | ||
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.