Skip to content

Commit

Permalink
Move qcodes.dataset.database code to sqlite.database
Browse files Browse the repository at this point in the history
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
astafan8 committed May 17, 2019
1 parent c64961f commit 3c2c1c7
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 57 deletions.
66 changes: 9 additions & 57 deletions qcodes/dataset/database.py
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
57 changes: 57 additions & 0 deletions qcodes/dataset/sqlite/database.py
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]

0 comments on commit 3c2c1c7

Please sign in to comment.