You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
40 lines
1.1 KiB
40 lines
1.1 KiB
3 years ago
|
#!/usr/bin/env python
|
||
|
# -*- encoding: utf-8 -*-
|
||
|
'''
|
||
|
@Date:2022/07/13 14:37:18
|
||
|
'''
|
||
|
|
||
|
|
||
|
def model_name_loer(db_model):
|
||
|
for i in db_model.split("\n"):
|
||
|
base = i.split(" = ")
|
||
|
if len(base) < 2:
|
||
|
continue
|
||
|
# print(base)
|
||
|
name = ""
|
||
|
base_name = base[0].replace(" ", '')
|
||
|
for k, v in enumerate(base_name):
|
||
|
if k != 0 and name and v.isupper():
|
||
|
name += '_'
|
||
|
if v.isupper():
|
||
|
name += v.lower()
|
||
|
else:
|
||
|
name += v
|
||
|
base_d = base[1].replace(" ", '')
|
||
|
comment = base_d.split("#")
|
||
|
try:
|
||
|
db_comment = comment[1]
|
||
|
except IndexError:
|
||
|
db_comment = ''
|
||
|
|
||
|
comment_name = comment[0][:-1] + f', comment="{db_comment}")'
|
||
|
print(f"{name} = {comment_name}")
|
||
|
|
||
|
|
||
|
def create_table(Base):
|
||
|
from sqlalchemy import create_engine
|
||
|
engine = create_engine('mysql+mysqldb://root:123456@localhost:3306/local_rms_db',
|
||
|
pool_recycle=10600, pool_size=100, max_overflow=20)
|
||
|
|
||
|
Base.metadata.create_all(engine)
|