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.
futool-db/test/test_dialect_connector.py

56 lines
3.6 KiB

#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time : 2023/4/4 22:05
# @Author : old tom
# @File : test_dialect_connector.py
# @Project : futool-db
from unittest import TestCase
from fudb.dbapis.fu_db_api import select_all, select_one, count, execute_update, batch_insert
from fudb.connectors.connector_factory import ConnFactory
dds = [(4, 'zr4', 34), (5, 'zr5', 35), (6, 'zr6', 36), (7, 'zr7', 37), (8, 'zr8', 38), (9, 'zr9', 39),
(10, 'zr10', 40), (11, 'zr11', 41), (12, 'zr12', 42), (13, 'zr13', 43), (14, 'zr14', 44), (15, 'zr15', 45),
(16, 'zr16', 46), (17, 'zr17', 47), (18, 'zr18', 48), (19, 'zr19', 49), (20, 'zr20', 50), (21, 'zr21', 51),
(22, 'zr22', 52), (23, 'zr23', 53), (24, 'zr24', 54), (25, 'zr25', 55), (26, 'zr26', 56), (27, 'zr27', 57),
(28, 'zr28', 58), (29, 'zr29', 59), (30, 'zr30', 60), (31, 'zr31', 61), (32, 'zr32', 62), (33, 'zr33', 63),
(34, 'zr34', 64), (35, 'zr35', 65), (36, 'zr36', 66), (37, 'zr37', 67), (38, 'zr38', 68), (39, 'zr39', 69),
(40, 'zr40', 70), (41, 'zr41', 71), (42, 'zr42', 72), (43, 'zr43', 73), (44, 'zr44', 74), (45, 'zr45', 75),
(46, 'zr46', 76), (47, 'zr47', 77), (48, 'zr48', 78), (49, 'zr49', 79), (50, 'zr50', 80), (51, 'zr51', 81),
(52, 'zr52', 82), (53, 'zr53', 83), (54, 'zr54', 84), (55, 'zr55', 85), (56, 'zr56', 86), (57, 'zr57', 87),
(58, 'zr58', 88), (59, 'zr59', 89), (60, 'zr60', 90), (61, 'zr61', 91), (62, 'zr62', 92), (63, 'zr63', 93),
(64, 'zr64', 94), (65, 'zr65', 95), (66, 'zr66', 96), (67, 'zr67', 97), (68, 'zr68', 98), (69, 'zr69', 99),
(70, 'zr70', 100), (71, 'zr71', 101), (72, 'zr72', 102), (73, 'zr73', 103), (74, 'zr74', 104),
(75, 'zr75', 105), (76, 'zr76', 106), (77, 'zr77', 107), (78, 'zr78', 108), (79, 'zr79', 109),
(80, 'zr80', 110), (81, 'zr81', 111), (82, 'zr82', 112), (83, 'zr83', 113), (84, 'zr84', 114),
(85, 'zr85', 115), (86, 'zr86', 116), (87, 'zr87', 117), (88, 'zr88', 118), (89, 'zr89', 119),
(90, 'zr90', 120), (91, 'zr91', 121), (92, 'zr92', 122), (93, 'zr93', 123), (94, 'zr94', 124),
(95, 'zr95', 125), (96, 'zr96', 126), (97, 'zr97', 127), (98, 'zr98', 128), (99, 'zr99', 129),
(100, 'zr100', 130), (101, 'zr101', 131), (102, 'zr102', 132), (103, 'zr103', 133)]
# @Desc :
class TestPostgresqlConnector(TestCase):
def test_get_conn(self):
# factory = ConnFactory('postgresql', 'postgres', 'root@123', 'localhost', 5432, 'postgres')
oracle_factory = ConnFactory('oracle', 'zr', 'root@123', 'localhost', 1521, 'XE')
# factory2 = ConnFactory('postgresql', 'postgres', 'root@123', 'localhost', 5432, 'postgres')
# print(id(factory), id(factory2))
conn = oracle_factory.get_conn()
# 返回第一条
select_one(oracle_factory.get_conn(), 'select * from test limit 20')
# 查全部
select_all(oracle_factory.get_conn(), 'select * from test limit 20')
# 数据量统计
count(oracle_factory.get_conn(), 'test')
# delete \insert \update
execute_update(oracle_factory.get_conn(),'delete from test where id=1')
# 批量插入
batch_insert(conn, 'oracle', 'into t_user (id,name,age) values %s', dds, 10)
# print(select_all(factory.get_conn(), 'select * from test limit 20'))
# print(select_all(factory.get_conn(), 'select * from t_user limit 20'))
# conn.close()
# execute_update(conn, 'update t_user set age=100 where id=3')
# print(execute_update(conn, 'delete from t_user where id=3'))
print(batch_insert(conn, 'oracle', 'into t_user (id,name,age) values %s', dds, 10))