python: generator model using sql server 2019
設計或生成好數據庫,可以生成自己設計好的框架項目
# encoding: utf-8
# 版权所有 :2024 ©涂聚文有限公司
# 许可信息查看 :言語成了邀功盡責的功臣,還需要行爲每日來值班嗎
# 描述: : 生成实体
# Author : geovindu,Geovin Du 涂聚文.
# IDE : PyCharm 2023.1 python 3.11
# OS : windows 10
# Datetime : 2024/11/18 22:41
# User : geovindu
# Product : PyCharm
# Project : pyGenerator
# File : SqlServerGenerator/CreateModel.py
# explain : 学习
import os
import re
import sys
import io
import datetime
from common.fileHelper import FileHelper
from common.strHelper import StrHelper
from bll.tableNameAndKey import TableNameAndKeyBll
from bll.tableForegin import TableForeginBll
from bll.tableModel import TableModelBll
class CreateModel(object):
"""
"""
def __init__(self):
self.__modelpath = os.path.join(os.getcwd() + "/test/model/")
self.__file = FileHelper()
self.__blltablekey = TableNameAndKeyBll()
self.__database = "sql server 2019"
self.__name = "CreateModel"
pass
def __del__(self):
"""
:return:
"""
print(f"{self.__name} ERASE MEMORY")
def addpackagefile(self):
"""
生成包配置文件
:return:
"""
now = datetime.datetime.now()
bll = TableNameAndKeyBll()
sb = []
sbt = f"""
# encoding: utf-8
# 版权所有 2024 ©涂聚文有限公司
# 许可信息查看:言語成了邀功盡責的功臣,還需要行爲每日來值班嗎
# 描述:
# Author : geovindu,Geovin Du 涂聚文.
# IDE : PyCharm 2023.1 python 3.11
# OS : windows 10
# Datetime : {now.strftime('%Y-%m-%d %H:%M:%S')}
# database :{self.__database}
# User : geovindu
# Product : PyCharm
# Project : IctGame
# File : model/__init__.py
# explain : 学习
"""
sb.append(sbt)
for li in bll.selectSql():
sbp=f"""
from model.{StrHelper.firstLower(li.TableName)} import {li.TableName}Info
"""
sb.append(sbp)
if not os.path.exists(self.__modelpath):
os.makedirs(self.__modelpath)
filepath = self.__modelpath + '__init__.py'
content = ''.join(sb)
ok = self.__file.createModelFile(filepath, content)
def add(self):
"""
生成实体
:return:
"""
#fileHelper=FileHelper()
now = datetime.datetime.now()
bll = TableNameAndKeyBll()
for li in bll.selectSql():
sb = []
sbt=f"""
# encoding: utf-8
# 版权所有 2024 ©涂聚文有限公司
# 许可信息查看:言語成了邀功盡責的功臣,還需要行爲每日來值班嗎
# 描述:
# Author : geovindu,Geovin Du 涂聚文.
# IDE : PyCharm 2023.1 python 3.11
# OS : windows 10
# Datetime : {now.strftime('%Y-%m-%d %H:%M:%S')}
# database :{self.__database}
# User : geovindu
# Product : PyCharm
# Project : IctGame
# File : model/{li.TableName}.py
# explain : 学习
class {li.TableName}Info(object):
\"""
{li.TableDescription}
\"""
"""
sb.append(sbt)
tbll = TableModelBll()
sinhead = f"""
def __init__(self):
\"""
構造
\"""
"""
sb.append((sinhead))
for tli in tbll.selectSql(li.TableName):
sin=f"""
self._{tli.FieldName} = None
\"""
{tli.FieldDescription}
\"""
"""
sb.append(sin)
for pli in tbll.selectSql(li.TableName):
psb=f"""
@property
def {pli.FieldName}(self):
\"""
{pli.FieldDescription}
\"""
return self._{pli.FieldName}
@{pli.FieldName}.setter
def {pli.FieldName}(self, {StrHelper.firstLower(pli.FieldName)}):
\"""
{pli.FieldDescription}
:param {pli.FieldName}:
:return:
\"""
self._{pli.FieldName} = {StrHelper.firstLower(pli.FieldName)}
"""
sb.append(psb)
if not os.path.exists(self.__modelpath):
os.makedirs(self.__modelpath)
filepath=self.__modelpath+StrHelper.firstLower(li.TableName)+'.py'
content=''.join(sb)
ok = self.__file.createModelFile(filepath,content)
原設計的表有表,列的描述
生成器生成的代碼:
# encoding: utf-8
# 版权所有 2024 ©涂聚文有限公司
# 许可信息查看:言語成了邀功盡責的功臣,還需要行爲每日來值班嗎
# 描述:
# Author : geovindu,Geovin Du 涂聚文.
# IDE : PyCharm 2023.1 python 3.11
# OS : windows 10
# Datetime : 2024-11-19 05:45:09
# database :sql server 2019
# User : geovindu
# Product : PyCharm
# Project : IctGame
# File : model/School.py
# explain : 学习
class SchoolInfo(object):
"""
学校表
"""
def __init__(self):
"""
構造
"""
self._SchoolId = None
"""
ID,主键
"""
self._SchoolName = None
"""
校名
"""
self._SchoolTelNo = None
"""
学校电话
"""
@property
def SchoolId(self):
"""
ID,主键
"""
return self._SchoolId
@SchoolId.setter
def SchoolId(self, schoolId):
"""
ID,主键
:param SchoolId:
:return:
"""
self._SchoolId = schoolId
@property
def SchoolName(self):
"""
校名
"""
return self._SchoolName
@SchoolName.setter
def SchoolName(self, schoolName):
"""
校名
:param SchoolName:
:return:
"""
self._SchoolName = schoolName
@property
def SchoolTelNo(self):
"""
学校电话
"""
return self._SchoolTelNo
@SchoolTelNo.setter
def SchoolTelNo(self, schoolTelNo):
"""
学校电话
:param SchoolTelNo:
:return:
"""
self._SchoolTelNo = schoolTelNo