Database
HIPPO stores data in a SQLite Database file that structures information across multiple cross-referenced tables. For general use it is not necessary to understand the database schema in detail.
- class hippo.db.Database(path: Path, animal: HIPPO, update_legacy: bool = False, auto_compute_bfps: bool = True)[source]
Wrapper to connect to the HIPPO sqlite database.
Attention
Databaseobjects should not be created directly. Instead use the methods inHIPPOto interact with data in the database. See Getting started with HIPPO and insert_elaborations.Database initialisation
- property auto_compute_bfps: bool
Automatically compute compound binary fingerprints on insertion
- backup(destination: Path | str | None = None, pages: int = 10000) None[source]
Create a backup of the database
- calculate_all_murcko_scaffolds(generic: bool = True)[source]
Determine Murcko and optionally generic Murcko scaffolds for all Compounds in the Database and add relevant records.
- Parameters:
generic – Calculate generic (single bonds and all carbon) scaffolds as well
- calculate_all_scaffolds() None[source]
Determine and insert records for all substructure/superstructure relationships in the Compound table
- commit(*, retry: float | None = 1) None[source]
Commit changes to the database
- Parameters:
retry – If truthy, keep trying to execute every retry seconds if the Database is locked
- property connection: sqlite3.connection
Returns a
sqlite3.connectionto the database
- classmethod copy_from(source: Path, destination: Path, animal: HIPPO, update_legacy: bool = False, overwrite_existing: bool = False, pages: int = 10000) None[source]
Create a
Databasefrom an existing one
- copy_interactions_to_temp(pose_id: int) int[source]
Copy the records from the ‘temp_interaction’ table to the ‘interaction’ table
- Returns:
ID of the last inserted
Interaction
- copy_temp_interactions() int[source]
Copy the records from the ‘temp_interaction’ table to the ‘interaction’ table
- Returns:
ID of the last inserted
Interaction
- count(table: str) int[source]
Count all entries in a table
- Parameters:
table – table to count entries from
- count_where(table: str, key: str, value=None)[source]
Count all entries in a table where
key==value- Parameters:
table – table to count entries from
key – the key to match as
{table}_{key} = {value}or the SQL string ifvalue == Nonevalue – the value to match (Default value = None)
- create_metadata_id_map(*, table: str, key: str) dict[str, int][source]
Create a mapping between metadata[key] values to their respective parent record ID’s
- Returns:
dictionary mapping metadata[key] values to integer ID’s
- create_table_interaction(table: str = 'interaction', debug: bool = True) None[source]
Create an interaction table
- property cursor: sqlite3.cursor
Returns a
sqlite3.cursor
- delete_interactions() None[source]
Delete all calculated interactions and set pose_fingerprint appropriately
- delete_tag(tag: str) None[source]
Delete all tag entries with the matching name
- Parameters:
tag – tag name to match
- delete_where(table: str, key: str, value: str | None = None, commit: bool = True) None[source]
Delete entries where
key==value- Parameters:
table – the table from which to delete
key – column name to match to value, if no
valueis provided thisvalue – the value to match (Default value = None)
commit – commit the changes (Default value = True)
- execute(sql, payload=None, *, retry: float | None = 1, debug: bool = False)[source]
Execute arbitrary SQL with retry if database is locked.
- executemany(sql, payload, *, retry: float | None = 1) None[source]
Execute arbitrary SQL
- Parameters:
sql – SQL query
retry – If truthy, keep trying to executemany every retry seconds if the Database is locked
payload – Payload for insertion, etc. (Default value = None)
- fix_incorrect_pose_compound_assignments()[source]
Fix pose_compound values that reference incorrect chemical structures
- get_compound(*, id: int | None = None, inchikey: str | None = None, alias: str | None = None, smiles: str | None = None, none: str = 'error', **kwargs) Compound[source]
Get a
Compoundusing one of the following fields: [‘id’, ‘inchikey’, ‘alias’, ‘smiles’]- Parameters:
id – the ID to search for (Default value = None)
inchikey – the InChi-Key to search for (Default value = None)
alias – the alias to search for (Default value = None)
smiles – the smiles to search for (Default value = None)
- Returns:
the
Compoundobject
- get_compound_cluster_dict(cset: CompoundSet | None = None, *, fractions: bool = False, max_scaffolds: int | None = None, fraction_reference: CompoundSet | None = None) dict[tuple, set][source]
Create a dictionary grouping compounds by their scaffold/base cluster.
- Parameters:
cset –
CompoundSetsubset to query, defaults to all compoundsfractions – Calculate fractional populations for each cluster
max_scaffolds – Define the maximum number of compounds to use as cluster keys
fraction_reference – Use cset to build the cluster map and use fraction_reference to determine the fractional populations
- Returns:
A dictionary mapping a tuple of scaffold
CompoundIDs to a set of superstructureCompoundID’s.
- get_compound_computed_property(prop: str, compound_id: int) int | str[source]
Use chemicalite to calculate a property from the stored binary molecule
- Parameters:
prop – the property to calculate [num_heavy_atoms, formula, num_rings]
compound_id – the compound ID to query
- Returns:
the value of the computed property
- get_compound_id(*, inchikey: str | None = None, alias: str | None = None, smiles: str | None = None, **kwargs) int[source]
Get a compound’s ID using one of the following fields: [‘inchikey’, ‘alias’, ‘smiles’]
- Parameters:
inchikey – the InChi-Key to search for (Default value = None)
alias – the alias to search for (Default value = None)
smiles – the smiles to search for (Default value = None)
- Returns:
the
CompoundID
- get_compound_id_inchikey_dict(cset: CompoundSet | None = None) dict[int, str][source]
Get a dictionary mapping
CompoundIDs to their inchikeys
- get_compound_id_inspiration_ids_dict() dict[int, set][source]
Get a dictionary mapping
CompoundID’s to a set ofPoseID’s for the inspirations for the whole database
- get_compound_id_obj_dict(cset: CompoundSet) dict[id, Compound][source]
Get a dictionary mapping
CompoundID’s to their objects
- get_compound_id_pose_ids_dict(cset: CompoundSet) dict[int, set][source]
Get a dictionary mapping
CompoundID’s to their associatedPoseID’s
- get_compound_id_smiles_dict(cset: CompoundSet | None = None) dict[int, set[str]][source]
Get a dictionary mapping
CompoundID’s to suppliers which stock it
- get_compound_id_suppliers_dict(cset: CompoundSet) dict[int, set[str]][source]
Get a dictionary mapping
CompoundID’s to suppliers which stock it
- get_compound_inchikey_id_dict(inchikeys: list[str]) dict[str, int][source]
Get a dictionary mapping
Compoundinchikeys to their ID’s
- get_compound_scaffold_dict() dict[int, set[int]][source]
Get a dictionary mapping scaffold_base compound ID’s to a set of their superstructure IDs
- get_compound_tag_dict(cset: CompoundSet | None = None) dict[int, set[str]][source]
Get a dictionary mapping compound ID’s to their tags
- get_id_metadata_dict(*, table: str, ids: list[int]) dict[int, dict][source]
Get a dictionary mapping IDs to metadata dictionaries
- get_inspiration_tuples() list[int, int][source]
Get a dictionary mapping
PoseID’s to a set ofPoseID’s for the inspirations for the whole database
- get_interaction(*, id: int, table: str = 'interaction') Interaction[source]
Fetch the
Interactionobject with given ID- Parameters:
id – the ID of the Interaction to retrieve
- Returns:
Interactionobject
- get_metadata(*, table: str, id: int) dict[source]
Get metadata dictionary from a specific table and ID
- Parameters:
table – the table from which to get the entry
id – the ID to search for (Default value = None)
- Returns:
a dictionary of metadata
- get_pose(*, id: int | None = None, inchikey: str = None, alias: str = None) Pose[source]
Get a pose using one of the following fields: [‘id’, ‘inchikey’, ‘alias’]
- Parameters:
id – the ID to search for (Default value = None)
inchikey – the InChi-Key to search for (Default value = None)
alias – the alias to search for (Default value = None)
- Returns:
the
Poseobject
- get_pose_alias_id_dict(pset: PoseSet | None = None) dict[str, int][source]
Get a dictionary mapping
Posealiases to ID’s
- get_pose_alias_path_dict(pset: PoseSet | None = None) dict[str, str][source]
Get a dictionary mapping
Posealiases to paths
- get_pose_id(*, inchikey: str | None = None, alias: str | None = None) int[source]
Get a pose’s ID using one of the following fields: [‘inchikey’, ‘alias’, ‘smiles’]
- Parameters:
table – the table from which to get the entry (Default value = ‘pose’)
inchikey – the InChi-Key to search for (Default value = None)
alias – the alias to search for (Default value = None)
- Returns:
the
PoseID
- get_pose_id_alias_dict(pset: PoseSet | None = None) dict[str, int][source]
Get a dictionary mapping
Posealiases to ID’s
- get_pose_id_inspiration_ids_dict(pset: PoseSet = None) dict[int, set][source]
Get a dictionary mapping
PoseID’s to a set ofPoseID’s for the inspirations for the whole database
- get_pose_id_interaction_ids_dict(pset: PoseSet) dict[int, set][source]
Get a dictionary mapping
PoseID’s to their associatedInteractionID’s
- get_pose_id_interaction_tuples_dict(pset: PoseSet) dict[int, set][source]
Get a dictionary mapping
PoseID’s to lists of (interaction_type, feature_id) tuples describing their interactions
- get_pose_id_obj_dict(pset: PoseSet) dict[id, Pose][source]
Get a dictionary mapping
PoseID’s to their objects
- get_pose_path_id_dict(pset: PoseSet | None = None) dict[str, int][source]
Get a dictionary mapping
Posealiases to ID’s
- get_pose_subsite_names_dict() dict[int, set[str]][source]
Get a dictionary mapping pose ID’s to their subsite names
- get_pose_tag_dict(pset: PoseSet | None = None) dict[int, set[str]][source]
Get a dictionary mapping pose ID’s to their tags
- get_possible_reaction_ids(*, compound_ids: list[int]) list[int][source]
Given a set of reactant
CompoundID’s, compute whichReactionobjects are possible (all reactants present).
- get_possible_reaction_product_ids(*, reaction_ids: list[int]) list[int][source]
Given a set of
ReactionIDs return theCompoundIDs of their synthesis products
- get_product_id_routes_dict() dict[int, set[int]][source]
Get a dictionary mapping product
Compoundto their route IDs
- get_quote(*, id: int | None = None, none: str | None = None) Quote[source]
Get a quote using its ID
- Parameters:
id – the ID to search for (Default value = None)
none – define the behaviour for no matches, any value other than
'error'will silently return empty data (Default value = ‘error’)
- Returns:
the
Quoteobject
- get_quote_df(ids: list[int]) pd.DataFrame[source]
Get a pandas DataFrame representing quotes with given IDs
- get_reactant_product_tuples(compound_ids: list | None = None, deduplicated: bool = True) set[tuple[int, int]][source]
Get tuples of (reactant, product)
CompoundIDs
- get_reaction(*, id: int | None = None, none: str | None = None) Reaction[source]
Get a reaction using its ID
- Parameters:
id – the ID to search for (Default value = None)
none – define the behaviour for no matches, any value other than
'error'will silently return empty data (Default value = ‘error’)
- Returns:
the
Reactionobject
- get_reaction_map_from_products(product_ids: list[int]) dict[tuple[str, int], set[int]][source]
Get a dictionary mapping (reaction_type, product_id) tuples to sets of reactant_ids
- get_reaction_price_estimate(*, reaction: Reaction) float[source]
Estimate the price of a
Reaction- Parameters:
reaction –
Reactionobject- Returns:
price estimate
- get_route_id_product_dict() dict[int, int][source]
Get a dictionary mapping route ID’s to their product
Compound
- get_route_products() CompoundSet | None[source]
Get a
CompoundSetof all route products
- get_scaffold_similarity_dict(scaffolds: CompoundSet | None = None) list[dict][source]
Get a dictionary mapping scaffold
CompoundIDs to their superstructure’s IDs
- get_scaffold_tuples(compound_ids: list | None = None) set[tuple[int, int]][source]
Get tuples of (reactant, product)
CompoundIDs
- get_subsite(*, id) Subsite[source]
Get protein subsite with a given ID
- Parameters:
ID – the subsite ID
- Returns:
Subsiteobject
- get_subsite_id(*, name: str, **kwargs) int | None[source]
Get protein Subsite ID with a given name
- Parameters:
name – the protein Subsite name
- Returns:
the Subsite ID
- get_subsite_name(*, id: str, **kwargs) int | None[source]
Get protein
Subsitename with a given ID- Parameters:
name – the protein
SubsiteID- Returns:
the
SubsiteID
- get_subsite_tag(*, id) SubsiteTag[source]
Get subsite_tag with a given ID
- Parameters:
ID – the subsite_tag ID
- Returns:
SubsiteTagobject
- get_target(*, id: int) Target[source]
Get target with specific ID
- Parameters:
id – the ID of the target to retrieve
- Returns:
Targetobject
- get_target_id(*, name: str) int | None[source]
Get target ID with a given name
- Parameters:
name – the protein target name
- Returns:
the
TargetID
- get_target_name(*, id: int) str[source]
Get the name of a target with given ID
- Parameters:
id – the ID of the target to retrieve
- Returns:
target name
- get_unsolved_reaction_tree(*, product_ids: list[int], debug: bool = False)[source]
Given a set of product
CompoundIDs, recursively solve for all the reactants (CompoundSet) and reactions (ReactionSet) that could be involved in their synthesis. N.B. This evaluates all synthesis branches.- Parameters:
product_ids – list of product
CompoundIDsdebug – increase verbosity for debugging, defaults to False
- Returns:
a tuple of
(reactants, reactions)
- insert_component(*, route: int, ref: int, component_type: int, amount: float = 1.0, commit: bool = True) int[source]
component_type
table
ref
1
reaction
reaction
2
compound
reactant
3
compound
intermediate
- insert_compound(*, smiles: str, alias: str | None = None, tags: None | list[str] = None, warn_duplicate: bool = True, commit: bool = True, metadata: None | dict = None, inchikey: str = None) int[source]
Insert an entry into the compound table
- Parameters:
smiles – SMILES string
alias – optional alias for the compound (Default value = None)
tags – list of string tags, (Default value = None)
warn_duplicate – print a warning if the compound already exists (Default value = True)
commit – commit the changes to the database (Default value = True)
metadata – dictionary of metadata (Default value = None)
inchikey – provide an InChI-key, otherwise it’s calculated from the SMILES, (Default value = None)
- Returns:
compound ID
- insert_compound_pattern_bfp(compound_id: int, commit: bool = True) int[source]
Insert a compound_pattern_bfp
- Parameters:
compound_id – ID of the associated compound
commit – commit the changes to the database (Default value = True)
- Returns:
binary fingerprint ID
- insert_feature(*, family: str, target: int, chain_name: str, residue_name: str, residue_number: int, atom_names: list[str], warn_duplicate: bool = False, commit: bool = True) int[source]
Insert an entry into the feature table
- Parameters:
family – feature type string
target – associated
TargetIDchain_name – single character name of the chain
residue_name – 3-4 character string name of the residue
residue_number – integer residue number
atom_names – list of atom names
commit – commit the changes to the database (Default value = True)
- Returns:
feature ID
- insert_inspiration(*, original: Pose | int, derivative: Pose | int, warn_duplicate: bool = True, commit: bool = True) int[source]
Insert an entry into the inspiration table
- insert_interaction(*, feature: Feature | int, pose: Pose | int, type: str, family: str, atom_ids: list[int], prot_coord: list[float], lig_coord: list[float], distance: float, angle: float | None = None, energy: float | None = None, warn_duplicate: bool = True, commit: bool = True, table: str = 'interaction') int[source]
Insert an entry into the interaction table
- Parameters:
feature – associated
Featureobject or IDpose – associated
Poseobject or IDtype – interaction type
family – ligand feature type
atom_ids – atom indices of ligand feature
prot_coord –
[x,y,z]coordinate of protein featurelig_coord –
[x,y,z]coordinate of ligand featuredistance – interaction distance
Angstromangle – optional interaction angle
degreesenergy – energy score
kcal/mol, defaults toNonewarn_duplicate – print a warning if the pose already exists (Default value = True)
commit – commit the changes to the database (Default value = True)
table – the name of the table to insert into (Default value = ‘interaction’)
- Returns:
the interaction ID
- insert_metadata(*, table: str, id: int, payload: dict, commit: bool = True) None[source]
Insert metadata into an an existing entry in the compound or pose tables
- Parameters:
table – table for insertions
['pose', 'compound', 'subsite', 'subsite_tag']id – associated entry ID
payload – metadata dictionary
commit – commit the changes to the database (Default value = True)
- insert_pose(*, compound: Compound | int, target: Target | int | str, path: str, inchikey: str | None = None, alias: str | None = None, reference: int | Pose | None = None, tags: None | list = None, energy_score: float | None = None, distance_score: float | None = None, metadata: None | dict = None, commit: bool = True, warn_duplicate: bool = True, resolve_path: bool = True) int[source]
Insert an entry into the pose table
- Parameters:
compound – associated
Compoundobject or IDtarget – protein
Targetname or IDpath – path to the molecular structure (.pdb/.mol)
inchikey – provide an InChI-key if available, (Default value = None)
alias – optional alias for the compound (Default value = None)
reference – reference
Poseobject or ID to use for the protein conformation (Default value = None)tags – list of string tags, (Default value = None)
energy_score – optional score of the ligand’s binding energy (Default value = None)
distance_score – optional score of the ligand’s binding position (Default value = None)
metadata – dictionary of metadata (Default value = None)
commit – commit the changes to the database (Default value = True)
warn_duplicate – print a warning if the pose already exists (Default value = True)
resolve_path – try resolving the path (Default value = True)
- Returns:
the pose ID
- insert_quote(*, compound: Compound | int, supplier: str, catalogue: str | None = None, entry: str | None = None, amount: float, price: float, currency: str | None = None, purity: float | None = None, lead_time: float, smiles: str | None = None, date: str | None = None, commit: bool = True) int | None[source]
Insert an entry into the quote table
- Parameters:
compound – associated
Compoundobject or IDsupplier – name of the supplier
catalogue – optional catalogue name
entry – name of the catalogue entry
amount – amount in mg
price – price of the compound
currency – currency string
['GBP', 'EUR', 'USD', None]purity – compound purity fraction
lead_time – lead time in days
smiles – quoted SMILES string (Default value = None)
commit – commit the changes to the database (Default value = True)
- Returns:
the quote ID
- insert_reactant(*, compound: Compound | int, reaction: Reaction | int, amount: float = 1.0, commit: bool = True) int[source]
Insert an entry into the reactant table
- insert_reaction(*, type: str, product: Compound | int, product_yield: float = 1.0, commit: bool = True) int[source]
Insert an entry into the reaction table
- Parameters:
type – string to indicate the reaction type
product –
Compoundobject or ID of the reaction productproduct_yield – yield fraction of the reaction product (Default value = 1.0)
commit – commit the changes to the database (Default value = True)
- Returns:
the reaction ID
- insert_route(*, product_id: int, commit: bool = True) int[source]
Insert an entry into the route table
- Parameters:
product_id –
CompoundID of the productcommit – commit the changes to the database (Default value = True)
- Returns:
route ID
- insert_scaffold(*, scaffold: Compound | int, superstructure: Compound | int, warn_duplicate: bool = True, commit: bool = True) int[source]
Insert an entry into the scaffold table
- Parameters:
- Returns:
the scaffold row ID
- insert_subsite(target: int, name: str, commit: bool = True) int[source]
Insert an entry into the subsite table
- Parameters:
target – protein
TargetIDname – name of the protein subsite/subsite
- Returns:
the subsite ID
- insert_subsite_tag(*, pose_id: int, name: str | None, target: int | None = None, subsite_id: int | None = None, commit: bool = True) int[source]
Insert an entry into the subsite_tag table
- insert_tag(*, name: str, compound: int = None, pose: int = None, commit: bool = True) int[source]
Insert an entry into the tag table.
Attention
Exactly one of compound or pose arguments must have a value
- insert_target(*, name: str, warn_duplicate: bool = True) int[source]
Insert an entry into the target table
- Parameters:
name – name of the protein target
- Returns:
the target ID
- max_id(table: str) int[source]
Get the maximal entry ID from a given table
- Parameters:
table – the database table to query
- Returns:
the largest entry ID
- migrate_legacy_scaffolds() int[source]
Migrate legacy compound_scaffold records from the ‘compound’ table to the ‘scaffold’ table
- Returns:
ID of the last inserted scaffold record
- min_id(table: str) int[source]
Get the minimal entry ID from a given table
- Parameters:
table – the database table to query
- Returns:
the smallest entry ID
- property path: Path
Returns the path to the database file
- print_table(table: str) None[source]
Print a table’s entries
- Parameters:
table – the table to print
- prune_reactions(reactions: ReactionSet) list[Reaction][source]
Remove duplicate reactions
- Parameters:
reactions –
ReactionSet- Returns:
list of pruned
Reactionobjects
- query_exact(query: str, threshold: float = 0.989) CompoundSet[source]
Search for exact match compounds (default similarity > 0.989)
- Parameters:
query – SMILES string
threshold – similarity threshold to exceed
- query_most_similar(query: str, subset: CompoundSet, return_similarity: bool = False, none='error')[source]
Search for the most similar compound by tanimoto similarity of binary pattern fingerprints using the chemicalite function mol_pattern_bfp
- Parameters:
query – SMILES string
return_similarity – return a list of similarity values together with the
CompoundSet(Default value = False)none – define the behaviour for no matches, any value other than
'error'will silently return empty data (Default value = ‘error’)subset – optional subset of compounds to search
- Returns:
Compoundand optionally a similarity values
- query_similarity(query: str, threshold: float, return_similarity: bool = False, subset: CompoundSet = None, none='error')[source]
Search compounds by tanimoto similarity of binary pattern fingerprints using the chemicalite function mol_pattern_bfp
- Parameters:
query – SMILES string
threshold – similarity threshold to exceed
return_similarity – return a list of similarity values together with the
CompoundSet(Default value = False)none – define the behaviour for no matches, any value other than
'error'will silently return empty data (Default value = ‘error’)subset – optional subset of compounds to search
- Returns:
CompoundSetand optionally a list of similarity values
- query_substructure(query: str, *, fast: bool = True, none: str = 'error', smarts: bool = False) CompoundSet[source]
Search for compounds by substructure
- Parameters:
query – SMILES string of the substructure
fast – Use pattern binary fingerprint table to improve performance (Default value = True)
none – define the behaviour for no matches, any value other than
'error'will silently return empty data (Default value = ‘error’)
- Returns:
CompoundSetobject
- register_compounds(*, smiles: list[str], radical: str = 'warning', sanitisation_verbosity: bool = True, sanitise: bool = True, debug: bool = False) list[tuple[str, str]][source]
Bulk register compounds
- register_poses(dicts: list[dict]) set[int][source]
Insert or ignore a bunch of poses, also returns a set of Pose IDs
- Parameters:
dicts – a list of dictionaries describing the poses to be inserted. See the expected format below:
- dicts = [
- dict(
alias=…, # string can be None reference_id=…, # reference pose id inchikey=…, # pre-computed inchikey smiles=…, # SMILEs path=…, # path to mol-file on disk, used for uniqueness check, can be a fake path compound_id=…, # Compound database ID target_id=…, # Target database ID mol=…, # rdkit.Chem.Mol energy_score=…, # float, can be None distance_score=…, # float, can be None metadata=…, # dictionary, can be empty
)
]
- reinitialise_molecules()[source]
In the case where the Mol binaries in a database are throwing unpickling errors, run this to reinitialise them all from their smiles.
- remove_metadata_list_item(*, table: str, key: str, value, remove_empty: bool = True) None[source]
Remove a specific item from list-like values associated with a given key from all metadata entries in a given table
- Parameters:
table – the database table to query
key – the
Metadatakey to matchvalue – the value to remove from the list
remove_empty – remove the key from the metadata if the list is empty (Default value = True)
- select(query: str, table: str, multiple: bool = False) tuple | list[tuple][source]
Wrapper for the SQL SELECT query, in the following syntax:
'SELECT {query} FROM {table}'
- Parameters:
query – the columns to return
table – the table from which to select
multiple – fetch all results (Default value = False)
- Returns:
the result of the query
- select_all_where(table: str, key: str, value: str | None = None, multiple: bool = False, none: str | None = 'error') tuple | list[tuple][source]
Select entries where
key==value. Similar toselect_where()except the query argument is always*.- Parameters:
table – the table from which to select
key – column name to match to value, if no
valueis provided thisvalue – the value to match (Default value = None)
multiple – fetch all results (Default value = False)
none – define the behaviour for no matches, any value other than
'error'will silently return empty data (Default value = ‘error’)
- Returns:
the result of the query
- select_id_where(table: str, key: str, value: str | None = None, multiple: bool = False, none: str | None = 'error') tuple | list[tuple][source]
Select ID’s where
key==value. Similar toselect_where()except the query argument is always{table}_id.- Parameters:
table – the table from which to select
key – column name to match to value, if no
valueis provided thisvalue – the value to match (Default value = None)
multiple – fetch all results (Default value = False)
none – define the behaviour for no matches, any value other than
'error'will silently return empty data (Default value = ‘error’)
- Returns:
the result of the query
- select_where(query: str, table: str, key: str, value: str | None = None, multiple: bool = False, none: str | None = 'error', sort: str = None) tuple | list[tuple][source]
Select entries where
key == valueExamples
Find compound alias with matching ID:
animal.db.select_where( query='compound_alias', table='compound', key='id', value='123', ) # the above evaluates to: 'SELECT compound_id FROM compound WHERE compound_id = 123'
Find compound aliases with ID below 10 and order alphabetically:
animal.db.select_where( query='compound_alias', table='compound', key='compound_id < 10', multiple=True, sort='compound_alias', ) # the above evaluates to: 'SELECT compound_id FROM compound WHERE compound_id < 10 ORDER BY compound_alias'
:param : :type : param query: the columns to return :param : :type : param table: the table from which to select :param : :type : param key: column name to match to value, if no
valueis provided the key argument should contain the a SQL string to select entries :param : :type : param value: the value to match (Default value = None) :param : :type : param multiple: fetch all results (Default value = False) :param : :type : param none: define the behaviour for no matches, any value other than'error'will silently return empty data (Default value = ‘error’) :param : :type : param sort: optionally sort the output (Default value = None) :param : :type : returns: the result of the query
- set_derivative_subsites(commit: bool = True) None[source]
Propagate all subsite assignments from inspirations to their derivatives
- slice_ids(*, table: str, start: int | None, stop: int | None, step: int = 1, name: bool = False) list[int][source]
Retrieve ID’s matching a slice
- Parameters:
table – the database table to query
start – return IDs equal to or larger than this value
stop – return IDs smaller than this value
step – return IDs in increments of this value (Default value = 1)
- Returns:
matching IDs
- table_info(table: str) list[tuple][source]
Print a table’s schema
- Parameters:
table – the table to print
- property table_names: list[str]
List of all the table names in the database
- property total_changes: int
Return the total number of database rows that have been modified, inserted, or deleted since the database connection was opened.
- update(*, table: str, id: int, key: str, value, commit: bool = True) int[source]
Update a field in a database entry with given ID
- Parameters:
table – the table which to update
id – the ID of the entry to update
key – column name to update
value – the value to insert
commit – commit the changes to the database (Default value = True)
- Returns:
the ID of the modified entry