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.

33 lines
914 B

#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time : 2023/4/4 18:33
# @Author : old tom
# @File : connector_factory.py
# @Project : futool-db
# @Desc : 连接器工厂
from fudb.connectors.dialect.dialect_connector import OracleConnector, PostgresqlConnector
from urllib.parse import quote_plus as urlquote
class ConnFactory(object):
"""
数据库连接器工厂
"""
CONNECTION_CONTAINER = {
'oracle': OracleConnector,
'postgresql': PostgresqlConnector
}
def __init__(self, db_type, user, password, host, port, database):
self.db_type = db_type
# urlquote 用于处理密码中的特殊字符例如@
self.connector = self.CONNECTION_CONTAINER[self.db_type](user, urlquote(password), host, port, database)
def get_conn(self):
"""
获取连接
:return:
"""
return self.connector.get_conn()