forked from microsoft/Qcodes
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.
- Loading branch information
Showing
2 changed files
with
66 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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] |