|
1 | 1 | import sqlalchemy
|
2 | 2 | from sqlalchemy.dialects import mysql as dmysql
|
3 |
| -from sqlalchemy.orm import declarative_base |
| 3 | +from sqlalchemy.orm import declarative_base, sessionmaker |
4 | 4 | from sqlalchemy import Column
|
5 |
| -from sqlalchemy import text |
| 5 | +from sqlalchemy import text, insert |
| 6 | +import time |
6 | 7 |
|
7 | 8 | with open(".deploy_mysqld") as f:
|
8 | 9 | url = f.readline().strip()
|
|
18 | 19 | all_type = [
|
19 | 20 | t
|
20 | 21 | for t in dir(dmysql.types)
|
21 |
| - if t.isupper() and t not in ["ARRAY", "NULLTYPE", "STRINGTYPE"] and "CHAR" not in t |
| 22 | + if t.isupper() and t not in ["ARRAY", "NULLTYPE", "STRINGTYPE", "DECIMAL"] and "CHAR" not in t |
22 | 23 | ]
|
23 | 24 | Base = declarative_base()
|
24 | 25 | all_type_column = [
|
|
31 | 32 | )
|
32 | 33 | all_type_column.append(" ENUM = Column(dmysql.ENUM('hello', 'world', 'a'))")
|
33 | 34 | all_type_column.append(" SET = Column(dmysql.SET('a', 'b', 'c'))")
|
| 35 | +all_type_column.append( |
| 36 | + " DECIMAL = Column(dmysql.types.DECIMAL(10, 2))" |
| 37 | +) |
| 38 | +all_type_column.append( |
| 39 | + " CHAR = Column(dmysql.types.CHAR(20))" |
| 40 | +) |
| 41 | +all_type_column.append( |
| 42 | + " VARBINARY = Column(dmysql.VARBINARY(203))" |
| 43 | +) |
34 | 44 | all_type_column.append(
|
35 | 45 | " int_def_col = Column(dmysql.types.BIGINT, server_default=text('42'))"
|
36 | 46 | )
|
|
40 | 50 | exec("\n".join(all_type_column))
|
41 | 51 | AllType = locals().get("AllType")
|
42 | 52 | engine = sqlalchemy.create_engine(url)
|
| 53 | + |
| 54 | +with engine.connect() as conn: |
| 55 | + conn.exec_driver_sql("use test") |
| 56 | + conn.exec_driver_sql("drop table if exists all_type") |
| 57 | + conn.commit() |
| 58 | + |
43 | 59 | Base.metadata.create_all(engine)
|
| 60 | + |
| 61 | +with sessionmaker(bind=engine)() as session: |
| 62 | + test_data = AllType(BIGINT=98283201, |
| 63 | + BIT = 1, |
| 64 | + DATETIME='2024-01-01 09:00:01', |
| 65 | + DOUBLE = 3.1415926, |
| 66 | + FLOAT = 6.189, |
| 67 | + INTEGER = 8621, |
| 68 | + DECIMAL=910.79, |
| 69 | + LONGBLOB=text("repeat('x', 100)"), |
| 70 | + LONGTEXT = text("repeat('g', 3)"), |
| 71 | + MEDIUMBLOB = text("NULL"), |
| 72 | + MEDIUMINT = 999999, |
| 73 | + MEDIUMTEXT = text("NULL"), |
| 74 | + NUMERIC = 10.9, |
| 75 | + REAL = 1092.892, |
| 76 | + SMALLINT = 981, |
| 77 | + TEXT = "TEXT", |
| 78 | + TIME = '03:04:00', |
| 79 | + TIMESTAMP = "2024-07-24 09:05:28", |
| 80 | + YEAR = 2024, |
| 81 | + ENUM = "a", |
| 82 | + SET = "a,b,c", |
| 83 | + TINYBLOB = b"TINYBLOB", |
| 84 | + TINYINT = 99, |
| 85 | + TINYTEXT = "TINYTEXT", |
| 86 | + CHAR = "09283012", |
| 87 | + VARBINARY = b"VARBINARY", |
| 88 | + ) |
| 89 | + session.add(test_data) |
| 90 | + session.commit() |
0 commit comments