当前位置: 首页 > article >正文

python: generator model using mysql9.0 or postgreSQL 17.0

mysql 9.0:

# 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      : MySqlGenerator/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() + "/mytest/model/")
        self.__file = FileHelper()
        self.__blltablekey = TableNameAndKeyBll()
        self.__bllTableModel = TableModelBll()
        self.__database = "MySQL 9.0"
        self.__os = "windows 10"
        self.__product = "PyCharm"
        self.__project = "IctGame"
        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 self.__blltablekey.selectSql():
            sbp=f"""
from model.{StrHelper.firstLower(li.TableName)} import {StrHelper.firstUper(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 self.__blltablekey.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 {StrHelper.firstUper(li.TableName)}Info(object):
    \"""
    {li.TableDescription}                    
    \""" 
"""
            sb.append(sbt)
            #tbll = TableModelBll()
            sinhead = f"""
    def __init__(self):
        \"""
            構造
        \"""               

              """
            sb.append((sinhead))
            for tli in self.__bllTableModel.selectSql(li.TableName):
                sin=f"""
        self._{tli.FieldName} = None
        \"""
        {tli.FieldDescription}
        \"""
        """
                sb.append(sin)
            for pli in self.__bllTableModel.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)


postgreSQL 17.0:

# 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      : postgreSqlGenerator/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() + "/posttest/model/")
        self.__file = FileHelper()
        self.__blltablekey = TableNameAndKeyBll()
        self.__bllTableModel = TableModelBll()
        self.__database = "postgreSQL 17.0"
        self.__os = "windows 10"
        self.__product = "PyCharm"
        self.__project = "IctGame"
        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 self.__blltablekey.selectSql():
            sbp=f"""
from model.{StrHelper.firstLower(li.TableName)} import {StrHelper.firstUper(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 self.__blltablekey.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 {StrHelper.firstUper(li.TableName)}Info(object):
    \"""
    {li.TableDescription}                    
    \""" 
"""
            sb.append(sbt)
            #tbll = TableModelBll()
            sinhead = f"""
    def __init__(self):
        \"""
            構造
        \"""               

              """
            sb.append((sinhead))
            for tli in self.__bllTableModel.selectSql(li.TableName):
                sin=f"""
        self._{tli.FieldName} = None
        \"""
        {tli.FieldDescription}
        \"""
        """
                sb.append(sin)
            for pli in self.__bllTableModel.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)


mysql:

postgresql:

sql server:


http://www.kler.cn/a/414699.html

相关文章:

  • AD7606使用方法
  • Python标识符命名规则
  • 非关系型数据库有哪些特点?
  • git 学习笔记
  • 讨论JAVA、JVM与Spring
  • openssl编译安装升级为新版本
  • 基于SpringBoot的“财务管理系统”的设计与实现(源码+数据库+文档+PPT)
  • Java基础面试题07:finalize() 方法什么时候被调用?析构函数(finalization)的目的是什么?
  • 【unity】WebSocket 与 EventSource 的区别
  • 状态模式S
  • 0.查找命令
  • 【docker 拉取镜像超时问题】
  • NeurIPS 2024 数据集汇总|覆盖云层去除/化学光谱/歌声音频/自动驾驶/昆虫标本······...
  • AI 声音:数字音频、语音识别、TTS 简介与使用示例
  • 爬虫开发(5)如何写一个CSDN热门榜爬虫小程序
  • 学习日志 --A5rZ
  • git:下载与安装
  • HTTPS的安全性优势
  • Pytorch中反向传播
  • C++初阶(十六)--STL--list的模拟实现
  • QT QFormLayout控件 全面详解
  • C++中的volatile关键字
  • torch.set_printoptions
  • 房屋出租出售预约系统支持微信小程序+H5+APP
  • 【含开题报告+文档+PPT+源码】基于SpringBoot的艺术培训学校管理系统的设计与实现
  • vue2 中使用 Ag-grid-enterprise 企业版