linkml_store.api.stores.solr.solr_database module
- class SolrDatabase(handle=None, **kwargs)[source]
Bases:
Database
- collection_class
alias of
SolrCollection
-
use_cores:
bool
= False
-
base_url:
str
- get_collection(name, create_if_not_exists=True, **kwargs)[source]
Get a named collection.
- Return type:
Examples
>>> from linkml_store.api.client import Client >>> client = Client() >>> db = client.attach_database("duckdb", alias="test") >>> collection = db.create_collection("Person") >>> db.get_collection("Person") == collection True >>> db.get_collection("NonExistent", create_if_not_exists=False) Traceback (most recent call last): ... KeyError: 'Collection NonExistent does not exist'
- type name:
str
- param name:
name of the collection
- param type:
target class name
- type create_if_not_exists:
- param create_if_not_exists:
create the collection if it does not exist
- create_collection(name, alias=None, metadata=None, **kwargs)[source]
Create a new collection in the current database.
The collection must have a Type, and may have an Alias.
Examples:
>>> from linkml_store.api.client import Client >>> client = Client() >>> db = client.attach_database("duckdb", alias="test") >>> collection = db.create_collection("Person", alias="persons") >>> collection.alias 'persons' >>> collection.target_class_name 'Person'
If alias is not provided, it defaults to the name of the type.
>>> collection = db.create_collection("Organization") >>> collection.alias 'Organization'
- Parameters:
name (
str
) – name of the collectionalias (
Optional
[str
]) – alias for the collectionmetadata (
Optional
[CollectionConfig
]) – metadata for the collectionrecreate_if_exists – recreate the collection if it already exists
kwargs – additional arguments
- Return type:
- init_collections()[source]
Initialize collections.
TODO: Not typically called directly: consider making this private :return:
- query(query, **kwargs)[source]
Run a query against the database.
Examples
>>> from linkml_store.api.client import Client >>> from linkml_store.api.queries import Query >>> client = Client() >>> db = client.attach_database("duckdb", alias="test") >>> collection = db.create_collection("Person") >>> collection.insert([{"id": "P1", "name": "John"}, {"id": "P2", "name": "Alice"}]) >>> query = Query(from_table="Person", where_clause={"name": "John"}) >>> result = db.query(query) >>> len(result.rows) 1 >>> result.rows[0]["id"] 'P1'
- type query:
Query
- param query:
- type kwargs:
- param kwargs:
- rtype:
QueryResult
- return: