# Copyright (c) 2015, InfluxFramework LLC
# License: MIT. See LICENSE

# Database Module
# --------------------

from influxframework.database.database import savepoint


def setup_database(force, source_sql=None, verbose=None, no_mariadb_socket=False):
	import influxframework

	if influxframework.conf.db_type == "postgres":
		import influxframework.database.postgres.setup_db

		return influxframework.database.postgres.setup_db.setup_database(force, source_sql, verbose)
	else:
		import influxframework.database.mariadb.setup_db

		return influxframework.database.mariadb.setup_db.setup_database(
			force, source_sql, verbose, no_mariadb_socket=no_mariadb_socket
		)


def drop_user_and_database(db_name, root_login=None, root_password=None):
	import influxframework

	if influxframework.conf.db_type == "postgres":
		import influxframework.database.postgres.setup_db

		return influxframework.database.postgres.setup_db.drop_user_and_database(
			db_name, root_login, root_password
		)
	else:
		import influxframework.database.mariadb.setup_db

		return influxframework.database.mariadb.setup_db.drop_user_and_database(
			db_name, root_login, root_password
		)


def get_db(host=None, user=None, password=None, port=None):
	import influxframework

	if influxframework.conf.db_type == "postgres":
		import influxframework.database.postgres.database

		return influxframework.database.postgres.database.PostgresDatabase(host, user, password, port=port)
	else:
		import influxframework.database.mariadb.database

		return influxframework.database.mariadb.database.MariaDBDatabase(host, user, password, port=port)


def setup_help_database(help_db_name):
	import influxframework

	if influxframework.conf.db_type == "postgres":
		import influxframework.database.postgres.setup_db

		return influxframework.database.postgres.setup_db.setup_help_database(help_db_name)
	else:
		import influxframework.database.mariadb.setup_db

		return influxframework.database.mariadb.setup_db.setup_help_database(help_db_name)
