sage.database.postgres_backends.postgres_catalog package¶
Submodules¶
sage.database.postgres_backends.postgres_catalog.connector module¶
-
class
sage.database.postgres_backends.postgres_catalog.connector.
CatalogPostgresConnector
(table_name: str, dbname: str, user: str, password: str, host: str = '', port: int = 5432, fetch_size: int = 500)¶ Bases:
sage.database.postgres_backends.connector.PostgresConnector
A CatalogPostgresConnector search for RDF triples in a PostgreSQL database.
- Args:
table_name: Name of the SQL table containing RDF data.
dbname: the database name.
user: user name used to authenticate.
password: password used to authenticate.
host: database host address (defaults to UNIX socket if not provided).
port: connection port number (defaults to 5432 if not provided).
fetch_size: The number of SQL rows/RDF triples to fetch per batch (defaults to 500).
-
delete
(subject: str, predicate: str, obj: str) → None¶ Delete a RDF triple from the RDF graph.
- Args:
subject: Subject of the RDF triple.
predicate: Predicate of the RDF triple.
obj: Object of the RDF triple.
-
from_config
() → sage.database.postgres_backends.connector.PostgresConnector¶ Build a CatalogPostgresConnector from a configuration object.
The configuration object must contains the following fields: ‘dbname’, ‘name’, ‘user’ and ‘password’. Optional fields are: ‘host’, ‘port’ and ‘fetch_size’.
-
insert
(subject: str, predicate: str, obj: str) → None¶ Insert a RDF triple into the RDF graph.
- Args:
subject: Subject of the RDF triple.
predicate: Predicate of the RDF triple.
obj: Object of the RDF triple.
-
search
(subject: str, predicate: str, obj: str, last_read: Optional[str] = None, as_of: Optional[datetime.datetime] = None) → Tuple[sage.database.postgres_backends.postgres_catalog.iterator.PostgresIterator, int]¶ Get an iterator over all RDF triples matching a triple pattern.
- Args:
subject: Subject of the triple pattern.
predicate: Predicate of the triple pattern.
object: Object of the triple pattern.
last_read: A RDF triple ID. When set, the search is resumed for this RDF triple.
as_of: A version timestamp. When set, perform all reads against a consistent snapshot represented by this timestamp.
- Returns:
A tuple (iterator, cardinality), where iterator is a Python iterator over RDF triples matching the given triples pattern, and cardinality is the estimated cardinality of the triple pattern.
sage.database.postgres_backends.postgres_catalog.iterator module¶
-
class
sage.database.postgres_backends.postgres_catalog.iterator.
PostgresIterator
(cursor, connection, start_query: str, start_params: List[str], pattern: Dict[str, str], fetch_size: int = 500)¶ Bases:
sage.database.db_iterator.DBIterator
A PostgresIterator implements a DBIterator for a triple pattern evaluated using a Postgre database file
-
has_next
() → bool¶ Return True if there is still results to read, and False otherwise
-
last_read
() → str¶ Return the index ID of the last element read
-
next
() → Optional[Dict[str, str]]¶ Return the next solution mapping or None if there are no more solutions
-
sage.database.postgres_backends.postgres_catalog.queries module¶
-
sage.database.postgres_backends.postgres_catalog.queries.
get_catalog_insert_many_query
()¶ Build a SQL query to insert a RDF term into a PostgreSQL dataset
-
sage.database.postgres_backends.postgres_catalog.queries.
get_catalog_insert_query
()¶ Build a SQL query to insert a RDF term into a PostgreSQL dataset
-
sage.database.postgres_backends.postgres_catalog.queries.
get_delete_query
(table_name)¶ Build a SQL query to delete a RDF triple form a PostgreSQL dataset
-
sage.database.postgres_backends.postgres_catalog.queries.
get_extract_query
()¶
-
sage.database.postgres_backends.postgres_catalog.queries.
get_insert_many_query
(table_name)¶ Build a SQL query to insert a RDF triple into a PostgreSQL dataset
-
sage.database.postgres_backends.postgres_catalog.queries.
get_insert_query
(table_name)¶ Build a SQL query to insert a RDF triple into a PostgreSQL dataset
-
sage.database.postgres_backends.postgres_catalog.queries.
get_locate_query
()¶
-
sage.database.postgres_backends.postgres_catalog.queries.
get_resume_query
(subj, pred, obj, last_read, table_name, symbol='>=')¶ Get a prepared SQL query which resumes scanning for a triple pattern and the parameters used to execute it.
-
sage.database.postgres_backends.postgres_catalog.queries.
get_start_query
(subj, pred, obj, table_name)¶ Get a prepared SQL query which starts scanning for a triple pattern and the parameters used to execute it.