This commit is contained in:
halliday 2024-12-24 20:11:28 +08:00
parent 78b59c3ac6
commit e9a1e2c747
5 changed files with 72 additions and 10 deletions

1
.gitignore vendored
View File

@ -162,3 +162,4 @@ cython_debug/
/.vscode /.vscode
/data/ /data/
devenv/

View File

@ -134,3 +134,62 @@ def oracle_config():
return(oracle_info_dict) return(oracle_info_dict)
def pg_config():
pg_info_dict={}
pg_info_dict['driver_name'] = "org.postgresql.Driver"
pg_info_dict['driver_jar'] = "postgresql-42.5.2.jar"
driver_jar_path = etc_dir / "driver" / pg_info_dict['driver_jar']
pg_info_dict['driver_jar_path'] = str(driver_jar_path)
#这里要连接到具体的库
pg_info_dict['jdbc_url'] = "jdbc:postgresql://" + config['IP'] + ":" + config['PROT'] + "/" + config['DATABASES']
pg_info_dict['db_user'] = config['DBUSER']
pg_info_dict['db_password'] = config['DBPASSWD']
#create table sql
week = get_now()
table_name = "pg_test_table_w" + week
create_sql_string = "CREATE TABLE "
create_sql_string += table_name
create_sql_string += "("
create_sql_string += "uuid varchar(50) NULL,"
create_sql_string += "id integer NULL,"
create_sql_string += "name varchar(50) NULL,"
create_sql_string += "mobile varchar(50) NULL,"
create_sql_string += "ssn varchar(50) NULL,"
create_sql_string += "sex integer NULL,"
create_sql_string += "email varchar(50) NULL,"
create_sql_string += "job varchar(50) NULL,"
create_sql_string += "address varchar(150) NULL,"
create_sql_string += "actime_time varchar(50) NULL"
create_sql_string += ")"
pg_info_dict['create_sql_string'] = create_sql_string
# insert into sql
insert_list = []
data = faker_data.faker_data(lines=config['InsertRows'])[1:]
for a in data:
#拼接sql
insert_sql_string = "INSERT INTO " + table_name
insert_sql_string += "(uuid, id, name, mobile, ssn, sex, email, job, address, actime_time) VALUES("
str_data = ','.join("'{0}'".format(x) for x in a)
insert_sql_string += str_data + ");"
insert_list.append(insert_sql_string)
# 返回所有的插入语句
pg_info_dict['insert_list'] = insert_list
# delete sql
del_sql = "delete FROM "+ table_name + " where id in (select id from" + table_name + " limit 100)"
pg_info_dict['del_sql'] = del_sql
# uptata sql
updata_sql = "UPDATE "+ table_name
updata_sql += " SET job='unary_测试' WHERE name like '%' AND sex = 1 AND id in ("
updata_sql += " select id from "+ table_name
updata_sql += " limit 100) "
pg_info_dict['updata_sql'] = updata_sql
return(pg_info_dict)

View File

@ -10,7 +10,7 @@ from schedule import every, repeat, run_pending
""" """
说明 说明
1. 用于数据库的持续增目前支持MySQL和Oracle 1. 用于数据库的持续增目前支持MySQLPG和Oracle
2. DBConfig.py 为数据库连接配置使用时需要修改连接信息 2. DBConfig.py 为数据库连接配置使用时需要修改连接信息
- 每周一建立一张表 - 每周一建立一张表
- 每秒往测试表中插入N条数据 - 每秒往测试表中插入N条数据
@ -18,7 +18,7 @@ from schedule import every, repeat, run_pending
- 每1小时修改一下数据 - 每1小时修改一下数据
""" """
# 目前支持 MySQL和Oracle两种数据库,其他的数据库需要做适配 # 目前支持 MySQL、PG和Oracle 数据库,其他的数据库需要做适配
DBType = DBConfig.config['DBType'] DBType = DBConfig.config['DBType']
@ -29,6 +29,8 @@ def get_db_info(dbtype=DBType):
db_config = DBConfig.mysql_config() db_config = DBConfig.mysql_config()
elif dbtype == "Oracle": elif dbtype == "Oracle":
db_config = DBConfig.oracle_config() db_config = DBConfig.oracle_config()
elif dbtype == "PG":
db_config = DBConfig.pg_config()
else: else:
assert False ,"DBType is not support." assert False ,"DBType is not support."
return(db_config) return(db_config)
@ -65,7 +67,7 @@ def create_table():
#每秒插入N条数据 #每秒插入N条数据
@repeat(every(2).seconds) @repeat(every(1).seconds)
def insert_data(): def insert_data():
print("insert data ....") print("insert data ....")
#重新获取一下,确保每次的插入的数据都不一样 #重新获取一下,确保每次的插入的数据都不一样

View File

@ -2,18 +2,18 @@
# 通用配置 # 通用配置
# 数据库类型目前仅支持MySQL和Oracle,注意大小写 # 数据库类型目前仅支持MySQL和Oracle,注意大小写
DBType: Oracle DBType: PG
# 数据库地址 # 数据库地址
IP: "10.10.29.41" IP: "10.72.0.5"
PROT: "1521" PROT: "5432"
# 数据库用户名 # 数据库用户名
DBUSER: "test" DBUSER: "postgres"
# 数据库密码 # 数据库密码
DBPASSWD: "test123" DBPASSWD: "unary@2008"
# 库名 # 库名
DATABASES: "TEST" DATABASES: "postgres"
# 每秒中插入多少条数据 # 每秒中插入多少条数据
InsertRows: 200 InsertRows: 100
# 服务名-Oracle # 服务名-Oracle

Binary file not shown.