Skip to content

Commit

Permalink
Feature/enhance (#57)
Browse files Browse the repository at this point in the history
* feat: support show for _post_parsed field

* fix: post_parsed return json value

* fmt

---------

Co-authored-by: yongcai <[email protected]>
  • Loading branch information
WinChua and yongcai authored Dec 26, 2024
1 parent 63062b7 commit f58636b
Show file tree
Hide file tree
Showing 39 changed files with 620 additions and 348 deletions.
11 changes: 8 additions & 3 deletions devtools/create_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class User(Base):
name = Column(String(50))
age = Column(Integer)


with open(".deploy_mysqld") as f:
url = f.readline().strip()

Expand All @@ -29,13 +30,17 @@ class User(Base):
session = Session()

if len(sys.argv) > 1 and sys.argv[1] == "random":
ids = iter(random.sample(range(0, 2*1000*1000), 1000*1000))
ids = iter(random.sample(range(0, 2 * 1000 * 1000), 1000 * 1000))
for i in range(1000):
session.bulk_insert_mappings(User, [{"id": next(ids), "name":"Hello", "age": 10} for j in range(1000)])
session.bulk_insert_mappings(
User, [{"id": next(ids), "name": "Hello", "age": 10} for j in range(1000)]
)
elif len(sys.argv) > 1 and sys.argv[1] == "drop":
User.__table__.drop(bind=engine)
else:
for i in range(1000):
session.bulk_insert_mappings(User, [{"name":"Hello", "age": 10} for i in range(1000)])
session.bulk_insert_mappings(
User, [{"name": "Hello", "age": 10} for i in range(1000)]
)

session.commit()
44 changes: 22 additions & 22 deletions devtools/create_instant_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,42 +8,42 @@

with engine.connect() as conn:
conn.exec_driver_sql("use test")
conn.exec_driver_sql('''
conn.exec_driver_sql("""
DROP TABLE IF EXISTS test_for_instant;
''')
conn.exec_driver_sql('''
""")
conn.exec_driver_sql("""
CREATE TABLE test_for_instant (
id int(11) primary key auto_increment,
name varchar(255) NOT NULL,
drop1 int(11) NOT NULL,
drop2 varchar(255) not null default 'drop2'
)
''')
conn.exec_driver_sql('''
""")
conn.exec_driver_sql("""
insert into test_for_instant(name, drop1, drop2) values ("original record", 12, "original drop 2 column");
''')
conn.exec_driver_sql('''
""")
conn.exec_driver_sql("""
alter table test_for_instant add column add1 varchar(255) default null
''')
conn.exec_driver_sql('''
""")
conn.exec_driver_sql("""
alter table test_for_instant add column add2 varchar(255) default 'add2 default'
''')
conn.exec_driver_sql('''
""")
conn.exec_driver_sql("""
insert into test_for_instant (name, drop1, drop2, add2) values ('insert after alter', 93, 'drop2 after alter', 'add2')
''')
conn.exec_driver_sql('''
""")
conn.exec_driver_sql("""
alter table test_for_instant drop column drop1
''')
conn.exec_driver_sql('''
""")
conn.exec_driver_sql("""
alter table test_for_instant add column drop1 int(11) not null default '99'
''')
conn.exec_driver_sql('''
""")
conn.exec_driver_sql("""
insert into test_for_instant (name, drop1, drop2, add2) values ('insert after first add', 23, 'drop2 after first add', 'add2')
''')
conn.exec_driver_sql('''
""")
conn.exec_driver_sql("""
alter table test_for_instant add column add3 varchar(255) not null
''')
conn.exec_driver_sql('''
""")
conn.exec_driver_sql("""
insert into test_for_instant (name, drop1, drop2, add2, add3) values ('insert after second add', 23, 'drop2 after second add', 'add2', 'add3')
''')
""")
conn.commit()
114 changes: 56 additions & 58 deletions devtools/create_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
all_type = [
t
for t in dir(dmysql.types)
if t.isupper() and t not in ["ARRAY", "NULLTYPE", "STRINGTYPE", "DECIMAL"] and "CHAR" not in t
if t.isupper()
and t not in ["ARRAY", "NULLTYPE", "STRINGTYPE", "DECIMAL"]
and "CHAR" not in t
]
Base = declarative_base()
all_type_column = [
Expand All @@ -33,15 +35,9 @@
)
all_type_column.append(" ENUM = Column(dmysql.ENUM('hello', 'world', 'a'))")
all_type_column.append(" SET = Column(dmysql.SET('a', 'b', 'c'))")
all_type_column.append(
" DECIMAL = Column(dmysql.types.DECIMAL(10, 2))"
)
all_type_column.append(
" CHAR = Column(dmysql.types.CHAR(20), nullable=True)"
)
all_type_column.append(
" VARBINARY = Column(dmysql.VARBINARY(203))"
)
all_type_column.append(" DECIMAL = Column(dmysql.types.DECIMAL(10, 2))")
all_type_column.append(" CHAR = Column(dmysql.types.CHAR(20), nullable=True)")
all_type_column.append(" VARBINARY = Column(dmysql.VARBINARY(203))")
all_type_column.append(
" int_def_col = Column(dmysql.types.BIGINT, server_default=text('42'))"
)
Expand All @@ -60,59 +56,61 @@
Base.metadata.create_all(engine)

with sessionmaker(bind=engine)() as session:
test_data = AllType(BIGINT=98283201,
BIT = 1,
DATETIME='2024-01-01 09:00:01',
DOUBLE = 3.1415926,
FLOAT = 6.189,
INTEGER = 8621,
test_data = AllType(
BIGINT=98283201,
BIT=1,
DATETIME="2024-01-01 09:00:01",
DOUBLE=3.1415926,
FLOAT=6.189,
INTEGER=8621,
DECIMAL=910.79,
LONGBLOB=text("repeat('x', 100)"),
LONGTEXT = text("repeat('g', 3)"),
MEDIUMBLOB = text("NULL"),
MEDIUMINT = 999999,
MEDIUMTEXT = text("NULL"),
NUMERIC = 10.9,
REAL = 1092.892,
SMALLINT = 981,
TEXT = "TEXT",
TIME = '03:04:00',
TIMESTAMP = "2024-07-24 09:05:28",
YEAR = 2024,
ENUM = "a",
SET = "a,b,c",
TINYBLOB = b"TINYBLOB",
TINYINT = 99,
TINYTEXT = "TINYTEXT",
CHAR = "09283012",
VARBINARY = b"VARBINARY",
LONGTEXT=text("repeat('g', 3)"),
MEDIUMBLOB=text("NULL"),
MEDIUMINT=999999,
MEDIUMTEXT=text("NULL"),
NUMERIC=10.9,
REAL=1092.892,
SMALLINT=981,
TEXT="TEXT",
TIME="03:04:00",
TIMESTAMP="2024-07-24 09:05:28",
YEAR=2024,
ENUM="a",
SET="a,b,c",
TINYBLOB=b"TINYBLOB",
TINYINT=99,
TINYTEXT="TINYTEXT",
CHAR="09283012",
VARBINARY=b"VARBINARY",
)
test_data2 = AllType(BIGINT=98283201,
BIT = 1,
DATETIME='2024-01-01 09:00:01',
DOUBLE = 3.1415926,
FLOAT = 6.189,
INTEGER = 8621,
test_data2 = AllType(
BIGINT=98283201,
BIT=1,
DATETIME="2024-01-01 09:00:01",
DOUBLE=3.1415926,
FLOAT=6.189,
INTEGER=8621,
DECIMAL=910.79,
LONGBLOB=text("repeat('x', 100)"),
LONGTEXT = text("repeat('g', 3)"),
MEDIUMBLOB = text("NULL"),
MEDIUMINT = 999999,
MEDIUMTEXT = text("NULL"),
NUMERIC = 10.9,
REAL = 1092.892,
SMALLINT = 981,
TEXT = "TEXT",
TIME = '03:04:00',
TIMESTAMP = "2024-07-24 09:05:28",
YEAR = 2024,
ENUM = "a",
SET = "a,b,c",
TINYBLOB = b"TINYBLOB",
TINYINT = 99,
TINYTEXT = "TINYTEXT",
CHAR = text("NULL"),
VARBINARY = b"VARBINARY",
LONGTEXT=text("repeat('g', 3)"),
MEDIUMBLOB=text("NULL"),
MEDIUMINT=999999,
MEDIUMTEXT=text("NULL"),
NUMERIC=10.9,
REAL=1092.892,
SMALLINT=981,
TEXT="TEXT",
TIME="03:04:00",
TIMESTAMP="2024-07-24 09:05:28",
YEAR=2024,
ENUM="a",
SET="a,b,c",
TINYBLOB=b"TINYBLOB",
TINYINT=99,
TINYTEXT="TINYTEXT",
CHAR=text("NULL"),
VARBINARY=b"VARBINARY",
)
session.add(test_data)
session.add(test_data2)
Expand Down
23 changes: 15 additions & 8 deletions devtools/deploy_mysqld.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,18 @@
from testcontainers.mysql import MySqlContainer
from docker.models.containers import Container


@click.group()
def main():
pass


@main.command()
def list():
data = load_deploy()
pprint(data)


@main.command()
@click.option("--version", type=click.STRING)
def clean(version):
Expand All @@ -38,13 +41,15 @@ def clean(version):
with open(".deploy_mysqld", "w") as f:
dump_deploy(data, f)


@dataclass
class Instance:
url: str
container_id: str
cmd: str
datadir: str


def load_deploy():
if os.path.exists(".deploy_mysqld"):
with open(".deploy_mysqld", "r") as f:
Expand All @@ -59,19 +64,22 @@ def load_deploy():
return {}
return {}


def dump_deploy(data, f):
for k in data:
data[k] = asdict(data[k])

json.dump(data, f)


def mDeploy(version):
deploy_container = load_deploy()
if version in deploy_container:
print(f"a container of mysqld[{version}] has been deploy at {deploy_container[version]}")
print(
f"a container of mysqld[{version}] has been deploy at {deploy_container[version]}"
)
return


os.environ["TESTCONTAINERS_RYUK_DISABLED"] = "true"
mContainer = MySqlContainer(f"mysql:{version}")
datadir = os.getcwd() + f"/datadir/{version}"
Expand All @@ -81,10 +89,10 @@ def mDeploy(version):
mysql = mContainer.start()
with open(".deploy_mysqld", "w") as f:
deploy_container[version] = Instance(
url=mysql.get_connection_url(),
container_id=f"{mysql._container.short_id}",
cmd=f"mysql -h 127.0.0.1 -P{mysql.get_exposed_port(mysql.port)} -u{mysql.username} -p{mysql.password}",
datadir=datadir,
url=mysql.get_connection_url(),
container_id=f"{mysql._container.short_id}",
cmd=f"mysql -h 127.0.0.1 -P{mysql.get_exposed_port(mysql.port)} -u{mysql.username} -p{mysql.password}",
datadir=datadir,
)
dump_deploy(deploy_container, f)

Expand All @@ -105,7 +113,6 @@ def connect(version):

os.system(deploy_container.get(version).cmd)


if __name__ == "__main__":
main()


1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ dev-dependencies = [
"pymysql>=1.1.1",
"requests==2.31.0",
"cryptography>=43.0.0",
"python-lsp-server>=1.12.0",
]

[tool.hatch.metadata]
Expand Down
4 changes: 2 additions & 2 deletions src/pyinnodb/cli/frm.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from pyinnodb.sdi import table
from pyinnodb.disk_struct.index import MIndexPage


@main.command()
@click.pass_context
@click.argument("frmfile")
Expand All @@ -17,8 +18,7 @@ def frm(ctx, frmfile):
for i, col in enumerate(frm_header.cols):
cols.append(col.to_dd_column(col.name, i, frm_header.column_labels))


#print(frm_header.keys[0][0].key_parts)
# print(frm_header.keys[0][0].key_parts)
keys, key_name, key_comment = frm_header.keys[0]

idx = keys.to_dd_index(key_name.decode(), frm_header.cols)
Expand Down
Loading

0 comments on commit f58636b

Please sign in to comment.