From 3c2c1c706816e6fa6cc7761092e27cde61ca539f Mon Sep 17 00:00:00 2001 From: Mikhail Astafev Date: Fri, 17 May 2019 18:23:01 +0200 Subject: [PATCH] Move qcodes.dataset.database code to sqlite.database qcodes.dataset.database now contains only import statements for backwards compatibility. in following commits, all QCoDeS will use sqlite.database instead of qcodes.dataset.database. --- qcodes/dataset/database.py | 66 +++++-------------------------- qcodes/dataset/sqlite/database.py | 57 ++++++++++++++++++++++++++ 2 files changed, 66 insertions(+), 57 deletions(-) create mode 100644 qcodes/dataset/sqlite/database.py diff --git a/qcodes/dataset/database.py b/qcodes/dataset/database.py index 55d7971ab63..0e5239505d1 100644 --- a/qcodes/dataset/database.py +++ b/qcodes/dataset/database.py @@ -1,57 +1,9 @@ -# high-level interface to the database - -from os.path import expanduser - -from qcodes.dataset.sqlite_base import ConnectionPlus -from qcodes.dataset.sqlite_base import connect as _connect -from qcodes.dataset.sqlite_base import init_db as _init_db -import qcodes.config - - -def get_DB_location() -> str: - return expanduser(qcodes.config["core"]["db_location"]) - - -def get_DB_debug() -> bool: - return bool(qcodes.config["core"]["db_debug"]) - - -def initialise_database() -> None: - """ - Initialise a database in the location specified by the config object - If the database already exists, nothing happens. The database is - created with or upgraded to the newest version - - Args: - config: An instance of the config object - """ - conn = _connect(get_DB_location(), get_DB_debug()) - # init is actually idempotent so it's safe to always call! - _init_db(conn) - conn.close() - del conn - - -def initialise_or_create_database_at(db_file_with_abs_path: str) -> None: - """ - This function sets up QCoDeS to refer to the given database file. If the - database file does not exist, it will be initiated. - - Args: - db_file_with_abs_path - Database file name with absolute path, for example - ``C:\\mydata\\majorana_experiments.db`` - """ - qcodes.config.core.db_location = db_file_with_abs_path - initialise_database() - - -def path_to_dbfile(conn: ConnectionPlus) -> str: - """ - Return the path of the database file that the conn object is connected to - """ - cursor = conn.cursor() - cursor.execute("PRAGMA database_list") - row = cursor.fetchall()[0] - - return row[2] +""" +Code of this module has been moved to `.sqlite.database`. This module now +only re-imports the functions which it used to contain, for backwards +compatibility. Do not import functions from this module because it will be +removed soon. +""" + +from .sqlite.database import get_DB_debug, get_DB_location, \ + initialise_database, initialise_or_create_database_at, path_to_dbfile diff --git a/qcodes/dataset/sqlite/database.py b/qcodes/dataset/sqlite/database.py new file mode 100644 index 00000000000..55d7971ab63 --- /dev/null +++ b/qcodes/dataset/sqlite/database.py @@ -0,0 +1,57 @@ +# high-level interface to the database + +from os.path import expanduser + +from qcodes.dataset.sqlite_base import ConnectionPlus +from qcodes.dataset.sqlite_base import connect as _connect +from qcodes.dataset.sqlite_base import init_db as _init_db +import qcodes.config + + +def get_DB_location() -> str: + return expanduser(qcodes.config["core"]["db_location"]) + + +def get_DB_debug() -> bool: + return bool(qcodes.config["core"]["db_debug"]) + + +def initialise_database() -> None: + """ + Initialise a database in the location specified by the config object + If the database already exists, nothing happens. The database is + created with or upgraded to the newest version + + Args: + config: An instance of the config object + """ + conn = _connect(get_DB_location(), get_DB_debug()) + # init is actually idempotent so it's safe to always call! + _init_db(conn) + conn.close() + del conn + + +def initialise_or_create_database_at(db_file_with_abs_path: str) -> None: + """ + This function sets up QCoDeS to refer to the given database file. If the + database file does not exist, it will be initiated. + + Args: + db_file_with_abs_path + Database file name with absolute path, for example + ``C:\\mydata\\majorana_experiments.db`` + """ + qcodes.config.core.db_location = db_file_with_abs_path + initialise_database() + + +def path_to_dbfile(conn: ConnectionPlus) -> str: + """ + Return the path of the database file that the conn object is connected to + """ + cursor = conn.cursor() + cursor.execute("PRAGMA database_list") + row = cursor.fetchall()[0] + + return row[2]