2021-02-18 06:04:30 +01:00
|
|
|
# standard imports
|
|
|
|
import logging
|
|
|
|
|
|
|
|
# local imports
|
2021-05-01 15:20:14 +02:00
|
|
|
from .list import (
|
|
|
|
list_transactions_mined,
|
|
|
|
list_transactions_account_mined,
|
|
|
|
add_transaction,
|
|
|
|
tag_transaction,
|
|
|
|
add_tag,
|
|
|
|
)
|
2021-11-10 09:55:30 +01:00
|
|
|
from cic_cache.db.models.base import SessionBase
|
2021-05-01 15:20:14 +02:00
|
|
|
|
2021-02-18 06:04:30 +01:00
|
|
|
|
|
|
|
logg = logging.getLogger()
|
|
|
|
|
|
|
|
|
2021-11-10 09:07:23 +01:00
|
|
|
def dsn_from_config(config, name):
|
2021-02-18 06:04:30 +01:00
|
|
|
scheme = config.get('DATABASE_ENGINE')
|
|
|
|
if config.get('DATABASE_DRIVER') != None:
|
|
|
|
scheme += '+{}'.format(config.get('DATABASE_DRIVER'))
|
|
|
|
|
2021-11-10 09:07:23 +01:00
|
|
|
database_name = name
|
|
|
|
if config.get('DATABASE_PREFIX'):
|
|
|
|
database_name = '{}_{}'.format(config.get('DATABASE_PREFIX'), database_name)
|
2021-02-18 06:04:30 +01:00
|
|
|
dsn = ''
|
|
|
|
if config.get('DATABASE_ENGINE') == 'sqlite':
|
2021-11-10 09:55:30 +01:00
|
|
|
SessionBase.poolable = False
|
2021-02-18 06:04:30 +01:00
|
|
|
dsn = '{}:///{}'.format(
|
|
|
|
scheme,
|
2021-11-10 09:07:23 +01:00
|
|
|
database_name,
|
2021-02-18 06:04:30 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
else:
|
|
|
|
dsn = '{}://{}:{}@{}:{}/{}'.format(
|
|
|
|
scheme,
|
|
|
|
config.get('DATABASE_USER'),
|
|
|
|
config.get('DATABASE_PASSWORD'),
|
|
|
|
config.get('DATABASE_HOST'),
|
|
|
|
config.get('DATABASE_PORT'),
|
2021-11-10 09:07:23 +01:00
|
|
|
database_name,
|
2021-02-18 06:04:30 +01:00
|
|
|
)
|
|
|
|
logg.debug('parsed dsn from config: {}'.format(dsn))
|
|
|
|
return dsn
|
|
|
|
|