-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Serialize query results early and stream out.
- Loading branch information
Stefano Cossu
committed
Mar 9, 2018
1 parent
f569606
commit d756458
Showing
2 changed files
with
28 additions
and
23 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,21 +1,32 @@ | ||
import logging | ||
|
||
from io import BytesIO | ||
|
||
from lakesuperior.dictionaries.namespaces import ns_collection as nsc | ||
from lakesuperior.dictionaries.namespaces import ns_mgr as nsm | ||
from lakesuperior.env import env | ||
from lakesuperior.store.ldp_rs.lmdb_store import LmdbStore, TxnManager | ||
|
||
|
||
logger = logging.getLogger(__name__) | ||
rdfly = env.app_globals.rdfly | ||
rdf_store = env.app_globals.rdf_store | ||
|
||
|
||
def sparql_query(qry_str): | ||
def sparql_query(qry_str, fmt): | ||
''' | ||
Send a SPARQL query to the triplestore. | ||
@param qry_str (str) SPARQL query string. SPARQL 1.1 Query Language | ||
(https://www.w3.org/TR/sparql11-query/) is supported. | ||
@param fmt(string) Serialization format. This varies depending on the | ||
query type (SELECT, ASK, CONSTRUCT, etc.). [@TODO Add reference to RDFLib | ||
serialization formats] | ||
@return rdflib.query.QueryResult | ||
@return BytesIO | ||
''' | ||
return rdfly.raw_query(qry_str) | ||
with TxnManager(rdf_store) as txn: | ||
qres = rdfly.raw_query(qry_str) | ||
out_stream = BytesIO(qres.serialize(format=fmt)) | ||
|
||
return out_stream |
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