import re from sqlalchemy.sql import functions as sql_functions from fpcapture import config def current_user(db_url=config.FPC_DB_URL): """Determines the value to use when setting created_by/updated_by columns on a model. SQLite does not support the CURRENT_USER var/function, so we need to use a stub value (which is a literal string) when using SQLite. Args: db_url (str): DB connection URL Return: str|sqlalchemy.sql.functions.current_user: current DB user """ # DB is assumed to be MySQL if not SQLite if re.match('sqlite:\/\/', db_url): return 'test@localhost' return sql_functions.current_user()